mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-26 10:45:57 +08:00
feat(mobile): create from template on mobile (#9968)
This commit is contained in:
@@ -1,10 +1,13 @@
|
|||||||
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 { DocsService } from '@affine/core/modules/doc';
|
||||||
|
import { FeatureFlagService } from '@affine/core/modules/feature-flag';
|
||||||
|
import { TemplateDocService } from '@affine/core/modules/template-doc';
|
||||||
import { WorkbenchService } from '@affine/core/modules/workbench';
|
import { WorkbenchService } from '@affine/core/modules/workbench';
|
||||||
import { WorkspaceService } from '@affine/core/modules/workspace';
|
import { WorkspaceService } from '@affine/core/modules/workspace';
|
||||||
import track from '@affine/track';
|
import track from '@affine/track';
|
||||||
import { EditIcon } from '@blocksuite/icons/rc';
|
import { EditIcon } from '@blocksuite/icons/rc';
|
||||||
import { useService } from '@toeverything/infra';
|
import { useLiveData, useService } from '@toeverything/infra';
|
||||||
import { useCallback } from 'react';
|
|
||||||
|
|
||||||
import type { AppTabCustomFCProps } from './data';
|
import type { AppTabCustomFCProps } from './data';
|
||||||
import { TabItem } from './tab-item';
|
import { TabItem } from './tab-item';
|
||||||
@@ -12,17 +15,43 @@ import { TabItem } from './tab-item';
|
|||||||
export const AppTabCreate = ({ tab }: AppTabCustomFCProps) => {
|
export const AppTabCreate = ({ tab }: AppTabCustomFCProps) => {
|
||||||
const workbench = useService(WorkbenchService).workbench;
|
const workbench = useService(WorkbenchService).workbench;
|
||||||
const workspaceService = useService(WorkspaceService);
|
const workspaceService = useService(WorkspaceService);
|
||||||
|
const featureFlagService = useService(FeatureFlagService);
|
||||||
|
const templateDocService = useService(TemplateDocService);
|
||||||
|
const docsService = useService(DocsService);
|
||||||
|
|
||||||
const currentWorkspace = workspaceService.workspace;
|
const currentWorkspace = workspaceService.workspace;
|
||||||
const pageHelper = usePageHelper(currentWorkspace.docCollection);
|
const pageHelper = usePageHelper(currentWorkspace.docCollection);
|
||||||
|
const enableTemplateDoc = useLiveData(
|
||||||
|
featureFlagService.flags.enable_template_doc.$
|
||||||
|
);
|
||||||
|
const enablePageTemplate = useLiveData(
|
||||||
|
templateDocService.setting.enablePageTemplate$
|
||||||
|
);
|
||||||
|
const pageTemplateDocId = useLiveData(
|
||||||
|
templateDocService.setting.pageTemplateDocId$
|
||||||
|
);
|
||||||
|
|
||||||
const createPage = useCallback(
|
const createPage = useAsyncCallback(
|
||||||
(isActive: boolean) => {
|
async (isActive: boolean) => {
|
||||||
if (isActive) return;
|
if (isActive) return;
|
||||||
const doc = pageHelper.createPage(undefined, { show: false });
|
if (enableTemplateDoc && enablePageTemplate && pageTemplateDocId) {
|
||||||
workbench.openDoc({ docId: doc.id, fromTab: 'true' });
|
const docId =
|
||||||
|
await docsService.duplicateFromTemplate(pageTemplateDocId);
|
||||||
|
workbench.openDoc({ docId, fromTab: 'true' });
|
||||||
|
} else {
|
||||||
|
const doc = pageHelper.createPage(undefined, { show: false });
|
||||||
|
workbench.openDoc({ docId: doc.id, fromTab: 'true' });
|
||||||
|
}
|
||||||
track.$.navigationPanel.$.createDoc();
|
track.$.navigationPanel.$.createDoc();
|
||||||
},
|
},
|
||||||
[pageHelper, workbench]
|
[
|
||||||
|
docsService,
|
||||||
|
enablePageTemplate,
|
||||||
|
enableTemplateDoc,
|
||||||
|
pageHelper,
|
||||||
|
pageTemplateDocId,
|
||||||
|
workbench,
|
||||||
|
]
|
||||||
);
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -236,7 +236,7 @@ export const AFFINE_FLAGS = {
|
|||||||
displayName: 'Enable template doc',
|
displayName: 'Enable template doc',
|
||||||
description:
|
description:
|
||||||
'Allow users to mark a doc as a template, and create new docs from it',
|
'Allow users to mark a doc as a template, and create new docs from it',
|
||||||
configurable: !isMobile,
|
configurable: true,
|
||||||
defaultState: isCanaryBuild,
|
defaultState: isCanaryBuild,
|
||||||
},
|
},
|
||||||
// TODO(@L-Sun): remove this flag when ready
|
// TODO(@L-Sun): remove this flag when ready
|
||||||
|
|||||||
Reference in New Issue
Block a user