mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-15 00:56:26 +08:00
refactor(web): move current atoms into plugin infra (#3220)
This commit is contained in:
@@ -13,7 +13,12 @@ import {
|
||||
} from '@affine/workspace/migration';
|
||||
import { createIndexedDBDownloadProvider } from '@affine/workspace/providers';
|
||||
import { assertExists } from '@blocksuite/global/utils';
|
||||
import { rootStore } from '@toeverything/plugin-infra/manager';
|
||||
import {
|
||||
currentPageIdAtom,
|
||||
currentWorkspaceIdAtom,
|
||||
rootStore,
|
||||
} from '@toeverything/plugin-infra/manager';
|
||||
import Router from 'next/router';
|
||||
|
||||
import { WorkspaceAdapters } from '../adapters/workspace';
|
||||
|
||||
@@ -31,6 +36,49 @@ if (process.env.NODE_ENV === 'development') {
|
||||
console.log('Runtime Preset', runtimeConfig);
|
||||
}
|
||||
|
||||
if (!environment.isServer) {
|
||||
currentWorkspaceIdAtom.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;
|
||||
};
|
||||
|
||||
currentPageIdAtom.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;
|
||||
};
|
||||
}
|
||||
|
||||
if (runtimeConfig.enablePlugin && !environment.isServer) {
|
||||
import('@affine/copilot');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user