mirror of
https://github.com/docmost/docmost.git
synced 2025-11-13 11:32:39 +10:00
page icon emoji picker
This commit is contained in:
@ -1,25 +1,38 @@
|
||||
import { useMutation, useQuery, UseQueryResult, useQueryClient } from '@tanstack/react-query';
|
||||
import {
|
||||
useMutation,
|
||||
useQuery,
|
||||
UseQueryResult,
|
||||
} from "@tanstack/react-query";
|
||||
import {
|
||||
createPage,
|
||||
deletePage,
|
||||
getPageById,
|
||||
getPages,
|
||||
getRecentChanges,
|
||||
updatePage,
|
||||
} from '@/features/page/services/page-service';
|
||||
import { IPage } from '@/features/page/types/page.types';
|
||||
import { notifications } from '@mantine/notifications';
|
||||
} from "@/features/page/services/page-service";
|
||||
import { IPage } from "@/features/page/types/page.types";
|
||||
import { notifications } from "@mantine/notifications";
|
||||
|
||||
const RECENT_CHANGES_KEY = ['recentChanges'];
|
||||
const RECENT_CHANGES_KEY = ["recentChanges"];
|
||||
|
||||
export function usePageQuery(pageId: string): UseQueryResult<IPage, Error> {
|
||||
return useQuery({
|
||||
queryKey: ['pages', pageId],
|
||||
queryKey: ["pages", pageId],
|
||||
queryFn: () => getPageById(pageId),
|
||||
enabled: !!pageId,
|
||||
staleTime: 5 * 60 * 1000,
|
||||
});
|
||||
}
|
||||
|
||||
export function useGetPagesQuery(): UseQueryResult<IPage[], Error> {
|
||||
return useQuery({
|
||||
queryKey: ["pages"],
|
||||
queryFn: () => getPages(),
|
||||
staleTime: 5 * 60 * 1000,
|
||||
});
|
||||
}
|
||||
|
||||
export function useRecentChangesQuery(): UseQueryResult<IPage[], Error> {
|
||||
return useQuery({
|
||||
queryKey: RECENT_CHANGES_KEY,
|
||||
@ -31,17 +44,14 @@ export function useRecentChangesQuery(): UseQueryResult<IPage[], Error> {
|
||||
export function useCreatePageMutation() {
|
||||
return useMutation<IPage, Error, Partial<IPage>>({
|
||||
mutationFn: (data) => createPage(data),
|
||||
onSuccess: (data) => {},
|
||||
});
|
||||
}
|
||||
|
||||
export function useUpdatePageMutation() {
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
return useMutation<IPage, Error, Partial<IPage>>({
|
||||
mutationFn: (data) => updatePage(data),
|
||||
onSuccess: (data) => {
|
||||
queryClient.setQueryData(['pages', data.id], data);
|
||||
},
|
||||
onSuccess: (data) => {},
|
||||
});
|
||||
}
|
||||
|
||||
@ -49,7 +59,7 @@ export function useDeletePageMutation() {
|
||||
return useMutation({
|
||||
mutationFn: (pageId: string) => deletePage(pageId),
|
||||
onSuccess: () => {
|
||||
notifications.show({ message: 'Page deleted successfully' });
|
||||
notifications.show({ message: "Page deleted successfully" });
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user