mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-12 20:38:52 +00:00
refactor!: next generation AFFiNE code structure (#1176)
This commit is contained in:
24
apps/web/src/hooks/current/use-current-workspace.ts
Normal file
24
apps/web/src/hooks/current/use-current-workspace.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
import { useAtom } from 'jotai';
|
||||
import { useCallback } from 'react';
|
||||
|
||||
import { currentPageIdAtom, currentWorkspaceIdAtom } from '../../atoms';
|
||||
import { RemWorkspace } from '../../shared';
|
||||
import { useWorkspace } from '../use-workspace';
|
||||
|
||||
export function useCurrentWorkspace(): [
|
||||
RemWorkspace | null,
|
||||
(id: string | null) => void
|
||||
] {
|
||||
const [id, setId] = useAtom(currentWorkspaceIdAtom);
|
||||
const [, setPageId] = useAtom(currentPageIdAtom);
|
||||
return [
|
||||
useWorkspace(id),
|
||||
useCallback(
|
||||
(id: string | null) => {
|
||||
setPageId(null);
|
||||
setId(id);
|
||||
},
|
||||
[setId, setPageId]
|
||||
),
|
||||
];
|
||||
}
|
||||
Reference in New Issue
Block a user