mirror of
https://github.com/docmost/docmost
synced 2025-03-28 21:13:28 +00:00
better page deletion handling
This commit is contained in:
parent
fb057b7801
commit
d33452ad62
@ -7,6 +7,7 @@ import {
|
||||
updatePage,
|
||||
} from '@/features/page/services/page-service';
|
||||
import { IPage } from '@/features/page/types/page.types';
|
||||
import { notifications } from '@mantine/notifications';
|
||||
|
||||
const RECENT_CHANGES_KEY = ['recentChanges'];
|
||||
|
||||
@ -41,5 +42,8 @@ export function useUpdatePageMutation() {
|
||||
export function useDeletePageMutation() {
|
||||
return useMutation({
|
||||
mutationFn: (pageId: string) => deletePage(pageId),
|
||||
onSuccess: () => {
|
||||
notifications.show({ title: 'Page deleted successfully' });
|
||||
},
|
||||
});
|
||||
}
|
||||
|
@ -8,16 +8,19 @@ import {
|
||||
} from 'react-arborist';
|
||||
import { useAtom } from 'jotai';
|
||||
import { treeDataAtom } from '@/features/page/tree/atoms/tree-data-atom';
|
||||
import { createPage, deletePage, movePage } from '@/features/page/services/page-service';
|
||||
import { movePage } from '@/features/page/services/page-service';
|
||||
import { v4 as uuidv4 } from 'uuid';
|
||||
import { IMovePage } from '@/features/page/types/page.types';
|
||||
import { useNavigate } from 'react-router-dom';
|
||||
import { TreeNode } from '@/features/page/tree/types';
|
||||
import { useUpdatePageMutation } from '@/features/page/queries/page';
|
||||
import { useCreatePageMutation, useDeletePageMutation, useUpdatePageMutation } from '@/features/page/queries/page';
|
||||
|
||||
export function usePersistence<T>() {
|
||||
const [data, setData] = useAtom(treeDataAtom);
|
||||
const createPageMutation = useCreatePageMutation();
|
||||
const updatePageMutation = useUpdatePageMutation();
|
||||
const deletePageMutation = useDeletePageMutation();
|
||||
|
||||
const navigate = useNavigate();
|
||||
|
||||
const tree = useMemo(() => new SimpleTree<TreeNode>(data), [data]);
|
||||
@ -75,7 +78,7 @@ export function usePersistence<T>() {
|
||||
}
|
||||
|
||||
try {
|
||||
await createPage(payload);
|
||||
await createPageMutation.mutateAsync(payload);
|
||||
navigate(`/p/${payload.id}`);
|
||||
} catch (error) {
|
||||
console.error('Error creating the page:', error);
|
||||
@ -89,7 +92,8 @@ export function usePersistence<T>() {
|
||||
setData(tree.data);
|
||||
|
||||
try {
|
||||
await deletePage(args.ids[0]);
|
||||
await deletePageMutation.mutateAsync(args.ids[0]);
|
||||
navigate('/home');
|
||||
} catch (error) {
|
||||
console.error('Error deleting page:', error);
|
||||
}
|
||||
|
@ -18,7 +18,7 @@ root.render(
|
||||
<MantineProvider theme={theme}>
|
||||
<ModalsProvider>
|
||||
<TanstackProvider>
|
||||
<Notifications />
|
||||
<Notifications position="top-center" limit={3} />
|
||||
<App />
|
||||
</TanstackProvider>
|
||||
</ModalsProvider>
|
||||
|
@ -20,7 +20,7 @@ export default function Page() {
|
||||
return <div>Loading...</div>;
|
||||
}
|
||||
|
||||
if (isError) {
|
||||
if (isError || !data) { // TODO: fix this
|
||||
return <div>Error fetching page data.</div>;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user