mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-12 12:28:42 +00:00
fix: correct router logic (#2342)
This commit is contained in:
@@ -37,6 +37,7 @@
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/ws": "^8.5.4",
|
||||
"next": "^13.4.1",
|
||||
"ws": "^8.13.0"
|
||||
},
|
||||
"version": "0.6.0-canary.0"
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import type { EditorContainer } from '@blocksuite/editor';
|
||||
import { atom, createStore } from 'jotai';
|
||||
import { atomWithStorage, createJSONStorage } from 'jotai/utils';
|
||||
import Router from 'next/router';
|
||||
|
||||
import type { WorkspaceFlavour } from './type';
|
||||
|
||||
@@ -32,12 +33,49 @@ export const rootCurrentWorkspaceIdAtom = atomWithStorage<string | null>(
|
||||
null,
|
||||
createJSONStorage(() => sessionStorage)
|
||||
);
|
||||
|
||||
rootCurrentWorkspaceIdAtom.onMount = set => {
|
||||
if (typeof window !== 'undefined') {
|
||||
const callback = (url: string) => {
|
||||
const value = url.split('/')[2];
|
||||
if (value) {
|
||||
set(value);
|
||||
} else {
|
||||
set(null);
|
||||
}
|
||||
};
|
||||
callback(window.location.pathname);
|
||||
Router.events.on('routeChangeStart', callback);
|
||||
return () => {
|
||||
Router.events.off('routeChangeStart', callback);
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
export const rootCurrentPageIdAtom = atomWithStorage<string | null>(
|
||||
'root-current-page-id',
|
||||
null,
|
||||
createJSONStorage(() => sessionStorage)
|
||||
);
|
||||
|
||||
rootCurrentPageIdAtom.onMount = set => {
|
||||
if (typeof window !== 'undefined') {
|
||||
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);
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
// current editor atom, each app should have only one editor in the same time
|
||||
export const rootCurrentEditorAtom = atom<Readonly<EditorContainer> | null>(
|
||||
null
|
||||
|
||||
Reference in New Issue
Block a user