diff --git a/frontend/src/queries/folders/useCreateFolderQuery.ts b/frontend/src/queries/folders/useCreateFolderQuery.ts new file mode 100644 index 0000000..edc62b3 --- /dev/null +++ b/frontend/src/queries/folders/useCreateFolderQuery.ts @@ -0,0 +1,23 @@ +import { useMutation, useQueryClient } from '@tanstack/react-query'; +import { createFolder } from '@/api/folderApi'; +import { FolderRequest } from '@/types'; + +interface CreateFolderMutationVariables { + projectId: number; + memberId: number; + folderData: FolderRequest; +} + +export default function useCreateFolderQuery() { + const queryClient = useQueryClient(); + + return useMutation({ + mutationFn: ({ projectId, memberId, folderData }: CreateFolderMutationVariables) => + createFolder(projectId, memberId, folderData), + onSuccess: (_, variables) => { + queryClient.invalidateQueries({ + queryKey: ['folderList', variables.projectId, variables.memberId], + }); + }, + }); +} diff --git a/frontend/src/queries/folders/useDeleteFolderQuery.ts b/frontend/src/queries/folders/useDeleteFolderQuery.ts new file mode 100644 index 0000000..d3e84b0 --- /dev/null +++ b/frontend/src/queries/folders/useDeleteFolderQuery.ts @@ -0,0 +1,22 @@ +import { useMutation, useQueryClient } from '@tanstack/react-query'; +import { deleteFolder } from '@/api/folderApi'; + +interface DeleteFolderMutationVariables { + projectId: number; + folderId: number; + memberId: number; +} + +export default function useDeleteFolderQuery() { + const queryClient = useQueryClient(); + + return useMutation({ + mutationFn: ({ projectId, folderId, memberId }: DeleteFolderMutationVariables) => + deleteFolder(projectId, folderId, memberId), + onSuccess: (_, variables) => { + queryClient.invalidateQueries({ + queryKey: ['folderList', variables.projectId, variables.folderId], + }); + }, + }); +} diff --git a/frontend/src/queries/folders/useUpdateFolderQuery.ts b/frontend/src/queries/folders/useUpdateFolderQuery.ts new file mode 100644 index 0000000..36525e8 --- /dev/null +++ b/frontend/src/queries/folders/useUpdateFolderQuery.ts @@ -0,0 +1,24 @@ +import { useMutation, useQueryClient } from '@tanstack/react-query'; +import { updateFolder } from '@/api/folderApi'; +import { FolderRequest } from '@/types'; + +interface UpdateFolderMutationVariables { + projectId: number; + folderId: number; + memberId: number; + folderData: FolderRequest; +} + +export default function useUpdateFolderQuery() { + const queryClient = useQueryClient(); + + return useMutation({ + mutationFn: ({ projectId, folderId, memberId, folderData }: UpdateFolderMutationVariables) => + updateFolder(projectId, folderId, memberId, folderData), + onSuccess: (_, variables) => { + queryClient.invalidateQueries({ + queryKey: ['folderList', variables.projectId, variables.folderId], + }); + }, + }); +} diff --git a/frontend/src/queries/images/useChangeImageStatusQuery.ts b/frontend/src/queries/images/useChangeImageStatusQuery.ts deleted file mode 100644 index d295412..0000000 --- a/frontend/src/queries/images/useChangeImageStatusQuery.ts +++ /dev/null @@ -1,18 +0,0 @@ -import { useMutation } from '@tanstack/react-query'; -import { changeImageStatus } from '@/api/imageApi'; -import { ImageStatusChangeRequest } from '@/types'; - -export default function useChangeImageStatusQuery(onSuccess?: () => void) { - return useMutation({ - mutationFn: ({ - imageId, - memberId, - statusChangeRequest, - }: { - imageId: number; - memberId: number; - statusChangeRequest: ImageStatusChangeRequest; - }) => changeImageStatus(imageId, memberId, statusChangeRequest), - onSuccess, - }); -} diff --git a/frontend/src/queries/images/useDeleteImageQuery.ts b/frontend/src/queries/images/useDeleteImageQuery.ts new file mode 100644 index 0000000..30dce4d --- /dev/null +++ b/frontend/src/queries/images/useDeleteImageQuery.ts @@ -0,0 +1,18 @@ +import { useMutation, useQueryClient } from '@tanstack/react-query'; +import { deleteImage } from '@/api/imageApi'; + +interface DeleteImageMutationVariables { + imageId: number; + memberId: number; +} + +export default function useDeleteImageQuery() { + const queryClient = useQueryClient(); + + return useMutation({ + mutationFn: ({ imageId, memberId }: DeleteImageMutationVariables) => deleteImage(imageId, memberId), + onSuccess: (_, variables) => { + queryClient.invalidateQueries({ queryKey: ['image', variables.imageId] }); + }, + }); +} diff --git a/frontend/src/queries/images/useImageQuery.ts b/frontend/src/queries/images/useImageQuery.ts new file mode 100644 index 0000000..e4ed924 --- /dev/null +++ b/frontend/src/queries/images/useImageQuery.ts @@ -0,0 +1,9 @@ +import { getImage } from '@/api/imageApi'; +import { useSuspenseQuery } from '@tanstack/react-query'; + +export default function useImageQuery(imageId: number, memberId: number) { + return useSuspenseQuery({ + queryKey: ['image', imageId, memberId], + queryFn: () => getImage(imageId, memberId), + }); +} diff --git a/frontend/src/queries/images/useMoveImageQuery.ts b/frontend/src/queries/images/useMoveImageQuery.ts new file mode 100644 index 0000000..9558389 --- /dev/null +++ b/frontend/src/queries/images/useMoveImageQuery.ts @@ -0,0 +1,21 @@ +import { useMutation, useQueryClient } from '@tanstack/react-query'; +import { moveImage } from '@/api/imageApi'; +import { ImageMoveRequest } from '@/types'; + +interface MoveImageMutationVariables { + imageId: number; + memberId: number; + moveRequest: ImageMoveRequest; +} + +export default function useMoveImageQuery() { + const queryClient = useQueryClient(); + + return useMutation({ + mutationFn: ({ imageId, memberId, moveRequest }: MoveImageMutationVariables) => + moveImage(imageId, memberId, moveRequest), + onSuccess: (_, variables) => { + queryClient.invalidateQueries({ queryKey: ['image', variables.imageId] }); + }, + }); +}