diff --git a/src/app/dashboard/[subdomain]/editor/portfolio-editor.tsx b/src/app/dashboard/[subdomain]/editor/portfolio-editor.tsx index 2a5e22e0..b3632a77 100644 --- a/src/app/dashboard/[subdomain]/editor/portfolio-editor.tsx +++ b/src/app/dashboard/[subdomain]/editor/portfolio-editor.tsx @@ -60,7 +60,6 @@ export default function PortfolioEditor() { if (!pageId) { const randomId = nanoid() key = `draft-${site.data?.characterId}-!local-${randomId}` - setDraftKey(key) queryClient.invalidateQueries([ "getPagesBySite", site.data?.characterId, @@ -131,6 +130,7 @@ export default function PortfolioEditor() { [visibility], ) + // Save const createPage = useCreatePage() const updatePage = useUpdatePage() @@ -153,30 +153,6 @@ export default function PortfolioEditor() { } } - const deleteP = useDeletePage() - const deletePage = async () => { - if (page.data) { - if (!page.data?.noteId) { - // Is draft - delStorage(`draft-${page.data.characterId}-${page.data.draftKey}`) - } else { - // Is Note - return deleteP.mutate({ - noteId: page.data.noteId, - characterId: page.data.characterId, - }) - } - } - } - - useEffect(() => { - if (deleteP.isSuccess) { - toast.success(t("Deleted!")) - deleteP.reset() - router.push(`/dashboard/${subdomain}/${type}s`) - } - }, [deleteP.isSuccess]) - const { present } = useModalStack() useEffect(() => { @@ -229,6 +205,32 @@ export default function PortfolioEditor() { } }, [createPage.isError, updatePage.isSuccess]) + // Delete + const deleteP = useDeletePage() + const deletePage = async () => { + if (page.data) { + if (!page.data?.noteId) { + // Is draft + delStorage(`draft-${page.data.characterId}-${page.data.draftKey}`) + } else { + // Is Note + return deleteP.mutate({ + noteId: page.data.noteId, + characterId: page.data.characterId, + }) + } + } + } + + useEffect(() => { + if (deleteP.isSuccess) { + toast.success(t("Deleted!")) + deleteP.reset() + router.push(`/dashboard/${subdomain}/${type}s`) + } + }, [deleteP.isSuccess]) + + // Init useEffect(() => { if (!page.data?.metadata || !draftKey) return useEditorState.setState({ @@ -246,6 +248,7 @@ export default function PortfolioEditor() { }) }, [page.data, subdomain, draftKey, site.data?.characterId]) + // Reset const discardChanges = useCallback(() => { if (draftKey) { delStorage(draftKey) diff --git a/src/app/dashboard/[subdomain]/editor/post-editor.tsx b/src/app/dashboard/[subdomain]/editor/post-editor.tsx index 431eb8d4..6709153e 100644 --- a/src/app/dashboard/[subdomain]/editor/post-editor.tsx +++ b/src/app/dashboard/[subdomain]/editor/post-editor.tsx @@ -70,7 +70,6 @@ export default function PostEditor() { if (!pageId) { const randomId = nanoid() key = `draft-${site.data?.characterId}-!local-${randomId}` - setDraftKey(key) queryClient.invalidateQueries([ "getPagesBySite", site.data?.characterId, @@ -348,9 +347,19 @@ export default function PostEditor() { ) }, [page.data, subdomain, draftKey, site.data?.characterId]) - const [view, setView] = useState() + // Reset + const discardChanges = useCallback(() => { + if (draftKey) { + delStorage(draftKey) + queryClient.invalidateQueries(["getPagesBySite", site.data?.characterId]) + page.remove() + page.refetch() + } + }, [draftKey, site.data?.characterId]) // editor + const [view, setView] = useState() + const onCreateEditor = useCallback( (view: EditorView) => { setView?.(view) @@ -389,15 +398,6 @@ export default function PostEditor() { /> ) - const discardChanges = useCallback(() => { - if (draftKey) { - delStorage(draftKey) - queryClient.invalidateQueries(["getPagesBySite", site.data?.characterId]) - page.remove() - page.refetch() - } - }, [draftKey, site.data?.characterId]) - return ( <>