mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-19 11:06:25 +08:00
fix(core): importing template with default mode (#8250)
This commit is contained in:
@@ -1,8 +1,10 @@
|
||||
import type { DocMode } from '@blocksuite/blocks';
|
||||
import { Entity, LiveData } from '@toeverything/infra';
|
||||
|
||||
interface TemplateOptions {
|
||||
templateName: string;
|
||||
snapshotUrl: string;
|
||||
templateMode: DocMode;
|
||||
}
|
||||
|
||||
export class ImportTemplateDialog extends Entity {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import type { WorkspaceFlavour } from '@affine/env/workspace';
|
||||
import { ZipTransformer } from '@blocksuite/blocks';
|
||||
import { type DocMode, ZipTransformer } from '@blocksuite/blocks';
|
||||
import type { WorkspaceMetadata, WorkspacesService } from '@toeverything/infra';
|
||||
import { DocsService, Service } from '@toeverything/infra';
|
||||
|
||||
@@ -10,7 +10,8 @@ export class ImportTemplateService extends Service {
|
||||
|
||||
async importToWorkspace(
|
||||
workspaceMetadata: WorkspaceMetadata,
|
||||
docBinary: Uint8Array
|
||||
docBinary: Uint8Array,
|
||||
mode: DocMode
|
||||
) {
|
||||
const { workspace, dispose: disposeWorkspace } =
|
||||
this.workspacesService.open({
|
||||
@@ -26,7 +27,7 @@ export class ImportTemplateService extends Service {
|
||||
const docsService = workspace.scope.get(DocsService);
|
||||
if (importedDoc) {
|
||||
// only support page mode for now
|
||||
docsService.list.setPrimaryMode(importedDoc.id, 'page');
|
||||
docsService.list.setPrimaryMode(importedDoc.id, mode);
|
||||
disposeWorkspace();
|
||||
return importedDoc.id;
|
||||
} else {
|
||||
@@ -38,6 +39,7 @@ export class ImportTemplateService extends Service {
|
||||
flavour: WorkspaceFlavour,
|
||||
workspaceName: string,
|
||||
docBinary: Uint8Array
|
||||
// todo: support doc mode on init
|
||||
) {
|
||||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
||||
let docId: string = null!;
|
||||
|
||||
@@ -5,6 +5,7 @@ import { useWorkspaceName } from '@affine/core/components/hooks/use-workspace-in
|
||||
import { WorkspaceSelector } from '@affine/core/components/workspace-selector';
|
||||
import { WorkspaceFlavour } from '@affine/env/workspace';
|
||||
import { useI18n } from '@affine/i18n';
|
||||
import type { DocMode } from '@blocksuite/blocks';
|
||||
import { AllDocsIcon } from '@blocksuite/icons/rc';
|
||||
import {
|
||||
useLiveData,
|
||||
@@ -24,10 +25,12 @@ import * as styles from './dialog.css';
|
||||
|
||||
const Dialog = ({
|
||||
templateName,
|
||||
templateMode,
|
||||
snapshotUrl,
|
||||
onClose,
|
||||
}: {
|
||||
templateName: string;
|
||||
templateMode: DocMode;
|
||||
snapshotUrl: string;
|
||||
onClose?: () => void;
|
||||
}) => {
|
||||
@@ -70,6 +73,8 @@ const Dialog = ({
|
||||
'/template/import?' +
|
||||
'&name=' +
|
||||
templateName +
|
||||
'&mode=' +
|
||||
templateMode +
|
||||
'&snapshotUrl=' +
|
||||
snapshotUrl
|
||||
);
|
||||
@@ -82,6 +87,7 @@ const Dialog = ({
|
||||
onClose,
|
||||
snapshotUrl,
|
||||
templateName,
|
||||
templateMode,
|
||||
]);
|
||||
|
||||
useEffect(() => {
|
||||
@@ -108,7 +114,8 @@ const Dialog = ({
|
||||
try {
|
||||
const docId = await importTemplateService.importToWorkspace(
|
||||
selectedWorkspace,
|
||||
templateDownloader.data$.value
|
||||
templateDownloader.data$.value,
|
||||
templateMode
|
||||
);
|
||||
openPage(selectedWorkspace.id, docId);
|
||||
onClose?.();
|
||||
@@ -124,6 +131,7 @@ const Dialog = ({
|
||||
openPage,
|
||||
selectedWorkspace,
|
||||
templateDownloader.data$.value,
|
||||
templateMode,
|
||||
]);
|
||||
|
||||
const handleImportToNewWorkspace = useAsyncCallback(async () => {
|
||||
@@ -235,6 +243,7 @@ export const ImportTemplateDialogProvider = () => {
|
||||
{template && (
|
||||
<Dialog
|
||||
templateName={template.templateName}
|
||||
templateMode={template.templateMode}
|
||||
snapshotUrl={template.snapshotUrl}
|
||||
onClose={() => importTemplateDialogService.dialog.close()}
|
||||
/>
|
||||
|
||||
Reference in New Issue
Block a user