feat: reintroduce outline navigation

This commit is contained in:
iCrawl
2023-11-13 18:03:23 +01:00
parent 7c935dc84b
commit bc8f83368a
21 changed files with 130 additions and 82 deletions

View File

@@ -0,0 +1,22 @@
'use client';
import { createContext, useContext, useMemo, useState } from 'react';
import type { PropsWithChildren, Dispatch, SetStateAction } from 'react';
import type { TableOfContentsSerialized } from '~/components/TableOfContentItems';
export const OutlineContext = createContext<{
members: TableOfContentsSerialized[] | null | undefined;
setMembers: Dispatch<SetStateAction<TableOfContentsSerialized[] | null | undefined>>;
}>({ members: undefined, setMembers: (_) => {} });
export const OutlineProvider = ({ children }: PropsWithChildren) => {
const [members, setMembers] = useState<TableOfContentsSerialized[] | null | undefined>(undefined);
const value = useMemo(() => ({ members, setMembers }), [members]);
return <OutlineContext.Provider value={value}>{children}</OutlineContext.Provider>;
};
export function useOutline() {
return useContext(OutlineContext);
}