Skip to content

Commit cd98f5d

Browse files
authored
Comment 컴포넌트 관련 구현 (#307)
* feat(constants): comment * feat(api-post): comment api * feat:(modules): comment button * feat:(modules): comment content * feat:(modules): comment input * feat:(modules): comment render * feat:(modules): comment tools * feat:(modules): comment index * feat:(hooks-react-query): comment * feat:(page): comment 컴포넌트 결합
1 parent 0e461dd commit cd98f5d

29 files changed

+727
-22
lines changed

constants/comment/button.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import LANGUAGE from "@Library/language/constant";
2+
3+
import { LanguageInterface } from "@Library/language/interface";
4+
5+
export const COMMENT_INPUT: LanguageInterface = {
6+
[LANGUAGE.ko]: "댓글 작성",
7+
[LANGUAGE.en]: "Writing a comment",
8+
};
9+
10+
export const REPLY_INPUT: LanguageInterface = {
11+
[LANGUAGE.ko]: "답글 작성",
12+
[LANGUAGE.en]: "Writing a reply",
13+
};
14+
15+
export const UPDATE_COMMENT: LanguageInterface = {
16+
[LANGUAGE.ko]: "댓글 수정",
17+
[LANGUAGE.en]: "Updating a comment",
18+
};
19+
20+
export const UPDATE_COMMENT_CANCEL: LanguageInterface = {
21+
[LANGUAGE.ko]: "취소",
22+
[LANGUAGE.en]: "Cancel",
23+
};
24+
25+
export const UPDATE_REPLY: LanguageInterface = {
26+
[LANGUAGE.ko]: "답글 수정",
27+
[LANGUAGE.en]: "Updating a reply",
28+
};

constants/comment/error.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import LANGUAGE from "@Library/language/constant";
2+
3+
import { LanguageInterface } from "@Library/language/interface";
4+
5+
const COMMENT_EMPTY: LanguageInterface = {
6+
[LANGUAGE.ko]: "코멘트를 입력해주세요!",
7+
[LANGUAGE.en]: "Please enter a comment!",
8+
};
9+
10+
export default COMMENT_EMPTY;

constants/comment/index.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import COMMENT_EMPTY from "@Constants/comment/error";
2+
3+
export * from "./reply";
4+
export * from "./placeholder";
5+
export * from "./button";
6+
7+
export { COMMENT_EMPTY };

constants/comment/placeholder.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import LANGUAGE from "@Library/language/constant";
2+
3+
import { LanguageInterface } from "@Library/language/interface";
4+
5+
export const COMMENT_PLACEHOLDER: LanguageInterface = {
6+
[LANGUAGE.ko]: "댓글을 입력하세요.",
7+
[LANGUAGE.en]: "Please enter a comment.",
8+
};
9+
10+
export const REPLY_PLACEHOLDER: LanguageInterface = {
11+
[LANGUAGE.ko]: "답글을 입력하세요.",
12+
[LANGUAGE.en]: "Please enter a reply.",
13+
};

constants/comment/reply.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import LANGUAGE from "@Library/language/constant";
2+
3+
import { LanguageInterface } from "@Library/language/interface";
4+
5+
export const REPLY_OPEN: LanguageInterface = {
6+
[LANGUAGE.ko]: "답글",
7+
[LANGUAGE.en]: "Reply",
8+
};
9+
10+
export const REPLY_CLOSE: LanguageInterface = {
11+
[LANGUAGE.ko]: "닫기",
12+
[LANGUAGE.en]: "Close",
13+
};

lib/api/index.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
import authService from "@Library/api/auth";
22
import categoryService from "@Library/api/category";
3-
import { postService, postLikeService } from "@Library/api/post";
3+
import {
4+
postService,
5+
postLikeService,
6+
commentService,
7+
} from "@Library/api/post";
48
import usersService from "@Library/api/users";
59

610
export default {
@@ -9,4 +13,5 @@ export default {
913
categoryService,
1014
postService,
1115
postLikeService,
16+
commentService,
1217
};
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { AxiosInstance } from "axios";
2+
3+
import { CommentApi, Configuration } from "@til-log.lab/tilog-api";
4+
5+
export default class CommentRepository extends CommentApi {
6+
constructor(
7+
axios?: AxiosInstance,
8+
basePath?: string,
9+
configuration?: Configuration
10+
) {
11+
super(configuration, basePath, axios);
12+
}
13+
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
import { AxiosRequestConfig, AxiosResponse } from "axios";
2+
3+
import validateToken from "@Library/api/auth/validateTokenDecorator";
4+
import CommentRepository from "@Library/api/post/comment/CommentRepository";
5+
6+
import {
7+
CreateCommentsRequestBodyDto,
8+
DeleteCommentRequestDto,
9+
GetCommentsResponseDto,
10+
UpdateCommentRequestDto,
11+
} from "@til-log.lab/tilog-api";
12+
13+
import ExceptionInterface from "@Library/api/exception/interface";
14+
15+
export default class CommentService {
16+
constructor(private readonly commentRepository: CommentRepository) {}
17+
18+
@validateToken()
19+
createComment(
20+
createCommentsRequestBodyDto: CreateCommentsRequestBodyDto,
21+
options?: AxiosRequestConfig
22+
): Promise<AxiosResponse<void, ExceptionInterface>> {
23+
return this.commentRepository.commentsControllerCreateComment(
24+
createCommentsRequestBodyDto,
25+
options
26+
);
27+
}
28+
29+
@validateToken()
30+
deleteComment(
31+
deleteCommentRequestDto: DeleteCommentRequestDto,
32+
options?: AxiosRequestConfig
33+
): Promise<AxiosResponse<void, ExceptionInterface>> {
34+
return this.commentRepository.commentsControllerDeleteComment(
35+
deleteCommentRequestDto,
36+
options
37+
);
38+
}
39+
40+
getComments(
41+
postId: string,
42+
replyTo?: string,
43+
options?: AxiosRequestConfig
44+
): Promise<AxiosResponse<GetCommentsResponseDto, ExceptionInterface>> {
45+
return this.commentRepository.commentsControllerGetComments(
46+
postId,
47+
replyTo,
48+
options
49+
);
50+
}
51+
52+
@validateToken()
53+
updateComment(
54+
updateCommentRequestDto: UpdateCommentRequestDto,
55+
options?: AxiosRequestConfig
56+
): Promise<AxiosResponse<void>> {
57+
return this.commentRepository.commentsControllerUpdateComment(
58+
updateCommentRequestDto,
59+
options
60+
);
61+
}
62+
}

lib/api/post/index.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,19 @@
11
import { TILOG_API } from "@Constants/environment";
22
import httpClient from "@Library/api/httpClient";
3+
import CommentRepository from "@Library/api/post/comment/CommentRepository";
4+
import CommentService from "@Library/api/post/comment/CommentService";
35
import PostLikeRepository from "@Library/api/post/like/postLikeRepository";
46
import PostLikeService from "@Library/api/post/like/postLikeService";
57
import PostRepository from "@Library/api/post/postRepository";
68
import PostService from "@Library/api/post/postService";
79

810
const postRepository = new PostRepository(httpClient.http, TILOG_API);
911
const postLikeRepository = new PostLikeRepository(httpClient.http, TILOG_API);
12+
const commentRepository = new CommentRepository(httpClient.http, TILOG_API);
1013

1114
const postService = new PostService(postRepository);
1215
const postLikeService = new PostLikeService(postLikeRepository);
1316

14-
export { postService, postLikeService };
17+
const commentService = new CommentService(commentRepository);
18+
19+
export { postService, postLikeService, commentService };
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { IoMdClose } from "react-icons/io";
2+
3+
import { useDeleteCommentMutation } from "@Hooks/react-query/comment/useCommentMutation";
4+
5+
import { GetCommentsItem } from "@til-log.lab/tilog-api";
6+
7+
import GetPostDetailRequestDto from "@Library/api/post/interface/getPostDetailRequest";
8+
9+
interface CommentDeleteProps {
10+
commentId: GetCommentsItem["id"];
11+
postId: GetPostDetailRequestDto["postId"];
12+
replyTo: GetCommentsItem["replyTo"];
13+
}
14+
const CommentDelete = ({ commentId, postId, replyTo }: CommentDeleteProps) => {
15+
const { mutate } = useDeleteCommentMutation();
16+
const handleDeleteComment = () => {
17+
mutate({
18+
commentId,
19+
postId,
20+
replyTo,
21+
});
22+
};
23+
return (
24+
<button type="button" onClick={handleDeleteComment}>
25+
<IoMdClose className="text-neutral-700 hover:text-neutral-900 dark:text-neutral-400 dark:hover:text-neutral-300" />
26+
</button>
27+
);
28+
};
29+
export default CommentDelete;

0 commit comments

Comments
 (0)