fix: current page atom (#4515)

This commit is contained in:
Alex Yang 2023-09-26 09:53:01 -05:00 committed by GitHub
parent 1b6cd70247
commit a633fb6dea
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 3 deletions

View File

@ -60,6 +60,6 @@ export declare const pushLayoutAtom: WritableAtom<
void void
>; >;
export declare const deleteLayoutAtom: WritableAtom<null, [string], void>; export declare const deleteLayoutAtom: WritableAtom<null, [string], void>;
export declare const currentPageAtom: Atom<Promise<Page>>; export declare const currentPageIdAtom: Atom<string | null>;
export declare const currentWorkspaceAtom: Atom<Promise<Workspace>>; export declare const currentWorkspaceAtom: Atom<Promise<Workspace>>;
export declare const rootStore: ReturnType<typeof getDefaultStore>; export declare const rootStore: ReturnType<typeof getDefaultStore>;

View File

@ -1,5 +1,6 @@
import { import {
currentPageAtom, currentPageIdAtom,
currentWorkspaceAtom,
deleteLayoutAtom, deleteLayoutAtom,
pushLayoutAtom, pushLayoutAtom,
} from '@affine/sdk/entry'; } from '@affine/sdk/entry';
@ -15,7 +16,11 @@ import { createRoot } from 'react-dom/client';
const Outline = () => { const Outline = () => {
const tocPanelRef = useRef<TOCNotesPanel | null>(null); const tocPanelRef = useRef<TOCNotesPanel | null>(null);
const currentPage = useAtomValue(currentPageAtom); const currentPageId = useAtomValue(currentPageIdAtom);
assertExists(currentPageId, 'current page id');
const currentWorkspace = useAtomValue(currentWorkspaceAtom);
const currentPage = currentWorkspace.getPage(currentPageId);
assertExists(currentPage, 'current page');
if (!tocPanelRef.current) { if (!tocPanelRef.current) {
tocPanelRef.current = new TOCNotesPanel(); tocPanelRef.current = new TOCNotesPanel();