Fix: 컨벤션 맞지 않는 잘못된 쿼리 수정
This commit is contained in:
parent
e150f68ce2
commit
f501fbe357
@ -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),
|
@ -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),
|
@ -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({
|
@ -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] });
|
||||
},
|
@ -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] });
|
||||
},
|
||||
});
|
||||
}
|
15
frontend/src/queries/comments/useUpdateCommentQuery.ts
Normal file
15
frontend/src/queries/comments/useUpdateCommentQuery.ts
Normal 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] });
|
||||
},
|
||||
});
|
||||
}
|
@ -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) =>
|
||||
|
Loading…
Reference in New Issue
Block a user