1- import {
2- useQuery ,
3- useMutation ,
4- useQueryClient ,
5- skipToken ,
6- } from "@tanstack/react-query" ;
1+ import { useQuery , useMutation , skipToken } from "@tanstack/react-query" ;
72
8- import {
9- getPages ,
10- createPage ,
11- deletePage ,
12- getPage ,
13- } from "@/entities/page/api/pageApi" ;
3+ import { createPage , deletePage , getPage } from "@/entities/page/api/pageApi" ;
144import { CreatePageRequest } from "@/entities/page/model/pageTypes" ;
155
166export const usePage = ( currentPage : number | null ) => {
@@ -27,33 +17,14 @@ export const usePage = (currentPage: number | null) => {
2717} ;
2818
2919export const useCreatePage = ( ) => {
30- const queryClient = useQueryClient ( ) ;
31-
3220 return useMutation ( {
3321 mutationFn : ( { title, content, x, y, emoji } : CreatePageRequest ) =>
3422 createPage ( { title, content, x, y, emoji } ) ,
35- onSuccess : ( ) => {
36- queryClient . invalidateQueries ( { queryKey : [ "pages" ] } ) ;
37- } ,
3823 } ) ;
3924} ;
4025
4126export const useDeletePage = ( ) => {
42- const queryClient = useQueryClient ( ) ;
43-
4427 return useMutation ( {
4528 mutationFn : ( { id } : { id : number } ) => deletePage ( id ) ,
46- onSuccess : ( ) => {
47- queryClient . invalidateQueries ( { queryKey : [ "pages" ] } ) ;
48- } ,
49- } ) ;
50- } ;
51-
52- export const usePages = ( workspaceId : string ) => {
53- const { data : pages , isError } = useQuery ( {
54- queryKey : [ "pages" , workspaceId ] ,
55- queryFn : workspaceId ? ( ) => getPages ( workspaceId ) : skipToken ,
5629 } ) ;
57-
58- return { pages, isError } ;
5930} ;
0 commit comments