Skip to content

Commit

Permalink
Merge pull request #252 from MovieReviewComment/feature/issue-233/rev…
Browse files Browse the repository at this point in the history
…iew-title

[#233] Implement ReviewTitle
  • Loading branch information
2wheeh authored Mar 11, 2024
2 parents 24bf4b8 + 3398d6d commit 8394345
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 0 deletions.
52 changes: 52 additions & 0 deletions ui/src/components/review/client/review-title.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
'use client';

import Title from '@/components/common/client/title';
import { useReview } from '@/context/review/review-context';
import { useToast } from '@/context/common/toast-context';
import { useDebouncedCallback } from '@/hooks/common/use-debounced-callback';
import { MAX_TITLE_LENGTH } from '@/lib/constants/review';
import { MAX_MOVIE_NAME_LENGTH } from '@/lib/constants/common';
import { normalizeWhitespace } from '@/lib/utils/common/normalizeWhitespace';

export default function ReviewTitle({
placeholder,
isMovieName,
}: {
placeholder: string;
isMovieName?: boolean;
}) {
const { title, movieName, setTitle, setMovieName, titleRef, movieNameRef } = useReview();

const [value, setValue, ref, maxLength] = isMovieName
? [movieName, setMovieName, movieNameRef, MAX_MOVIE_NAME_LENGTH]
: [title, setTitle, titleRef, MAX_TITLE_LENGTH];

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

const onChange = (e: React.ChangeEvent<HTMLTextAreaElement>) => {
let newText = normalizeWhitespace(e.target.value);

// limit length
if (newText.length > maxLength) {
newText = newText.slice(0, maxLength);

debouncedEmitToast(
`${isMovieName ? '영화 제목' : '제목'}${maxLength}자 이하로 입력해주세요.`,
'error'
);
}

setValue(newText);
};

return (
<Title
placeholder={placeholder}
subtitle={isMovieName}
value={value}
onChange={onChange}
ref={ref}
/>
);
}
1 change: 1 addition & 0 deletions ui/src/lib/constants/common.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const MAX_MOVIE_NAME_LENGTH = 100;
2 changes: 2 additions & 0 deletions ui/src/lib/constants/review.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export const MAX_TITLE_LENGTH = 100;
export const MAX_CONTENT_LENGTH = 2000;

0 comments on commit 8394345

Please sign in to comment.