Fix: 컨벤션 맞지 않는 잘못된 쿼리 수정

This commit is contained in:
정현조 2024-09-29 22:04:34 +09:00
parent e150f68ce2
commit f501fbe357
7 changed files with 26 additions and 27 deletions

View File

@ -1,7 +1,7 @@
import { getCommentList } from '@/api/commentAPi';
import { useSuspenseQuery } from '@tanstack/react-query';
export default function useGetCommentListQuery(projectId: number, imageId: number) {
export default function useCommentListQuery(projectId: number, imageId: number) {
return useSuspenseQuery({
queryKey: ['commentList', projectId, imageId],
queryFn: () => getCommentList(projectId, imageId),

View File

@ -1,7 +1,7 @@
import { getComment } from '@/api/commentAPi';
import { useSuspenseQuery } from '@tanstack/react-query';
export default function useGetCommentQuery(projectId: number, commentId: number) {
export default function useCommentQuery(projectId: number, commentId: number) {
return useSuspenseQuery({
queryKey: ['comment', projectId, commentId],
queryFn: () => getComment(projectId, commentId),

View File

@ -2,7 +2,7 @@ import { createComment } from '@/api/commentAPi';
import { useMutation, useQueryClient } from '@tanstack/react-query';
import { CommentResponse } from '@/types';
export default function useCreateCommentMutation(projectId: number, imageId: number) {
export default function useCreateCommentQuery(projectId: number, imageId: number) {
const queryClient = useQueryClient();
return useMutation({

View File

@ -1,11 +1,11 @@
import { deleteComment } from '@/api/commentAPi';
import { useMutation, useQueryClient } from '@tanstack/react-query';
export default function useDeleteCommentMutation(projectId: number, commentId: number) {
export default function useDeleteCommentQuery(projectId: number) {
const queryClient = useQueryClient();
return useMutation({
mutationFn: () => deleteComment(projectId, commentId),
mutationFn: (commentId: number) => deleteComment(projectId, commentId),
onSuccess: () => {
queryClient.invalidateQueries({ queryKey: ['commentList', projectId] });
},

View File

@ -1,15 +0,0 @@
import { updateComment } from '@/api/commentAPi';
import { useMutation, useQueryClient } from '@tanstack/react-query';
import { CommentResponse } from '@/types';
export default function useUpdateCommentMutation(projectId: number, commentId: number) {
const queryClient = useQueryClient();
return useMutation({
mutationFn: (commentData: CommentResponse) => updateComment(projectId, commentId, commentData),
onSuccess: () => {
queryClient.invalidateQueries({ queryKey: ['comment', projectId, commentId] });
queryClient.invalidateQueries({ queryKey: ['commentList', projectId] });
},
});
}

View File

@ -0,0 +1,15 @@
import { updateComment } from '@/api/commentAPi';
import { useMutation, useQueryClient } from '@tanstack/react-query';
import { CommentRequest } from '@/types';
export default function useUpdateCommentQuery(projectId: number) {
const queryClient = useQueryClient();
return useMutation({
mutationFn: ({ commentId, commentData }: { commentId: number; commentData: CommentRequest }) =>
updateComment(projectId, commentId, commentData),
onSuccess: () => {
queryClient.invalidateQueries({ queryKey: ['commentList', projectId] });
},
});
}

View File

@ -4,34 +4,33 @@ import { CommentResponse } from '@/types';
interface CommentWithToggle extends CommentResponse {
isOpen?: boolean;
}
interface CommentState {
comments: CommentWithToggle[];
addComment: (comment: CommentResponse) => void;
updateComment: (updatedComment: CommentResponse) => void;
setComments: (comments: CommentWithToggle[]) => void;
addComment: (comment: CommentWithToggle) => void;
updateComment: (updatedComment: CommentWithToggle) => void;
deleteComment: (commentId: number) => void;
toggleComment: (commentId: number) => void;
}
const useCommentStore = create<CommentState>((set) => ({
comments: [],
setComments: (comments) => set({ comments }),
addComment: (comment) =>
set((state) => ({
comments: [...state.comments, { ...comment, isOpen: false }],
comments: [...state.comments, { ...comment, isOpen: true }],
})),
updateComment: (updatedComment) =>
set((state) => ({
comments: state.comments.map((comment) =>
comment.id === updatedComment.id ? { ...updatedComment, isOpen: comment.isOpen } : comment
),
})),
deleteComment: (commentId) =>
set((state) => ({
comments: state.comments.filter((comment) => comment.id !== commentId),
})),
toggleComment: (commentId) =>
set((state) => ({
comments: state.comments.map((comment) =>