-
Notifications
You must be signed in to change notification settings - Fork 6
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
Fix: 댓글 폼 TextArea로 수정, 댓글/답글 관련 버그 수정 #210
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -52,17 +52,25 @@ export const formContainer = style({ | |
}); | ||
|
||
export const formInput = style({ | ||
width: 'inherit', | ||
height: 'auto', | ||
width: '100%', | ||
height: '20px', | ||
maxHeight: '60px', | ||
|
||
flex: '1 0 0', | ||
|
||
display: 'block', | ||
overflow: 'hidden', | ||
resize: 'none', | ||
outline: 'none', | ||
border: 'none', | ||
fontSize: '1.6rem', | ||
wordBreak: 'break-all', | ||
wordWrap: 'break-word', | ||
whiteSpace: 'pre-wrap', | ||
resize: 'none', | ||
backgroundColor: vars.color.gray3, | ||
'::-webkit-scrollbar': { | ||
display: 'none', | ||
}, | ||
Comment on lines
70
to
+73
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 오! textarea에서 스크롤이 보이지 않게 하는 속성인가요? 🎨 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 오 네네..!! overflow scroll에서 hidden으로 바꾸면서 필요없는 코드가 되어버렸네요🤔 삭제해야하는 코드인데 발견해주셔서 감사합니다!! 🥹 |
||
}); | ||
|
||
export const replyNickname = style({ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,7 +16,7 @@ import { QUERY_KEYS } from '@/lib/constants/queryKeys'; | |
import { CommentType } from '@/lib/types/commentType'; | ||
import { UserType } from '@/lib/types/userProfileType'; | ||
import { useUser } from '@/store/useUser'; | ||
import { useReplyId, useCommentId, useCommentIdStore, useIsEditing } from '@/store/useComment'; | ||
import { useReplyId, useCommentId, useCommentIdStore, useIsEditing, useCommentStatus } from '@/store/useComment'; | ||
import Modal from '@/components/Modal/Modal'; | ||
import CommentForm from './CommentForm'; | ||
import LoginModal from '@/components/login/LoginModal'; | ||
|
@@ -39,8 +39,8 @@ function Comments() { | |
const { replyId, deleteReplyId } = useReplyId(); | ||
const { commentId, setCommentId, deleteCommentId } = useCommentId(); | ||
const { setIsEditing, setIsNotEditing, isEditing } = useIsEditing(); | ||
const { status, resetStatus } = useCommentStatus(); | ||
const bottomRef = useRef<HTMLDivElement>(null); | ||
const replyBottomRef = useRef<HTMLDivElement>(null); | ||
|
||
//zustand로 관리하는 user정보 불러오기 | ||
const { user } = useUser(); | ||
|
@@ -103,8 +103,12 @@ function Comments() { | |
} | ||
}; | ||
|
||
const handleSetComment = (comment: string) => { | ||
setComment(comment); | ||
}; | ||
|
||
//댓글 폼 사용(추후 리액트 훅폼으로 수정해 볼 예정) | ||
const handleInputChange = (e: ChangeEvent<HTMLInputElement>) => { | ||
const handleInputChange = (e: ChangeEvent<HTMLTextAreaElement>) => { | ||
setComment(e.target.value); | ||
}; | ||
|
||
|
@@ -121,6 +125,7 @@ function Comments() { | |
setComment(''); | ||
deleteCommentId(); | ||
deleteReplyId(); | ||
resetStatus(); | ||
}; | ||
|
||
//댓글 생성 리액트 쿼리 함수 | ||
|
@@ -154,6 +159,7 @@ function Comments() { | |
deleteCommentId(); | ||
setActiveNickname(null); | ||
setIsPending(false); | ||
resetStatus(); | ||
}, | ||
}); | ||
|
||
|
@@ -170,6 +176,7 @@ function Comments() { | |
setComment(''); | ||
deleteCommentId(); | ||
setIsNotEditing(); | ||
resetStatus(); | ||
setIsPending(false); | ||
}, | ||
}); | ||
|
@@ -181,7 +188,7 @@ function Comments() { | |
setIsPending(true); | ||
}, | ||
onSuccess: () => { | ||
queryClient.invalidateQueries({ queryKey: [QUERY_KEYS.getComments, commentId] }); | ||
queryClient.invalidateQueries({ queryKey: [QUERY_KEYS.getComments] }); | ||
addCommentId(commentId as number); | ||
scrollToRef(); | ||
}, | ||
|
@@ -191,21 +198,22 @@ function Comments() { | |
deleteReplyId(); | ||
setIsNotEditing(); | ||
setIsPending(false); | ||
resetStatus(); | ||
}, | ||
}); | ||
|
||
//댓글/답글 폼 submit 함수 | ||
const handleSubmit = (e: React.FormEvent<HTMLFormElement>) => { | ||
const handleSubmit = (e: React.FormEvent<HTMLFormElement> | React.KeyboardEvent<HTMLTextAreaElement>) => { | ||
e.preventDefault(); | ||
Comment on lines
-198
to
207
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 명확한 타입지정 너무 좋네요!! 👍👍 |
||
if (!comment.trim()) { | ||
return null; | ||
} | ||
if (comment.trim()) { | ||
if (commentId && activeNickname) { | ||
if (status === 'createReply' && commentId && activeNickname) { | ||
createReplyMutation.mutate(); | ||
return; | ||
} | ||
if (isEditing) { | ||
if (status === 'edit') { | ||
if (replyId) { | ||
editReplyMutation.mutate(); | ||
return; | ||
|
@@ -276,9 +284,10 @@ function Comments() { | |
) : ( | ||
<Comment | ||
comment={item} | ||
onUpdate={setActiveNickname} | ||
setActiveNickname={setActiveNickname} | ||
activeNickname={activeNickname} | ||
handleSetCommentId={handleSetCommentId} | ||
handleSetComment={handleSetComment} | ||
listId={Number(params?.listId)} | ||
commentId={item.id} | ||
currentUserInfo={userInformation} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
interface IProps { | ||
handleSubmit: (e: React.FormEvent<HTMLFormElement> | React.KeyboardEvent<HTMLTextAreaElement>) => void; | ||
isSubmitting: boolean; | ||
} | ||
|
||
function usePressEnterFetch({ handleSubmit, isSubmitting }: IProps) { | ||
Comment on lines
+1
to
+6
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 나현님 혹시 props 타입이름을 함수명+props로 변경하면 어떨까용?? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 앗 코드 고대로 복붙해온 거 깜빡했어용..머쓱 ㅎㅎㅎ 타입명 수정해두겠습니당!!👍 감사합니다 소현님 🙇♀️ |
||
const handlePressEnterFetch = (e: React.KeyboardEvent<HTMLTextAreaElement>) => { | ||
if (e.key === 'Enter' && !e.shiftKey && !isSubmitting) { | ||
e.preventDefault(); | ||
handleSubmit(e); | ||
} | ||
}; | ||
|
||
return { handlePressEnterFetch }; | ||
} | ||
|
||
export default usePressEnterFetch; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍👍👍