Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#327] Implement Comment Board #365

Merged
merged 3 commits into from
May 10, 2024
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
37 changes: 35 additions & 2 deletions ui/src/app/(board)/comment/page.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,36 @@
export default function Page() {
return <>comment board</>;
import { Suspense } from 'react';

import { CommentBoardHeader } from '@/components/comment/client/comment-board-header';
import { CommentCardsList } from '@/components/comment/server/comment-cards-list';

import { COMMENT_FILTERS } from '@/lib/constants/comment';
import type { ListCommentsQuery } from '@/lib/definitions/comment';

export default function Page({
searchParams,
}: {
searchParams?: Omit<ListCommentsQuery, 'pageOffset' | 'pageSize'> & {
page?: string;
};
}) {
const query: ListCommentsQuery = {
movieName: searchParams?.movieName,
nickname: searchParams?.nickname,
pageOffset: Number(searchParams?.page),
};

const SEARCH_OPEN_KEY = COMMENT_FILTERS.reduce((acc, filter) => acc + (query[filter] ?? ''), '');

return (
<main className="container mx-auto flex max-w-5xl flex-col items-center">
<CommentBoardHeader SEARCH_OPEN_KEY={SEARCH_OPEN_KEY} />

<section className="w-full py-4">
{/* todo skeleton */}
<Suspense key={JSON.stringify(query)}>
<CommentCardsList query={query} />
</Suspense>
</section>
</main>
);
}
23 changes: 23 additions & 0 deletions ui/src/components/comment/server/comment-cards-list.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { CommentCard } from '@/components/comment/client/comment-card';
import { NoComment } from '@/components/comment/server/no-comment';
import Pagination from '@/components/common/client/pagination';

import { listComments } from '@/lib/apis/comment/server';
import type { ListCommentsQuery } from '@/lib/definitions/comment';

export async function CommentCardsList({ query }: { query: ListCommentsQuery }) {
const { comments, pagination } = await listComments(query);

return (
<div className="flex w-full flex-col items-center space-y-6">
<div className="w-full">
{comments.length > 0 &&
comments.map((comment) => <CommentCard key={comment.id} comment={comment} />)}

{comments.length === 0 && <NoComment />}
</div>

<Pagination totalPages={pagination.totalPageCount} />
</div>
);
}
13 changes: 13 additions & 0 deletions ui/src/components/comment/server/no-comment.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { XCircleIcon } from '@heroicons/react/24/outline';

import Text from '@/components/common/server/text';

export function NoComment() {
return (
<div className="flex flex-col p-6 items-center gap-8">
<XCircleIcon className="w-6 h-6 text-gray-500" />

<Text>해당하는 코멘트가 없습니다.</Text>
</div>
);
}