Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 33 additions & 6 deletions apps/web/src/api/courses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,40 @@ export type CourseItem = {
id: string;
imageUrl?: string;
title?: string;
date?: string;
date?: string; // createdAt을 여기로 매핑해 줄 거야
length: number;
};

type SearchUserCoursesRes = {
results: Array<{
id: number;
title: string;
imageUrl: string | null;
createdAt: string;
length: number;
time: number;
distance: number;
// departure, length, time, author, bookmarked, distance 등은 필요 시 추가
}>;
nextCursor: string | null;
};

export async function searchUserCourses(cursor?: string) {
const { data } = await api.get<{
results: CourseItem[];
nextCursor: string | null;
}>('/api/courses/search/users', { params: cursor ? { cursor } : undefined });
return data;
const { data } = await api.get<SearchUserCoursesRes>(
'/api/courses/search/users',
{
params: cursor ? { cursor } : undefined,
},
);

return {
results: data.results.map((r) => ({
id: String(r.id),
imageUrl: r.imageUrl ?? undefined,
title: r.title ?? undefined,
date: r.createdAt ?? undefined,
length: r.length ?? undefined,
})) as CourseItem[],
nextCursor: data.nextCursor ?? null,
};
}
4 changes: 1 addition & 3 deletions apps/web/src/api/posts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,13 +110,11 @@ function pickImageUrl(res: {
}

function mapListItemToEntity(res: PostResListItem | PostResListItemAlt): Post {
const author = res.authorInfo?.nickname;

return {
id: String(res.id),
category: res.type,
title: res.title,
author,
author: 'author',
commentsCount: res.commentCount,
content: res.content,
likeCount: res.likeCount,
Expand Down
16 changes: 2 additions & 14 deletions apps/web/src/pages/Community/CommunityDetail/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
getReadablePostError,
} from '@/api/posts';
import {
getPostComments, // ← 커서 기반 시그니처: (postId, limit?, cursor?)
getPostComments,
createPostComment,
updateComment,
deleteComment,
Expand Down Expand Up @@ -46,16 +46,13 @@ export default function CommunityDetail() {
null,
);

// 현재 사용자 ID (RN → Web 브리지)
const myIdRaw = useNativeBridgeStore((s) => s.init?.user?.id ?? null);
const toStr = useCallback((v: unknown) => (v == null ? null : String(v)), []);
const myId = toStr(myIdRaw);

// 게시글 수정/삭제 권한 (작성자 본인만)
const authorId = toStr(post?.authorInfo?.id) ?? null;
const canEdit = myId !== null && authorId !== null && myId === authorId;

// ---- 게시글 로드 ----
useEffect(() => {
let mounted = true;
(async () => {
Expand All @@ -81,7 +78,6 @@ export default function CommunityDetail() {
};
}, [id]);

// ---- 댓글 최초 로드 (커서 기반) ----
useEffect(() => {
let mounted = true;
(async () => {
Expand All @@ -104,7 +100,6 @@ export default function CommunityDetail() {
};
}, [id, cLimit]);

// ---- 좋아요 ----
const handleToggleLike = async () => {
if (!post || liking) return;
setLiking(true);
Expand All @@ -127,7 +122,6 @@ export default function CommunityDetail() {
}
};

// ---- 댓글 작성 ----
const handleSubmitComment = async () => {
const v = inputRef.current?.value?.trim();
if (!v || !id) return;
Expand All @@ -139,15 +133,13 @@ export default function CommunityDetail() {
setPost((p) =>
p ? { ...p, commentsCount: (p.commentsCount ?? 0) + 1 } : p,
);
// 커서는 서버가 새로 계산하므로 유지(append만 했으니 nextCursor 변화 없음)
} catch (e) {
alert(getReadablePostError(e));
} finally {
setSubmittingComment(false);
}
};

// ---- 댓글 수정 ----
const handleEditComment = async (commentId: string) => {
const target = comments.find((c) => c.id === commentId);
if (!target) return;
Expand Down Expand Up @@ -186,7 +178,6 @@ export default function CommunityDetail() {
}
};

// ---- 게시글 삭제 ----
const handleDeletePost = useCallback(async () => {
if (!post || deleting) return;

Expand All @@ -213,7 +204,6 @@ export default function CommunityDetail() {
}
}, [post, deleting, nav, confirm]);

// ---- 댓글 삭제 ----
const handleDeleteComment = async (commentId: string) => {
const ok = await confirm({
title: '댓글을 삭제하시겠습니까?',
Expand Down Expand Up @@ -243,9 +233,8 @@ export default function CommunityDetail() {
}
};

// ---- 더 보기(커서 페이징) ----
const handleLoadMore = async () => {
if (!post || !cCursor) return; // 더 불러올 것 없으면 종료
if (!post || !cCursor) return;
const { items, nextCursor } = await getPostComments(
post.id,
cLimit,
Expand All @@ -255,7 +244,6 @@ export default function CommunityDetail() {
setCCursor(nextCursor ?? null);
};

// ---- early returns ----
if (loading) {
return (
<AppLayout title="게시글" onBack={goBack}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,10 @@ export default function EditForm({
</PickerItem>
);
})}
{/* SHARE에서는 Picker 내부 하단에 footerSlot */}
{footerSlot}
</Picker>
</Field>
) : (
// PROOF/FREE/MATE에서는 Picker 대신 별도 영역으로 footerSlot 노출
footerSlot && <Field>{footerSlot}</Field>
)}

Expand Down
Loading