Skip to content

Commit bd317b2

Browse files
committed
feat: comment input (#develop)
1 parent 6585e3f commit bd317b2

File tree

13 files changed

+181
-29
lines changed

13 files changed

+181
-29
lines changed

services/ahhachul.com/src/components/common/comment/commentInput/CommentInput.component.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,10 @@ const SubmitComment = ({
115115
<UiComponent.Checkbox
116116
label="비공개 댓글"
117117
checked={isPrivate}
118-
onChange={e => setIsPrivate(e.target.checked)}
118+
onChange={e => {
119+
setIsPrivate(e.target.checked);
120+
editor.focus();
121+
}}
119122
/>
120123
)}
121124
<S.ButtonGroup>

services/ahhachul.com/src/components/common/comment/commentInput/CommentInput.styled.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export const contentEditableCss = (disalbed: boolean) => (theme: Theme) => css`
77
width: 100%;
88
border: 1px solid ${disalbed ? theme.colors.gray[20] : theme.colors.gray[50]};
99
border-radius: 5px;
10-
padding: 12px;
10+
padding: 12px 16px;
1111
overflow: hidden;
1212
text-wrap: wrap;
1313
color: ${theme.colors.gray[90]};
@@ -33,7 +33,7 @@ export const Container = styled.section`
3333
filter: drop-shadow(0px -1px 12px rgba(0, 0, 0, 0.04));
3434
3535
& > #editor-container {
36-
padding: 12px;
36+
padding: 12px 16px;
3737
background-color: white;
3838
3939
& > div {
@@ -47,7 +47,7 @@ export const Container = styled.section`
4747
}
4848
4949
& > pre {
50-
left: 13px;
50+
left: 16px;
5151
top: 13px;
5252
}
5353
}
@@ -58,13 +58,14 @@ export const SubmitBox = styled.div<{ showIsPrivateBtn?: boolean }>`
5858
width: 100%;
5959
margin: 0 auto;
6060
background: #fff;
61-
padding: 12px 8px;
61+
padding: 12px 16px;
6262
padding-top: 0;
6363
border-radius: 6px;
6464
overflow: hidden;
6565
display: flex;
6666
align-items: center;
6767
justify-content: ${showIsPrivateBtn ? 'space-between' : 'flex-end'};
68+
padding-bottom: 32px;
6869
`}
6970
`;
7071

services/ahhachul.com/src/components/common/comment/commentListItem/CommentListItem.component.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ const Comment = ({ comment, asChild = false }: CommentCardProps) => {
3939
}, [activity.params]);
4040

4141
return (
42-
<S.CommentWrapper asChild={asChild}>
42+
<S.CommentWrapper asChild={asChild} data-comment-id={comment.id}>
4343
<S.HeaderWrapper>
4444
<S.WriterName>{comment.writer}</S.WriterName>
4545
<CommentDropEllipsis
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import { useQueryClient } from '@tanstack/react-query';
2+
3+
import { sleep } from '@ahhachul/utils';
4+
5+
import { UiComponent } from '@/components';
6+
import { useAuth } from '@/contexts';
7+
import { usePostComment } from '@/services/comment';
8+
import { communityKeys } from '@/services/community';
9+
10+
type Props = {
11+
id: number;
12+
};
13+
14+
const CommuntiyCommentInput = ({ id }: Props) => {
15+
const {
16+
authService: { isAuthenticated },
17+
} = useAuth();
18+
const queryClient = useQueryClient();
19+
const communityCommentQueryKey = communityKeys.comments(id);
20+
const { mutate } = usePostComment();
21+
22+
const submitComment = ({ isPrivate, comment }: { isPrivate: boolean; comment: string }) => {
23+
mutate(
24+
{
25+
postId: id,
26+
content: comment,
27+
upperCommentId: null,
28+
isPrivate: isPrivate,
29+
servicePath: 'community-posts',
30+
},
31+
{
32+
onSuccess: async res => {
33+
queryClient.invalidateQueries({
34+
queryKey: communityCommentQueryKey,
35+
});
36+
37+
await sleep(250);
38+
39+
const comment = document.querySelector(`[data-comment-id="${res.result.id}"]`);
40+
if (comment) {
41+
comment.scrollIntoView({
42+
block: 'start',
43+
behavior: 'smooth',
44+
});
45+
}
46+
},
47+
},
48+
);
49+
};
50+
51+
return (
52+
<UiComponent.CommentInput
53+
showIsPrivateBtn
54+
onSubmit={submitComment}
55+
disabled={!isAuthenticated}
56+
placeholder="댓글을 입력해주세요."
57+
/>
58+
);
59+
};
60+
61+
export default CommuntiyCommentInput;

services/ahhachul.com/src/components/domain/community/postDetail/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ export { default as CommunityDetailSkeleton } from './skeleton/CommunityDetail.s
44
export { default as CommunityCommentList } from './commentList/CommunityCommentList.component';
55
export { default as CommunityCategoryBadge } from './categoryBadge/CommunityCategoryBadge.component';
66
export { default as CommunityDetailHeaderActions } from './headerActions/CommunityHeaderActions.component';
7+
export { default as CommuntiyCommentInput } from './commentInput/CommentInput.component';

services/ahhachul.com/src/components/domain/community/postDetail/template/CommunityDetail.component.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ const CommunityDetail = ({ id }: CommunityDetailProps) => {
4444
</S.ArticleWrapper>
4545

4646
<CommunityComponent.CommunityCommentList id={id} commentCnt={post.commentCnt} />
47+
<CommunityComponent.CommuntiyCommentInput id={id} />
48+
<S.Padding />
4749
</>
4850
);
4951
};

services/ahhachul.com/src/components/domain/community/postDetail/template/CommunityDetail.styled.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,3 +96,8 @@ export const LexicalContent = styled.div`
9696
}
9797
}
9898
`;
99+
100+
export const Padding = styled.div`
101+
width: 100%;
102+
height: 234px;
103+
`;
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import { useQueryClient } from '@tanstack/react-query';
2+
3+
import { sleep } from '@ahhachul/utils';
4+
5+
import { UiComponent } from '@/components';
6+
import { useAuth } from '@/contexts';
7+
import { usePostComment } from '@/services/comment';
8+
import { complaintKeys } from '@/services/complaint';
9+
10+
type Props = {
11+
id: number;
12+
};
13+
14+
const ComplaintCommentInput = ({ id }: Props) => {
15+
const {
16+
authService: { isAuthenticated },
17+
} = useAuth();
18+
const queryClient = useQueryClient();
19+
const complaintCommentQueryKey = complaintKeys.comments(id);
20+
const { mutate } = usePostComment();
21+
22+
const submitComment = ({ isPrivate, comment }: { isPrivate: boolean; comment: string }) => {
23+
mutate(
24+
{
25+
postId: id,
26+
content: comment,
27+
upperCommentId: null,
28+
isPrivate: isPrivate,
29+
servicePath: 'complaint-posts',
30+
},
31+
{
32+
onSuccess: async res => {
33+
queryClient.invalidateQueries({
34+
queryKey: complaintCommentQueryKey,
35+
});
36+
37+
await sleep(250);
38+
39+
const comment = document.querySelector(`[data-comment-id="${res.result.id}"]`);
40+
if (comment) {
41+
comment.scrollIntoView({
42+
block: 'start',
43+
behavior: 'smooth',
44+
});
45+
}
46+
},
47+
},
48+
);
49+
};
50+
51+
return (
52+
<UiComponent.CommentInput
53+
showIsPrivateBtn
54+
onSubmit={submitComment}
55+
disabled={!isAuthenticated}
56+
placeholder="댓글을 입력해주세요."
57+
/>
58+
);
59+
};
60+
61+
export default ComplaintCommentInput;

services/ahhachul.com/src/components/domain/complaint/postDetail/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ export { default as ComplaintDetailHeaderActions } from './headerActions/Complai
55
export { default as ComplaintDetailSkeleton } from './skeleton/ComplaintDetail.skeleton';
66
export { default as ComplaintErrorPage } from './error/ComplaintErrorPage.component';
77
export { default as SendComplaintMessage } from './sendMessage/SendMessage.component';
8+
export { default as ComplaintCommentInput } from './commentInput/CommentInput.component';

services/ahhachul.com/src/components/domain/complaint/postDetail/template/ComplaintDetail.component.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ const ComplaintDetail = ({ id }: ComplaintDetailProps) => {
5151
</S.ArticleWrapper>
5252

5353
<ComplaintComponent.ComplaintCommentList id={id} commentCnt={post.commentCnt} />
54+
<ComplaintComponent.ComplaintCommentInput id={id} />
55+
<S.Padding />
5456
</>
5557
);
5658
};

0 commit comments

Comments
 (0)