fix: jump to the correct url after importing notion (#3844)

This commit is contained in:
xiaodong zuo 2023-08-21 06:13:01 +08:00 committed by GitHub
parent a348df4c47
commit cae6133f7e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,4 +1,6 @@
import { toast } from '@affine/component';
import { initEmptyPage } from '@affine/env/blocksuite';
import { WorkspaceSubPath } from '@affine/env/workspace';
import { useBlockSuiteWorkspaceHelper } from '@toeverything/hooks/use-block-suite-workspace-helper';
import { useAtomValue, useSetAtom } from 'jotai';
import { useCallback } from 'react';
@ -8,7 +10,7 @@ import { useNavigateHelper } from '../../../hooks/use-navigate-helper';
import type { BlockSuiteWorkspace } from '../../../shared';
export const usePageHelper = (blockSuiteWorkspace: BlockSuiteWorkspace) => {
const { openPage } = useNavigateHelper();
const { openPage, jumpToSubPath } = useNavigateHelper();
const { createPage } = useBlockSuiteWorkspaceHelper(blockSuiteWorkspace);
const pageSettings = useAtomValue(pageSettingsAtom);
const isPreferredEdgeless = useCallback(
@ -35,8 +37,25 @@ export const usePageHelper = (blockSuiteWorkspace: BlockSuiteWorkspace) => {
);
const importFileAndOpen = useCallback(async () => {
const { showImportModal } = await import('@blocksuite/blocks');
showImportModal({ workspace: blockSuiteWorkspace });
}, [blockSuiteWorkspace]);
const onSuccess = (pageIds: string[], isWorkspaceFile: boolean) => {
toast(
`Successfully imported ${pageIds.length} Page${
pageIds.length > 1 ? 's' : ''
}.`
);
if (isWorkspaceFile) {
jumpToSubPath(blockSuiteWorkspace.id, WorkspaceSubPath.ALL);
return;
}
if (pageIds.length === 0) {
return;
}
const pageId = pageIds[0];
openPage(blockSuiteWorkspace.id, pageId);
};
showImportModal({ workspace: blockSuiteWorkspace, onSuccess });
}, [blockSuiteWorkspace, openPage, jumpToSubPath]);
return {
createPage: createPageAndOpen,
createEdgeless: createEdgelessAndOpen,