mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-09-07 01:09:54 +08:00
feat(core): update import entry in all page and page list (#8814)
This commit is contained in:
@@ -6,11 +6,11 @@ import {
|
|||||||
Scrollable,
|
Scrollable,
|
||||||
useConfirmModal,
|
useConfirmModal,
|
||||||
} from '@affine/component';
|
} from '@affine/component';
|
||||||
import { useAsyncCallback } from '@affine/core/components/hooks/affine-async-hooks';
|
|
||||||
import { useNavigateHelper } from '@affine/core/components/hooks/use-navigate-helper';
|
import { useNavigateHelper } from '@affine/core/components/hooks/use-navigate-helper';
|
||||||
import { WorkspaceDialogService } from '@affine/core/modules/dialogs';
|
import { WorkspaceDialogService } from '@affine/core/modules/dialogs';
|
||||||
import type { Tag } from '@affine/core/modules/tag';
|
import type { Tag } from '@affine/core/modules/tag';
|
||||||
import { TagService } from '@affine/core/modules/tag';
|
import { TagService } from '@affine/core/modules/tag';
|
||||||
|
import { WorkbenchService } from '@affine/core/modules/workbench';
|
||||||
import { isNewTabTrigger } from '@affine/core/utils';
|
import { isNewTabTrigger } from '@affine/core/utils';
|
||||||
import type { Collection } from '@affine/env/filter';
|
import type { Collection } from '@affine/env/filter';
|
||||||
import { useI18n } from '@affine/i18n';
|
import { useI18n } from '@affine/i18n';
|
||||||
@@ -41,31 +41,54 @@ import { PageListNewPageButton } from './page-list-new-page-button';
|
|||||||
|
|
||||||
export const PageListHeader = () => {
|
export const PageListHeader = () => {
|
||||||
const t = useI18n();
|
const t = useI18n();
|
||||||
const { workspaceService } = useServices({
|
const { workspaceService, workspaceDialogService, workbenchService } =
|
||||||
WorkspaceService,
|
useServices({
|
||||||
});
|
WorkspaceService,
|
||||||
|
WorkspaceDialogService,
|
||||||
|
WorkbenchService,
|
||||||
|
});
|
||||||
|
|
||||||
|
const workbench = workbenchService.workbench;
|
||||||
const workspace = workspaceService.workspace;
|
const workspace = workspaceService.workspace;
|
||||||
const { importFile, createEdgeless, createPage } = usePageHelper(
|
const { createEdgeless, createPage } = usePageHelper(workspace.docCollection);
|
||||||
workspace.docCollection
|
|
||||||
);
|
|
||||||
|
|
||||||
const title = useMemo(() => {
|
const title = useMemo(() => {
|
||||||
return t['com.affine.all-pages.header']();
|
return t['com.affine.all-pages.header']();
|
||||||
}, [t]);
|
}, [t]);
|
||||||
|
|
||||||
const onImportFile = useAsyncCallback(async () => {
|
const handleOpenDocs = useCallback(
|
||||||
const options = await importFile();
|
(result: {
|
||||||
if (options.isWorkspaceFile) {
|
docIds: string[];
|
||||||
track.allDocs.header.actions.createWorkspace({
|
entryId?: string;
|
||||||
control: 'import',
|
isWorkspaceFile?: boolean;
|
||||||
});
|
}) => {
|
||||||
} else {
|
const { docIds, entryId, isWorkspaceFile } = result;
|
||||||
track.allDocs.header.actions.createDoc({
|
// If the imported file is a workspace file, open the entry page.
|
||||||
control: 'import',
|
if (isWorkspaceFile && entryId) {
|
||||||
});
|
workbench.openDoc(entryId);
|
||||||
}
|
} else if (!docIds.length) {
|
||||||
}, [importFile]);
|
return;
|
||||||
|
}
|
||||||
|
// Open all the docs when there are multiple docs imported.
|
||||||
|
if (docIds.length > 1) {
|
||||||
|
workbench.openAll();
|
||||||
|
} else {
|
||||||
|
// Otherwise, open the only doc.
|
||||||
|
workbench.openDoc(docIds[0]);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
[workbench]
|
||||||
|
);
|
||||||
|
|
||||||
|
const onImportFile = useCallback(() => {
|
||||||
|
track.$.header.importModal.open();
|
||||||
|
workspaceDialogService.open('import', undefined, payload => {
|
||||||
|
if (!payload) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
handleOpenDocs(payload);
|
||||||
|
});
|
||||||
|
}, [workspaceDialogService, handleOpenDocs]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={styles.docListHeader}>
|
<div className={styles.docListHeader}>
|
||||||
|
|||||||
@@ -1,30 +0,0 @@
|
|||||||
import { useAsyncCallback } from '@affine/core/components/hooks/affine-async-hooks';
|
|
||||||
import { MenuItem } from '@affine/core/modules/app-sidebar/views';
|
|
||||||
import { useI18n } from '@affine/i18n';
|
|
||||||
import { track } from '@affine/track';
|
|
||||||
import type { DocCollection } from '@blocksuite/affine/store';
|
|
||||||
import { ImportIcon } from '@blocksuite/icons/rc';
|
|
||||||
|
|
||||||
import { usePageHelper } from '../blocksuite/block-suite-page-list/utils';
|
|
||||||
|
|
||||||
const ImportPage = ({ docCollection }: { docCollection: DocCollection }) => {
|
|
||||||
const t = useI18n();
|
|
||||||
const { importFile } = usePageHelper(docCollection);
|
|
||||||
|
|
||||||
const onImportFile = useAsyncCallback(async () => {
|
|
||||||
const options = await importFile();
|
|
||||||
track.$.navigationPanel.workspaceList[
|
|
||||||
options.isWorkspaceFile ? 'createWorkspace' : 'createDoc'
|
|
||||||
]({
|
|
||||||
control: 'import',
|
|
||||||
});
|
|
||||||
}, [importFile]);
|
|
||||||
|
|
||||||
return (
|
|
||||||
<MenuItem icon={<ImportIcon />} onClick={onImportFile}>
|
|
||||||
{t['Import']()}
|
|
||||||
</MenuItem>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export default ImportPage;
|
|
||||||
@@ -1,5 +1,4 @@
|
|||||||
import { usePageHelper } from '@affine/core/components/blocksuite/block-suite-page-list/utils';
|
import { usePageHelper } from '@affine/core/components/blocksuite/block-suite-page-list/utils';
|
||||||
import { useAsyncCallback } from '@affine/core/components/hooks/affine-async-hooks';
|
|
||||||
import {
|
import {
|
||||||
AllPageListOperationsMenu,
|
AllPageListOperationsMenu,
|
||||||
PageDisplayMenu,
|
PageDisplayMenu,
|
||||||
@@ -7,12 +6,15 @@ import {
|
|||||||
} from '@affine/core/components/page-list';
|
} from '@affine/core/components/page-list';
|
||||||
import { Header } from '@affine/core/components/pure/header';
|
import { Header } from '@affine/core/components/pure/header';
|
||||||
import { WorkspaceModeFilterTab } from '@affine/core/components/pure/workspace-mode-filter-tab';
|
import { WorkspaceModeFilterTab } from '@affine/core/components/pure/workspace-mode-filter-tab';
|
||||||
|
import { WorkspaceDialogService } from '@affine/core/modules/dialogs';
|
||||||
|
import { WorkbenchService } from '@affine/core/modules/workbench';
|
||||||
import { isNewTabTrigger } from '@affine/core/utils';
|
import { isNewTabTrigger } from '@affine/core/utils';
|
||||||
import type { Filter } from '@affine/env/filter';
|
import type { Filter } from '@affine/env/filter';
|
||||||
import { track } from '@affine/track';
|
import { track } from '@affine/track';
|
||||||
import { PlusIcon } from '@blocksuite/icons/rc';
|
import { PlusIcon } from '@blocksuite/icons/rc';
|
||||||
import { useServices, WorkspaceService } from '@toeverything/infra';
|
import { useServices, WorkspaceService } from '@toeverything/infra';
|
||||||
import clsx from 'clsx';
|
import clsx from 'clsx';
|
||||||
|
import { useCallback } from 'react';
|
||||||
|
|
||||||
import * as styles from './all-page.css';
|
import * as styles from './all-page.css';
|
||||||
|
|
||||||
@@ -25,26 +27,49 @@ export const AllPageHeader = ({
|
|||||||
filters: Filter[];
|
filters: Filter[];
|
||||||
onChangeFilters: (filters: Filter[]) => void;
|
onChangeFilters: (filters: Filter[]) => void;
|
||||||
}) => {
|
}) => {
|
||||||
const { workspaceService } = useServices({
|
const { workspaceService, workspaceDialogService, workbenchService } =
|
||||||
WorkspaceService,
|
useServices({
|
||||||
});
|
WorkspaceService,
|
||||||
|
WorkspaceDialogService,
|
||||||
|
WorkbenchService,
|
||||||
|
});
|
||||||
|
const workbench = workbenchService.workbench;
|
||||||
const workspace = workspaceService.workspace;
|
const workspace = workspaceService.workspace;
|
||||||
const { importFile, createEdgeless, createPage } = usePageHelper(
|
const { createEdgeless, createPage } = usePageHelper(workspace.docCollection);
|
||||||
workspace.docCollection
|
|
||||||
|
const handleOpenDocs = useCallback(
|
||||||
|
(result: {
|
||||||
|
docIds: string[];
|
||||||
|
entryId?: string;
|
||||||
|
isWorkspaceFile?: boolean;
|
||||||
|
}) => {
|
||||||
|
const { docIds, entryId, isWorkspaceFile } = result;
|
||||||
|
// If the imported file is a workspace file, open the entry page.
|
||||||
|
if (isWorkspaceFile && entryId) {
|
||||||
|
workbench.openDoc(entryId);
|
||||||
|
} else if (!docIds.length) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// Open all the docs when there are multiple docs imported.
|
||||||
|
if (docIds.length > 1) {
|
||||||
|
workbench.openAll();
|
||||||
|
} else {
|
||||||
|
// Otherwise, open the only doc.
|
||||||
|
workbench.openDoc(docIds[0]);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
[workbench]
|
||||||
);
|
);
|
||||||
|
|
||||||
const onImportFile = useAsyncCallback(async () => {
|
const onImportFile = useCallback(() => {
|
||||||
const options = await importFile();
|
track.$.header.importModal.open();
|
||||||
if (options.isWorkspaceFile) {
|
workspaceDialogService.open('import', undefined, payload => {
|
||||||
track.allDocs.header.actions.createWorkspace({
|
if (!payload) {
|
||||||
control: 'import',
|
return;
|
||||||
});
|
}
|
||||||
} else {
|
handleOpenDocs(payload);
|
||||||
track.allDocs.header.actions.createDoc({
|
});
|
||||||
control: 'import',
|
}, [workspaceDialogService, handleOpenDocs]);
|
||||||
});
|
|
||||||
}
|
|
||||||
}, [importFile]);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Header
|
<Header
|
||||||
|
|||||||
@@ -1,22 +1,22 @@
|
|||||||
{
|
{
|
||||||
"ar": 79,
|
"ar": 76,
|
||||||
"ca": 6,
|
"ca": 5,
|
||||||
"da": 6,
|
"da": 6,
|
||||||
"de": 29,
|
"de": 28,
|
||||||
"en": 100,
|
"en": 100,
|
||||||
"es-AR": 14,
|
"es-AR": 14,
|
||||||
"es-CL": 16,
|
"es-CL": 16,
|
||||||
"es": 14,
|
"es": 14,
|
||||||
"fr": 70,
|
"fr": 67,
|
||||||
"hi": 2,
|
"hi": 2,
|
||||||
"it": 1,
|
"it": 1,
|
||||||
"ja": 93,
|
"ja": 90,
|
||||||
"ko": 83,
|
"ko": 80,
|
||||||
"pl": 0,
|
"pl": 0,
|
||||||
"pt-BR": 90,
|
"pt-BR": 87,
|
||||||
"ru": 77,
|
"ru": 74,
|
||||||
"sv-SE": 5,
|
"sv-SE": 4,
|
||||||
"ur": 3,
|
"ur": 3,
|
||||||
"zh-Hans": 95,
|
"zh-Hans": 91,
|
||||||
"zh-Hant": 92
|
"zh-Hant": 88
|
||||||
}
|
}
|
||||||
@@ -1312,7 +1312,7 @@
|
|||||||
"com.affine.sidebarSwitch.collapse": "Collapse sidebar",
|
"com.affine.sidebarSwitch.collapse": "Collapse sidebar",
|
||||||
"com.affine.sidebarSwitch.expand": "Expand sidebar",
|
"com.affine.sidebarSwitch.expand": "Expand sidebar",
|
||||||
"com.affine.snapshot.import-export.enable": "Snapshot Imp. & Exp.",
|
"com.affine.snapshot.import-export.enable": "Snapshot Imp. & Exp.",
|
||||||
"com.affine.snapshot.import-export.enable.desc": "Snapshot import and export support. When your document has a data error, turn this on and ask the AFFiNE team for help. Once enabled you can find the Snapshot Export Import option in the document's More menu.",
|
"com.affine.snapshot.import-export.enable.desc": "Once enabled you can find the Snapshot Export Import option in the document's More menu.",
|
||||||
"com.affine.star-affine.cancel": "Maybe later",
|
"com.affine.star-affine.cancel": "Maybe later",
|
||||||
"com.affine.star-affine.confirm": "Star on GitHub",
|
"com.affine.star-affine.confirm": "Star on GitHub",
|
||||||
"com.affine.star-affine.description": "Are you finding our app useful and enjoyable? We'd love your support to keep improving! A great way to help us out is by giving us a star on GitHub. This simple action can make a big difference and helps us continue to deliver the best experience for you.",
|
"com.affine.star-affine.description": "Are you finding our app useful and enjoyable? We'd love your support to keep improving! A great way to help us out is by giving us a star on GitHub. This simple action can make a big difference and helps us continue to deliver the best experience for you.",
|
||||||
|
|||||||
@@ -1312,7 +1312,7 @@
|
|||||||
"com.affine.sidebarSwitch.collapse": "折叠侧边栏",
|
"com.affine.sidebarSwitch.collapse": "折叠侧边栏",
|
||||||
"com.affine.sidebarSwitch.expand": "展开侧边栏",
|
"com.affine.sidebarSwitch.expand": "展开侧边栏",
|
||||||
"com.affine.snapshot.import-export.enable": "启用快照导入导出",
|
"com.affine.snapshot.import-export.enable": "启用快照导入导出",
|
||||||
"com.affine.snapshot.import-export.enable.desc": "支持快照导入和导出。当您的文档出现数据错误时,请启用此功能并寻求 AFFiNE 团队的帮助。启用后,您可以在文档的更多菜单中找到快照导出导入选项。",
|
"com.affine.snapshot.import-export.enable.desc": "启用后,您可以在文档的更多菜单中找到快照导出导入选项。",
|
||||||
"com.affine.star-affine.cancel": "稍后",
|
"com.affine.star-affine.cancel": "稍后",
|
||||||
"com.affine.star-affine.confirm": "在 GitHub 点亮星标",
|
"com.affine.star-affine.confirm": "在 GitHub 点亮星标",
|
||||||
"com.affine.star-affine.description": "您觉得我们的应用程序有用且有趣吗? 我们希望得到您的支持,以不断进步! 帮助我们的一个好方法是在 GitHub 给我们一颗星。 这个简单的行动可以给我们很大的激励,并帮助我们继续为您提供最佳体验。",
|
"com.affine.star-affine.description": "您觉得我们的应用程序有用且有趣吗? 我们希望得到您的支持,以不断进步! 帮助我们的一个好方法是在 GitHub 给我们一颗星。 这个简单的行动可以给我们很大的激励,并帮助我们继续为您提供最佳体验。",
|
||||||
|
|||||||
@@ -1312,7 +1312,7 @@
|
|||||||
"com.affine.sidebarSwitch.collapse": "收起側欄",
|
"com.affine.sidebarSwitch.collapse": "收起側欄",
|
||||||
"com.affine.sidebarSwitch.expand": "展開側欄",
|
"com.affine.sidebarSwitch.expand": "展開側欄",
|
||||||
"com.affine.snapshot.import-export.enable": "啟用快照匯入匯出",
|
"com.affine.snapshot.import-export.enable": "啟用快照匯入匯出",
|
||||||
"com.affine.snapshot.import-export.enable.desc": "支援快照匯入和匯出。當您的文件出現資料錯誤時,請啟用此功能並尋求 AFFiNE 團隊的協助。啟用後,您可以在文件的更多選單中找到快照匯出匯入選項。",
|
"com.affine.snapshot.import-export.enable.desc": "啟用後,您可以在文件的更多選單中找到快照匯出匯入選項。",
|
||||||
"com.affine.star-affine.cancel": "稍後",
|
"com.affine.star-affine.cancel": "稍後",
|
||||||
"com.affine.star-affine.confirm": "在 GitHub 點亮星標",
|
"com.affine.star-affine.confirm": "在 GitHub 點亮星標",
|
||||||
"com.affine.star-affine.description": "您覺得我們的應用程序有用且有趣嗎?我們希望得到您的支持,以不斷進步!幫助我們的一個好方法是在 GitHub 給我們一顆星。這個簡單的行動可以給我們很大的激勵,並幫助我們繼續為您提供最佳體驗。",
|
"com.affine.star-affine.description": "您覺得我們的應用程序有用且有趣嗎?我們希望得到您的支持,以不斷進步!幫助我們的一個好方法是在 GitHub 給我們一顆星。這個簡單的行動可以給我們很大的激勵,並幫助我們繼續為您提供最佳體驗。",
|
||||||
|
|||||||
Reference in New Issue
Block a user