mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-08-22 20:41:50 +08:00
fix: jump to 404 when be removed from page (#1090)
This commit is contained in:
@@ -14,7 +14,7 @@ import { usePageHelper } from '@/hooks/use-page-helper';
|
|||||||
import dynamic from 'next/dynamic';
|
import dynamic from 'next/dynamic';
|
||||||
import Head from 'next/head';
|
import Head from 'next/head';
|
||||||
import { useTranslation } from '@affine/i18n';
|
import { useTranslation } from '@affine/i18n';
|
||||||
import { useGlobalState } from '@/store/app';
|
import { useGlobalState, useGlobalStateApi } from '@/store/app';
|
||||||
import exampleMarkdown from '@/templates/Welcome-to-AFFiNE-Alpha-Downhills.md';
|
import exampleMarkdown from '@/templates/Welcome-to-AFFiNE-Alpha-Downhills.md';
|
||||||
import { assertEquals } from '@blocksuite/store';
|
import { assertEquals } from '@blocksuite/store';
|
||||||
|
|
||||||
@@ -107,6 +107,7 @@ const PageDefender = ({ children }: PropsWithChildren) => {
|
|||||||
const currentWorkspace = useGlobalState(
|
const currentWorkspace = useGlobalState(
|
||||||
useCallback(store => store.currentDataCenterWorkspace, [])
|
useCallback(store => store.currentDataCenterWorkspace, [])
|
||||||
);
|
);
|
||||||
|
const dataCenter = useGlobalState(store => store.dataCenter);
|
||||||
const { createPage } = usePageHelper();
|
const { createPage } = usePageHelper();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -124,6 +125,16 @@ const PageDefender = ({ children }: PropsWithChildren) => {
|
|||||||
};
|
};
|
||||||
initPage();
|
initPage();
|
||||||
}, [createPage, currentWorkspace, loadPage, router.query.pageId]);
|
}, [createPage, currentWorkspace, loadPage, router.query.pageId]);
|
||||||
|
const api = useGlobalStateApi();
|
||||||
|
useEffect(
|
||||||
|
() =>
|
||||||
|
dataCenter.onWorkspacesChange(({ deleted }) => {
|
||||||
|
if (deleted?.some(workspace => workspace.id === currentWorkspace?.id)) {
|
||||||
|
router.replace('/404?code=kicked');
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
[api, currentWorkspace?.id, dataCenter, router]
|
||||||
|
);
|
||||||
|
|
||||||
return <>{pageLoaded ? children : null}</>;
|
return <>{pageLoaded ? children : null}</>;
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user