fix: correct router logic (#2342)

This commit is contained in:
Himself65
2023-05-12 13:55:45 +08:00
committed by GitHub
parent 10b4558947
commit 21fdced2bd
24 changed files with 206 additions and 332 deletions
@@ -1,5 +1,4 @@
import { useAtom, useAtomValue, useSetAtom } from 'jotai';
import { atomWithStorage } from 'jotai/utils';
import { useAtom, useAtomValue } from 'jotai';
import { useCallback } from 'react';
import { currentPageIdAtom, currentWorkspaceIdAtom } from '../../atoms';
@@ -11,11 +10,6 @@ import type { AllWorkspace } from '../../shared';
*/
export const currentWorkspaceAtom = rootCurrentWorkspaceAtom;
export const lastWorkspaceIdAtom = atomWithStorage<string | null>(
'last_workspace_id',
null
);
export function useCurrentWorkspace(): [
AllWorkspace,
(id: string | null) => void
@@ -23,16 +17,17 @@ export function useCurrentWorkspace(): [
const currentWorkspace = useAtomValue(rootCurrentWorkspaceAtom);
const [, setId] = useAtom(currentWorkspaceIdAtom);
const [, setPageId] = useAtom(currentPageIdAtom);
const setLast = useSetAtom(lastWorkspaceIdAtom);
return [
currentWorkspace,
useCallback(
(id: string | null) => {
if (typeof window !== 'undefined' && id) {
localStorage.setItem('last_workspace_id', id);
}
setPageId(null);
setLast(id);
setId(id);
},
[setId, setLast, setPageId]
[setId, setPageId]
),
];
}