Skip to content

Commit 8914f26

Browse files
authored
refactor: 웹 커뮤니티 하위 css tailwind로 전환 (#178)
* refactor: CommentWrite tailwind conversion * refactor: Comments tailwind conversion * remove: 미사용 코드 삭제 * feat: 댓글 작성 완료시 초기화
1 parent 16034ec commit 8914f26

5 files changed

Lines changed: 45 additions & 228 deletions

File tree

src/app/community/[boardCode]/[postId]/CommentWrite.tsx

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
"use client";
22

3-
import { useRouter } from "next/navigation";
4-
import { useRef } from "react";
3+
import { useRef, useState } from "react";
54

65
import { createCommentApi } from "@/services/community";
76

8-
import styles from "./comment-write.module.css";
9-
107
import { IconCloseFilled, IconFlight } from "@/public/svgs";
118

129
type CommentWriteProps = {
@@ -17,17 +14,16 @@ type CommentWriteProps = {
1714
};
1815

1916
const CommentWrite = ({ postId, curSelectedComment, setCurSelectedComment, onSuccess }: CommentWriteProps) => {
20-
const router = useRouter();
21-
const contentRef = useRef<HTMLInputElement>(null);
17+
const [content, setContent] = useState<string>("");
2218

2319
const submitComment = async () => {
2420
try {
2521
await createCommentApi({
2622
postId: postId,
27-
content: contentRef.current?.value || "",
23+
content: content,
2824
parentId: curSelectedComment,
2925
});
30-
// router.refresh();
26+
setContent("");
3127
onSuccess();
3228
} catch (err) {
3329
if (err.response) {
@@ -50,13 +46,13 @@ const CommentWrite = ({ postId, curSelectedComment, setCurSelectedComment, onSuc
5046
};
5147

5248
return (
53-
<div className={styles["comment-form"]}>
54-
<div className={styles["comment-input"]}>
49+
<div className="fixed bottom-14 flex w-full min-w-[360px] max-w-[600px] items-center gap-3 border-t border-[#ececec] bg-k-0 p-2">
50+
<div className="w-full">
5551
{curSelectedComment && (
56-
<div className={styles["comment-input-reply"]}>
57-
<div>답글을 입력중입니다..</div>
52+
<div className="flex h-10 w-full items-center justify-between rounded-t-lg bg-[#e2e2e2] px-2.5 pb-2.5 pt-3">
53+
<span className="text-xs font-normal leading-normal text-[#808080]">답글을 입력중입니다..</span>
5854
<button
59-
className={styles["comment-input-close"]}
55+
className="cursor-pointer border-none bg-transparent"
6056
onClick={handleCloseComment}
6157
type="button"
6258
aria-label="답글 작성 취소"
@@ -65,9 +61,20 @@ const CommentWrite = ({ postId, curSelectedComment, setCurSelectedComment, onSuc
6561
</button>
6662
</div>
6763
)}
68-
<input ref={contentRef} type="text" placeholder="댓글을 입력해 주세요" />
64+
<input
65+
className="h-10 w-full overflow-hidden text-ellipsis rounded-lg border-none bg-[#ececec] p-2.5 text-sm font-normal leading-normal outline-none placeholder:text-[#808080]"
66+
value={content}
67+
onChange={(e) => setContent(e.target.value)}
68+
type="text"
69+
placeholder="댓글을 입력해 주세요"
70+
/>
6971
</div>
70-
<button className={styles["comment-submit"]} onClick={submitComment} type="button" aria-label="댓글 작성">
72+
<button
73+
className="mb-2 mr-1 mt-auto cursor-pointer border-none bg-transparent"
74+
onClick={submitComment}
75+
type="button"
76+
aria-label="댓글 작성"
77+
>
7178
<IconFlight />
7279
</button>
7380
</div>

src/app/community/[boardCode]/[postId]/Comments.tsx

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import Image from "next/image";
22
import { useState } from "react";
33

4+
import clsx from "clsx";
5+
46
import { deleteCommentApi } from "@/services/community";
57
import { convertISODateToDateTime } from "@/utils/datetimeUtils";
68

7-
import Dropdown from "@/components/ui/Dropdown";
8-
9-
import styles from "./comments.module.css";
9+
import Dropdown from "@/components/ui/dropdown";
1010

1111
import { Comment } from "@/types/community";
1212

@@ -15,12 +15,11 @@ import { IconMoreVertFilled, IconSubComment } from "@/public/svgs";
1515
type CommentsProps = {
1616
comments: Comment[];
1717
postId: number;
18-
refresh: () => void;
1918
setCurSelectedComment: React.Dispatch<React.SetStateAction<number | null>>;
2019
onSuccess: () => void;
2120
};
2221

23-
const Comments = ({ comments, postId, refresh, setCurSelectedComment, onSuccess }: CommentsProps) => {
22+
const Comments = ({ comments, postId, setCurSelectedComment, onSuccess }: CommentsProps) => {
2423
const [activeDropdown, setActiveDropdown] = useState<number | null>(null);
2524

2625
const toggleDeleteComment = (commentId: number) => {
@@ -50,12 +49,13 @@ const Comments = ({ comments, postId, refresh, setCurSelectedComment, onSuccess
5049
};
5150

5251
return (
53-
<div className={styles["comment-container"]}>
52+
<div className="h-[50vh] pb-[49px]">
5453
{comments?.map((comment) => (
5554
<div
56-
className={`${styles["comment-wrapper"]} ${
57-
comment.parentId !== null && styles["comment-wrapper--sub-comment"]
58-
}`}
55+
className={clsx(
56+
"flex border-b border-[#ececec] px-5 py-[18px]",
57+
comment.parentId !== null ? "bg-[#f2f2f2]" : "bg-[#fafafa]",
58+
)}
5959
key={comment.id}
6060
role="button"
6161
tabIndex={0}
@@ -76,15 +76,16 @@ const Comments = ({ comments, postId, refresh, setCurSelectedComment, onSuccess
7676
}}
7777
>
7878
{comment.parentId !== null && (
79-
<div className={styles["comment__sub-comment-icon"]}>
79+
<div className="mr-1.5">
8080
<IconSubComment />
8181
</div>
8282
)}
83-
<div className={styles.comment}>
84-
<div className={styles["comment__first-row"]}>
85-
<div className={styles.comment__author}>
86-
<div className={styles["comment__author-profile-image"]}>
83+
<div className="flex w-full flex-col">
84+
<div className="flex justify-between">
85+
<div className="flex items-center gap-2">
86+
<div className="h-[25px] w-[25px] rounded-full bg-[#d9d9d9]">
8787
<Image
88+
className="h-full w-full rounded-full"
8889
src={
8990
comment.postFindSiteUserResponse.profileImageUrl
9091
? `${process.env.NEXT_PUBLIC_UPLOADED_IMAGE_URL}/${comment.postFindSiteUserResponse.profileImageUrl}`
@@ -95,12 +96,14 @@ const Comments = ({ comments, postId, refresh, setCurSelectedComment, onSuccess
9596
alt="alt"
9697
/>
9798
</div>
98-
<div className={styles["comment__author-name"]}>{comment.postFindSiteUserResponse.nickname}</div>
99+
<div className="overflow-hidden text-sm font-medium leading-normal text-black">
100+
{comment.postFindSiteUserResponse.nickname}
101+
</div>
99102
</div>
100103
{comment.isOwner && (
101-
<div className={styles["comment__kebab-menu-wrapper"]}>
104+
<div className="relative">
102105
<button
103-
className={styles["comment__kebab-menu"]}
106+
className="cursor-pointer"
104107
onClick={() => toggleDropdown(comment.id)}
105108
type="button"
106109
aria-label="더보기"
@@ -122,9 +125,9 @@ const Comments = ({ comments, postId, refresh, setCurSelectedComment, onSuccess
122125
</div>
123126
)}
124127
</div>
125-
<div className={styles.comment__content}>{comment.content}</div>
126-
<div className={styles["comment__created-at"]}>
127-
{convertISODateToDateTime(comment.createdAt) || "1970. 1. 1. 00:00"}
128+
<div className="mt-3 text-sm font-normal leading-normal text-black">{comment.content}</div>
129+
<div className="mt-2 overflow-hidden text-xs font-normal leading-normal text-[#7c7c7c]">
130+
{convertISODateToDateTime(comment.createdAt) || "1970. 01. 01. 00:00"}
128131
</div>
129132
</div>
130133
</div>

src/app/community/[boardCode]/[postId]/PostPageContent.tsx

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,6 @@ const PostPageContent = ({ boardCode, postId }: PostPageContentProps) => {
6969
<Comments
7070
comments={post.postFindCommentResponses}
7171
postId={postId}
72-
refresh={() => {
73-
router.refresh();
74-
}}
7572
setCurSelectedComment={setCurSelectedComment}
7673
onSuccess={fetchPosts}
7774
/>

src/app/community/[boardCode]/[postId]/comment-write.module.css

Lines changed: 0 additions & 92 deletions
This file was deleted.

src/app/community/[boardCode]/[postId]/comments.module.css

Lines changed: 0 additions & 98 deletions
This file was deleted.

0 commit comments

Comments
 (0)