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 CommentBoardHeader #361

Merged
merged 1 commit 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
71 changes: 71 additions & 0 deletions ui/src/components/comment/client/comment-board-header.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
'use client';

import { useEffect, useState } from 'react';

import { CommentCardHeader } from '@/components/comment/client/comment-card-header';
import { CommentEditable } from '@/components/comment/client/comment-editable';
import { CreateCommentButton } from '@/components/comment/client/create-comment-button';
import SearchForm from '@/components/common/client/search-form';
import { BoardHeader } from '@/components/common/server/board-header';
import Text from '@/components/common/server/text';

import { useAuth } from '@/context/auth/auth-context';
import { CommentProvider } from '@/context/comment/comment-context';

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

export function CommentBoardHeader({ SEARCH_OPEN_KEY }: { SEARCH_OPEN_KEY: string }) {
const [open, setOpen] = useState<null | 'search' | 'write'>(null);

useEffect(() => {
if (SEARCH_OPEN_KEY) {
setOpen('search');
}
}, [SEARCH_OPEN_KEY]);

const { user, signIn } = useAuth();

const handleClickNewComment = () => {
if (!user) {
signIn();
return;
}

setOpen((prev) => (prev === 'write' ? null : 'write'));
};

return (
<BoardHeader>
<div className="flex w-full flex-col">
<div className="flex justify-between">
<button
className="h-fit w-fit rounded-full border bg-white px-2 py-1"
onClick={() => setOpen((prev) => (prev === 'search' ? null : 'search'))}
>
<Text nowrap>{open === 'search' ? '검색닫기' : '검색열기'}</Text>
</button>

<button
className="h-fit w-fit rounded-full border bg-white px-2 py-1"
onClick={handleClickNewComment}
>
<Text nowrap>{open === 'write' ? '취소' : '새코멘트'}</Text>
</button>
</div>

{open !== null && (
<div className="pt-4">
{open === 'search' && <SearchForm filters={COMMENT_FILTERS} />}

{open === 'write' && (
<CommentProvider>
<CommentCardHeader />
<CommentEditable actions={<CreateCommentButton />} />
</CommentProvider>
)}
</div>
)}
</div>
</BoardHeader>
);
}
4 changes: 4 additions & 0 deletions ui/src/lib/constants/comment.ts
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
import type { CommentFilter } from '@/lib/definitions/comment';

export const MAX_COMMENT_LENGTH = 500;

export const COMMENT_FILTERS: (keyof CommentFilter)[] = ['movieName', 'nickname'];