fix(core): delete page (#3419)
This commit is contained in:
@@ -24,7 +24,7 @@ import { Panel, PanelGroup, PanelResizeHandle } from 'react-resizable-panels';
|
|||||||
import { pageSettingFamily } from '../atoms';
|
import { pageSettingFamily } from '../atoms';
|
||||||
import { fontStyleOptions, useAppSetting } from '../atoms/settings';
|
import { fontStyleOptions, useAppSetting } from '../atoms/settings';
|
||||||
import { BlockSuiteEditor as Editor } from './blocksuite/block-suite-editor';
|
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 * as styles from './page-detail-editor.css';
|
||||||
import { pluginContainer } from './page-detail-editor.css';
|
import { pluginContainer } from './page-detail-editor.css';
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,9 @@
|
|||||||
import type { WorkspaceSubPath } from '@affine/env/workspace';
|
import type { WorkspaceSubPath } from '@affine/env/workspace';
|
||||||
|
import {
|
||||||
|
currentPageIdAtom,
|
||||||
|
currentWorkspaceIdAtom,
|
||||||
|
} from '@toeverything/plugin-infra/atom';
|
||||||
|
import { useSetAtom } from 'jotai';
|
||||||
import { useCallback } from 'react';
|
import { useCallback } from 'react';
|
||||||
// eslint-disable-next-line @typescript-eslint/no-restricted-imports
|
// eslint-disable-next-line @typescript-eslint/no-restricted-imports
|
||||||
import { useLocation, useNavigate } from 'react-router-dom';
|
import { useLocation, useNavigate } from 'react-router-dom';
|
||||||
@@ -11,17 +16,22 @@ export enum RouteLogic {
|
|||||||
export function useNavigateHelper() {
|
export function useNavigateHelper() {
|
||||||
const location = useLocation();
|
const location = useLocation();
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
|
const setWorkspaceId = useSetAtom(currentWorkspaceIdAtom);
|
||||||
|
const setCurrentPageId = useSetAtom(currentPageIdAtom);
|
||||||
|
|
||||||
const jumpToPage = useCallback(
|
const jumpToPage = useCallback(
|
||||||
(
|
(
|
||||||
workspaceId: string,
|
workspaceId: string,
|
||||||
pageId: string,
|
pageId: string,
|
||||||
logic: RouteLogic = RouteLogic.PUSH
|
logic: RouteLogic = RouteLogic.PUSH
|
||||||
) => {
|
) => {
|
||||||
|
setWorkspaceId(workspaceId);
|
||||||
|
setCurrentPageId(pageId);
|
||||||
return navigate(`/workspace/${workspaceId}/${pageId}`, {
|
return navigate(`/workspace/${workspaceId}/${pageId}`, {
|
||||||
replace: logic === RouteLogic.REPLACE,
|
replace: logic === RouteLogic.REPLACE,
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
[navigate]
|
[navigate, setCurrentPageId, setWorkspaceId]
|
||||||
);
|
);
|
||||||
const jumpToPublicWorkspacePage = useCallback(
|
const jumpToPublicWorkspacePage = useCallback(
|
||||||
(
|
(
|
||||||
@@ -29,11 +39,13 @@ export function useNavigateHelper() {
|
|||||||
pageId: string,
|
pageId: string,
|
||||||
logic: RouteLogic = RouteLogic.PUSH
|
logic: RouteLogic = RouteLogic.PUSH
|
||||||
) => {
|
) => {
|
||||||
|
setWorkspaceId(workspaceId);
|
||||||
|
setCurrentPageId(pageId);
|
||||||
return navigate(`/public-workspace/${workspaceId}/${pageId}`, {
|
return navigate(`/public-workspace/${workspaceId}/${pageId}`, {
|
||||||
replace: logic === RouteLogic.REPLACE,
|
replace: logic === RouteLogic.REPLACE,
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
[navigate]
|
[navigate, setCurrentPageId, setWorkspaceId]
|
||||||
);
|
);
|
||||||
const jumpToSubPath = useCallback(
|
const jumpToSubPath = useCallback(
|
||||||
(
|
(
|
||||||
@@ -41,14 +53,18 @@ export function useNavigateHelper() {
|
|||||||
subPath: WorkspaceSubPath,
|
subPath: WorkspaceSubPath,
|
||||||
logic: RouteLogic = RouteLogic.PUSH
|
logic: RouteLogic = RouteLogic.PUSH
|
||||||
) => {
|
) => {
|
||||||
|
setWorkspaceId(workspaceId);
|
||||||
|
setCurrentPageId(null);
|
||||||
return navigate(`/workspace/${workspaceId}/${subPath}`, {
|
return navigate(`/workspace/${workspaceId}/${subPath}`, {
|
||||||
replace: logic === RouteLogic.REPLACE,
|
replace: logic === RouteLogic.REPLACE,
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
[navigate]
|
[navigate, setCurrentPageId, setWorkspaceId]
|
||||||
);
|
);
|
||||||
const openPage = useCallback(
|
const openPage = useCallback(
|
||||||
(workspaceId: string, pageId: string) => {
|
(workspaceId: string, pageId: string) => {
|
||||||
|
setWorkspaceId(workspaceId);
|
||||||
|
setCurrentPageId(pageId);
|
||||||
const isPublicWorkspace =
|
const isPublicWorkspace =
|
||||||
location.pathname.indexOf('/public-workspace') === 0;
|
location.pathname.indexOf('/public-workspace') === 0;
|
||||||
if (isPublicWorkspace) {
|
if (isPublicWorkspace) {
|
||||||
@@ -57,25 +73,35 @@ export function useNavigateHelper() {
|
|||||||
return jumpToPage(workspaceId, pageId);
|
return jumpToPage(workspaceId, pageId);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
[jumpToPage, jumpToPublicWorkspacePage, location.pathname]
|
[
|
||||||
|
jumpToPage,
|
||||||
|
jumpToPublicWorkspacePage,
|
||||||
|
location.pathname,
|
||||||
|
setCurrentPageId,
|
||||||
|
setWorkspaceId,
|
||||||
|
]
|
||||||
);
|
);
|
||||||
|
|
||||||
const jumpToIndex = useCallback(
|
const jumpToIndex = useCallback(
|
||||||
(logic: RouteLogic = RouteLogic.PUSH) => {
|
(logic: RouteLogic = RouteLogic.PUSH) => {
|
||||||
|
setWorkspaceId(null);
|
||||||
|
setCurrentPageId(null);
|
||||||
return navigate('/', {
|
return navigate('/', {
|
||||||
replace: logic === RouteLogic.REPLACE,
|
replace: logic === RouteLogic.REPLACE,
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
[navigate]
|
[navigate, setCurrentPageId, setWorkspaceId]
|
||||||
);
|
);
|
||||||
|
|
||||||
const jumpTo404 = useCallback(
|
const jumpTo404 = useCallback(
|
||||||
(logic: RouteLogic = RouteLogic.PUSH) => {
|
(logic: RouteLogic = RouteLogic.PUSH) => {
|
||||||
|
setWorkspaceId(null);
|
||||||
|
setCurrentPageId(null);
|
||||||
return navigate('/404', {
|
return navigate('/404', {
|
||||||
replace: logic === RouteLogic.REPLACE,
|
replace: logic === RouteLogic.REPLACE,
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
[navigate]
|
[navigate, setCurrentPageId, setWorkspaceId]
|
||||||
);
|
);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|||||||
Reference in New Issue
Block a user