mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-14 21:27:20 +00:00
feat: open last workspace when back or refresh affine (#1413)
Co-authored-by: himself65 <himself65@outlook.com>
This commit is contained in:
7
apps/web/src/hooks/affine/use-last-leave-workspace-id.ts
Normal file
7
apps/web/src/hooks/affine/use-last-leave-workspace-id.ts
Normal file
@@ -0,0 +1,7 @@
|
||||
import { useAtomValue } from 'jotai';
|
||||
|
||||
import { lastWorkspaceIdAtom } from '../current/use-current-workspace';
|
||||
|
||||
export function useLastWorkspaceId() {
|
||||
return useAtomValue(lastWorkspaceIdAtom);
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
import { atom, useAtom, useAtomValue } from 'jotai';
|
||||
import { atom, useAtom, useAtomValue, useSetAtom } from 'jotai';
|
||||
import { atomWithStorage } from 'jotai/utils';
|
||||
import { useCallback } from 'react';
|
||||
|
||||
import {
|
||||
@@ -16,6 +17,11 @@ export const currentWorkspaceAtom = atom<Promise<RemWorkspace | null>>(
|
||||
}
|
||||
);
|
||||
|
||||
export const lastWorkspaceIdAtom = atomWithStorage<string | null>(
|
||||
'last_workspace_id',
|
||||
null
|
||||
);
|
||||
|
||||
export function useCurrentWorkspace(): [
|
||||
RemWorkspace | null,
|
||||
(id: string | null) => void
|
||||
@@ -23,14 +29,16 @@ export function useCurrentWorkspace(): [
|
||||
const currentWorkspace = useAtomValue(currentWorkspaceAtom);
|
||||
const [, setId] = useAtom(currentWorkspaceIdAtom);
|
||||
const [, setPageId] = useAtom(currentPageIdAtom);
|
||||
const setLast = useSetAtom(lastWorkspaceIdAtom);
|
||||
return [
|
||||
currentWorkspace,
|
||||
useCallback(
|
||||
(id: string | null) => {
|
||||
setPageId(null);
|
||||
setLast(id);
|
||||
setId(id);
|
||||
},
|
||||
[setId, setPageId]
|
||||
[setId, setLast, setPageId]
|
||||
),
|
||||
];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user