refactor(web): move current atoms into plugin infra (#3220)

This commit is contained in:
Alex Yang
2023-07-13 20:14:30 +08:00
committed by GitHub
parent 0230cea16e
commit 64cf297399
13 changed files with 91 additions and 98 deletions

View File

@@ -4,7 +4,6 @@ import { createEmptyBlockSuiteWorkspace } from '@affine/workspace/utils';
import type { BlockHub } from '@blocksuite/blocks';
import { assertExists } from '@blocksuite/global/utils';
import { atom } from 'jotai';
import Router from 'next/router';
import { z } from 'zod';
const rootWorkspaceMetadataV1Schema = z.object({
@@ -232,52 +231,6 @@ export const rootWorkspacesMetadataAtom = atom<
}
);
// two more atoms to store the current workspace and page
export const rootCurrentWorkspaceIdAtom = atom<string | null>(null);
rootCurrentWorkspaceIdAtom.onMount = set => {
if (environment.isBrowser) {
const callback = (url: string) => {
const value = url.split('/')[2];
if (value === 'all' || value === 'trash' || value === 'shared') {
set(null);
} else if (value) {
set(value);
localStorage.setItem('last_workspace_id', value);
} else {
set(null);
}
};
callback(window.location.pathname);
Router.events.on('routeChangeStart', callback);
return () => {
Router.events.off('routeChangeStart', callback);
};
}
return;
};
export const rootCurrentPageIdAtom = atom<string | null>(null);
rootCurrentPageIdAtom.onMount = set => {
if (environment.isBrowser) {
const callback = (url: string) => {
const value = url.split('/')[3];
if (value) {
set(value);
} else {
set(null);
}
};
callback(window.location.pathname);
Router.events.on('routeChangeStart', callback);
return () => {
Router.events.off('routeChangeStart', callback);
};
}
return;
};
// blocksuite atoms,
// each app should have only one block-hub in the same time
export const rootBlockHubAtom = atom<Readonly<BlockHub> | null>(null);