Skip to content

Commit

Permalink
Merge pull request #356 from MovieReviewComment/feature/issue-327/com…
Browse files Browse the repository at this point in the history
…ment-card-header

[#327] Implement CommentCardHeader
  • Loading branch information
2wheeh authored May 4, 2024
2 parents c113783 + ddfbec1 commit 38327ed
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions ui/src/components/comment/client/comment-card-header.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
'use client';

import type { ChangeEventHandler } from 'react';

import Title from '@/components/common/client/title';

import { useComment } from '@/context/comment/comment-context';
import { useToast } from '@/context/common/toast-context';

import { useDebouncedCallback } from '@/hooks/common/use-debounced-callback';

import { MAX_MOVIE_NAME_LENGTH } from '@/lib/constants/common';
import { normalizeWhitespace } from '@/lib/utils/common/normalizeWhitespace';

export function CommentCardHeader() {
const { movieName, isEditing, setMovieName, movieNameRef } = useComment();

const { emitToast } = useToast();
const debouncedEmitToast = useDebouncedCallback(emitToast, 1000);

const handleMovieNameChange: ChangeEventHandler<HTMLTextAreaElement> = (e) => {
let newText = e.target.value;

newText = normalizeWhitespace(newText);
if (newText.length > MAX_MOVIE_NAME_LENGTH) {
newText = newText.slice(0, MAX_MOVIE_NAME_LENGTH);
debouncedEmitToast(`영화제목은 ${MAX_MOVIE_NAME_LENGTH}자를 넘을 수 없습니다.`, 'error');
}

setMovieName(newText);
};

return (
<Title
value={movieName}
subtitle
placeholder="영화제목을 입력해 주세요..."
readOnly={!isEditing}
onChange={handleMovieNameChange}
ref={movieNameRef}
/>
);
}

0 comments on commit 38327ed

Please sign in to comment.