Skip to content

There can be more than Notion and Miro. AFFiNE(pronounced [ə‘fain]) is a next-gen knowledge base that brings planning, sorting and creating all together. Privacy first, open-source, customizable and ready to use.

fix(core): delete page (#3419)

Alex Yanga3d665503f35
diff --git a/apps/core/src/components/page-detail-editor.tsx b/apps/core/src/components/page-detail-editor.tsx
index aadcfb8cac..3ceb3e52f9 100644
--- a/apps/core/src/components/page-detail-editor.tsx
+++ b/apps/core/src/components/page-detail-editor.tsx
@@ -24,7 +24,7 @@ import { Panel, PanelGroup, PanelResizeHandle } from 'react-resizable-panels';
import { pageSettingFamily } from '../atoms';
import { fontStyleOptions, useAppSetting } from '../atoms/settings';
import { BlockSuiteEditor as Editor } from './blocksuite/block-suite-editor';
-import TrashButtonGroup from './blocksuite/workspace-header/header-right-items/trash-button-group';
+import { TrashButtonGroup } from './blocksuite/workspace-header/header-right-items/trash-button-group';
import * as styles from './page-detail-editor.css';
import { pluginContainer } from './page-detail-editor.css';
diff --git a/apps/core/src/hooks/use-navigate-helper.ts b/apps/core/src/hooks/use-navigate-helper.ts
index 525f15d7c1..1bed7cf6cf 100644
--- a/apps/core/src/hooks/use-navigate-helper.ts
+++ b/apps/core/src/hooks/use-navigate-helper.ts
@@ -1,4 +1,9 @@
import type { WorkspaceSubPath } from '@affine/env/workspace';
+import {
+ currentPageIdAtom,
+ currentWorkspaceIdAtom,
+} from '@toeverything/plugin-infra/atom';
+import { useSetAtom } from 'jotai';
import { useCallback } from 'react';
// eslint-disable-next-line @typescript-eslint/no-restricted-imports
import { useLocation, useNavigate } from 'react-router-dom';
@@ -11,17 +16,22 @@ export enum RouteLogic {
export function useNavigateHelper() {
const location = useLocation();
const navigate = useNavigate();
+ const setWorkspaceId = useSetAtom(currentWorkspaceIdAtom);
+ const setCurrentPageId = useSetAtom(currentPageIdAtom);
+
const jumpToPage = useCallback(
(
workspaceId: string,
pageId: string,
logic: RouteLogic = RouteLogic.PUSH
) => {
+ setWorkspaceId(workspaceId);
+ setCurrentPageId(pageId);
return navigate(`/workspace/${workspaceId}/${pageId}`, {
replace: logic === RouteLogic.REPLACE,
});
},
- [navigate]
+ [navigate, setCurrentPageId, setWorkspaceId]
);
const jumpToPublicWorkspacePage = useCallback(
(
@@ -29,11 +39,13 @@ export function useNavigateHelper() {
pageId: string,
logic: RouteLogic = RouteLogic.PUSH
) => {
+ setWorkspaceId(workspaceId);
+ setCurrentPageId(pageId);
return navigate(`/public-workspace/${workspaceId}/${pageId}`, {
replace: logic === RouteLogic.REPLACE,
});
},
- [navigate]
+ [navigate, setCurrentPageId, setWorkspaceId]
);
const jumpToSubPath = useCallback(
(
@@ -41,14 +53,18 @@ export function useNavigateHelper() {
subPath: WorkspaceSubPath,
logic: RouteLogic = RouteLogic.PUSH
) => {
+ setWorkspaceId(workspaceId);
+ setCurrentPageId(null);
return navigate(`/workspace/${workspaceId}/${subPath}`, {
replace: logic === RouteLogic.REPLACE,
});
},
- [navigate]
+ [navigate, setCurrentPageId, setWorkspaceId]
);
const openPage = useCallback(
(workspaceId: string, pageId: string) => {
+ setWorkspaceId(workspaceId);
+ setCurrentPageId(pageId);
const isPublicWorkspace =
location.pathname.indexOf('/public-workspace') === 0;
if (isPublicWorkspace) {
@@ -57,25 +73,35 @@ export function useNavigateHelper() {
return jumpToPage(workspaceId, pageId);
}
},
- [jumpToPage, jumpToPublicWorkspacePage, location.pathname]
+ [
+ jumpToPage,
+ jumpToPublicWorkspacePage,
+ location.pathname,
+ setCurrentPageId,
+ setWorkspaceId,
+ ]
);
const jumpToIndex = useCallback(
(logic: RouteLogic = RouteLogic.PUSH) => {
+ setWorkspaceId(null);
+ setCurrentPageId(null);
return navigate('/', {
replace: logic === RouteLogic.REPLACE,
});
},
- [navigate]
+ [navigate, setCurrentPageId, setWorkspaceId]
);
const jumpTo404 = useCallback(
(logic: RouteLogic = RouteLogic.PUSH) => {
+ setWorkspaceId(null);
+ setCurrentPageId(null);
return navigate('/404', {
replace: logic === RouteLogic.REPLACE,
});
},
- [navigate]
+ [navigate, setCurrentPageId, setWorkspaceId]
);
return {