mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-20 11:36:25 +08:00
feat!: unified migration logic in server electron, and browser (#4079)
Co-authored-by: Mirone <Saul-Mirone@outlook.com>
This commit is contained in:
@@ -17,6 +17,8 @@ const logger = new DebugLogger('index-page');
|
||||
|
||||
export const loader: LoaderFunction = async () => {
|
||||
const rootStore = getCurrentStore();
|
||||
const { createFirstAppData } = await import('../bootstrap/setup');
|
||||
createFirstAppData(rootStore);
|
||||
const meta = await rootStore.get(rootWorkspacesMetadataAtom);
|
||||
const lastId = localStorage.getItem('last_workspace_id');
|
||||
const lastPageId = localStorage.getItem('last_page_id');
|
||||
@@ -52,9 +54,5 @@ export const loader: LoaderFunction = async () => {
|
||||
};
|
||||
|
||||
export const Component = () => {
|
||||
return (
|
||||
<>
|
||||
<AllWorkspaceModals />
|
||||
</>
|
||||
);
|
||||
return <AllWorkspaceModals />;
|
||||
};
|
||||
|
||||
@@ -1,18 +1,27 @@
|
||||
import { WorkspaceFlavour } from '@affine/env/workspace';
|
||||
import { rootWorkspacesMetadataAtom } from '@affine/workspace/atom';
|
||||
import { assertExists } from '@blocksuite/global/utils';
|
||||
import { getActiveBlockSuiteWorkspaceAtom } from '@toeverything/infra/__internal__/workspace';
|
||||
import {
|
||||
currentPageIdAtom,
|
||||
currentWorkspaceIdAtom,
|
||||
getCurrentStore,
|
||||
} from '@toeverything/infra/atom';
|
||||
import type { ReactElement } from 'react';
|
||||
import { type LoaderFunction, Outlet, redirect } from 'react-router-dom';
|
||||
import {
|
||||
type LoaderFunction,
|
||||
Outlet,
|
||||
redirect,
|
||||
useLoaderData,
|
||||
} from 'react-router-dom';
|
||||
|
||||
import { WorkspaceLayout } from '../../layouts/workspace-layout';
|
||||
|
||||
export const loader: LoaderFunction = async args => {
|
||||
const rootStore = getCurrentStore();
|
||||
const meta = await rootStore.get(rootWorkspacesMetadataAtom);
|
||||
if (!meta.some(({ id }) => id === args.params.workspaceId)) {
|
||||
const currentMetadata = meta.find(({ id }) => id === args.params.workspaceId);
|
||||
if (!currentMetadata) {
|
||||
return redirect('/404');
|
||||
}
|
||||
if (args.params.workspaceId) {
|
||||
@@ -22,12 +31,27 @@ export const loader: LoaderFunction = async args => {
|
||||
if (!args.params.pageId) {
|
||||
rootStore.set(currentPageIdAtom, null);
|
||||
}
|
||||
if (currentMetadata.flavour === WorkspaceFlavour.AFFINE_CLOUD) {
|
||||
const workspaceAtom = getActiveBlockSuiteWorkspaceAtom(currentMetadata.id);
|
||||
const workspace = await rootStore.get(workspaceAtom);
|
||||
return (() => {
|
||||
const blockVersions = workspace.meta.blockVersions;
|
||||
assertExists(blockVersions, 'blockVersions should not be null');
|
||||
for (const [flavour, schema] of workspace.schema.flavourSchemaMap) {
|
||||
if (blockVersions[flavour] !== schema.version) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
})();
|
||||
}
|
||||
return null;
|
||||
};
|
||||
|
||||
export const Component = (): ReactElement => {
|
||||
const incompatible = useLoaderData();
|
||||
return (
|
||||
<WorkspaceLayout>
|
||||
<WorkspaceLayout incompatible={!!incompatible}>
|
||||
<Outlet />
|
||||
</WorkspaceLayout>
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user