mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-13 21:05:19 +00:00
refactor(core): remove jump once (#6733)
Previously, we marked `jumpOnce: true` on `doc.meta` to open a specific doc after creating a new workspace. This pr removes `jumpOnce` and directly jumps to the specific doc URL. This PR also fixes an error when opening the all-page page, because the all-page page scans the jumpOnce attribute of all docs, and the code in it will fail on damaged data.
This commit is contained in:
@@ -24,31 +24,18 @@ export async function buildShowcaseWorkspace(
|
||||
|
||||
const docsService = workspace.scope.get(DocsService);
|
||||
|
||||
// todo: find better way to do the following
|
||||
// perhaps put them into middleware?
|
||||
{
|
||||
// the "Write, Draw, Plan all at Once." page should be set to edgeless mode
|
||||
const edgelessPage1 = docsService.list.docs$.value.find(
|
||||
p => p.title$.value === 'Write, Draw, Plan all at Once.'
|
||||
);
|
||||
// should jump to "Write, Draw, Plan all at Once." in edgeless by default
|
||||
const defaultDoc = docsService.list.docs$.value.find(p =>
|
||||
p.title$.value.startsWith('Write, Draw, Plan all at Once.')
|
||||
);
|
||||
|
||||
if (edgelessPage1) {
|
||||
edgelessPage1.setMode('edgeless');
|
||||
}
|
||||
|
||||
// should jump to "Write, Draw, Plan all at Once." by default
|
||||
const defaultPage = docsService.list.docs$.value.find(p =>
|
||||
p.title$.value.startsWith('Write, Draw, Plan all at Once.')
|
||||
);
|
||||
|
||||
if (defaultPage) {
|
||||
defaultPage.setMeta({
|
||||
jumpOnce: true,
|
||||
});
|
||||
}
|
||||
if (defaultDoc) {
|
||||
defaultDoc.setMode('edgeless');
|
||||
}
|
||||
|
||||
dispose();
|
||||
return meta;
|
||||
|
||||
return { meta, defaultDocId: defaultDoc?.id };
|
||||
}
|
||||
|
||||
const logger = new DebugLogger('createFirstAppData');
|
||||
@@ -59,26 +46,25 @@ export async function createFirstAppData(workspacesService: WorkspacesService) {
|
||||
}
|
||||
localStorage.setItem('is-first-open', 'false');
|
||||
if (runtimeConfig.enablePreloading) {
|
||||
const workspaceMetadata = await buildShowcaseWorkspace(
|
||||
const { meta, defaultDocId } = await buildShowcaseWorkspace(
|
||||
workspacesService,
|
||||
WorkspaceFlavour.LOCAL,
|
||||
DEFAULT_WORKSPACE_NAME
|
||||
);
|
||||
logger.info('create first workspace', workspaceMetadata);
|
||||
return workspaceMetadata;
|
||||
logger.info('create first workspace', defaultDocId);
|
||||
return { meta, defaultPageId: defaultDocId };
|
||||
} else {
|
||||
let defaultPageId: string | undefined = undefined;
|
||||
const workspaceMetadata = await workspacesService.create(
|
||||
WorkspaceFlavour.LOCAL,
|
||||
async workspace => {
|
||||
workspace.meta.setName(DEFAULT_WORKSPACE_NAME);
|
||||
const page = workspace.createDoc();
|
||||
workspace.setDocMeta(page.id, {
|
||||
jumpOnce: true,
|
||||
});
|
||||
defaultPageId = page.id;
|
||||
initEmptyPage(page);
|
||||
}
|
||||
);
|
||||
logger.info('create first workspace', workspaceMetadata);
|
||||
return workspaceMetadata;
|
||||
return { meta: workspaceMetadata, defaultPageId };
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user