From 99540141ead76844123f213bec5cdc7585d58d19 Mon Sep 17 00:00:00 2001 From: Philipinho <16838612+Philipinho@users.noreply.github.com> Date: Wed, 16 Apr 2025 23:23:27 +0100 Subject: [PATCH] WIP --- .../table-of-contents/table-of-contents.tsx | 5 +++ .../features/editor/readonly-page-editor.tsx | 1 + .../src/features/share/atoms/sidebar-atom.ts | 8 +--- .../features/share/components/share-shell.tsx | 43 +++++++++++++++---- .../features/share/hooks/use-toggle-toc.ts | 8 ++++ 5 files changed, 51 insertions(+), 14 deletions(-) create mode 100644 apps/client/src/features/share/hooks/use-toggle-toc.ts diff --git a/apps/client/src/features/editor/components/table-of-contents/table-of-contents.tsx b/apps/client/src/features/editor/components/table-of-contents/table-of-contents.tsx index 37b50a0a..b309d67d 100644 --- a/apps/client/src/features/editor/components/table-of-contents/table-of-contents.tsx +++ b/apps/client/src/features/editor/components/table-of-contents/table-of-contents.tsx @@ -149,6 +149,11 @@ export const TableOfContents: FC = (props) => { return ( <> + {props.isShare && ( + + {t("Table of contents")} + + )}
{links.map((item, idx) => ( diff --git a/apps/client/src/features/editor/readonly-page-editor.tsx b/apps/client/src/features/editor/readonly-page-editor.tsx index 2aff5be5..bd6b9f6b 100644 --- a/apps/client/src/features/editor/readonly-page-editor.tsx +++ b/apps/client/src/features/editor/readonly-page-editor.tsx @@ -61,6 +61,7 @@ export default function ReadonlyPageEditor({ } }} > +
); } diff --git a/apps/client/src/features/share/atoms/sidebar-atom.ts b/apps/client/src/features/share/atoms/sidebar-atom.ts index cfb7e39d..0bc9d681 100644 --- a/apps/client/src/features/share/atoms/sidebar-atom.ts +++ b/apps/client/src/features/share/atoms/sidebar-atom.ts @@ -1,13 +1,9 @@ import { atomWithWebStorage } from "@/lib/jotai-helper.ts"; -import { atom } from 'jotai/index'; +import { atom } from 'jotai'; export const tableOfContentAsideAtom = atomWithWebStorage( "showTOC", true, ); -export const mobileTableOfContentAsideAtom = atom(false); - - - -const sidebarWidthAtom = atomWithWebStorage('sidebarWidth', 300); \ No newline at end of file +export const mobileTableOfContentAsideAtom = atom(false); \ No newline at end of file diff --git a/apps/client/src/features/share/components/share-shell.tsx b/apps/client/src/features/share/components/share-shell.tsx index 0501b8ed..7df03c07 100644 --- a/apps/client/src/features/share/components/share-shell.tsx +++ b/apps/client/src/features/share/components/share-shell.tsx @@ -1,5 +1,6 @@ import React from "react"; import { + ActionIcon, Affix, AppShell, Button, @@ -27,6 +28,8 @@ import { mobileTableOfContentAsideAtom, tableOfContentAsideAtom, } from "@/features/share/atoms/sidebar-atom.ts"; +import { IconList } from "@tabler/icons-react"; +import { useToggleToc } from "@/features/share/hooks/use-toggle-toc.ts"; const MemoizedSharedTree = React.memo(SharedTree); @@ -43,6 +46,8 @@ export default function ShareShell({ const [tocOpened] = useAtom(tableOfContentAsideAtom); const [mobileTocOpened] = useAtom(mobileTableOfContentAsideAtom); + const toggleTocMobile = useToggleToc(mobileTableOfContentAsideAtom); + const toggleToc = useToggleToc(tableOfContentAsideAtom); const { shareId } = useParams(); const { data } = useGetSharedPageTreeQuery(shareId); @@ -61,16 +66,16 @@ export default function ShareShell({ }} aside={{ width: 300, - breakpoint: "md", + breakpoint: "sm", collapsed: { - mobile: mobileTocOpened, - desktop: tocOpened, + mobile: !mobileTocOpened, + desktop: !tocOpened, }, }} padding="md" > - + {data?.pageTree?.length > 0 && ( <> @@ -97,6 +102,32 @@ export default function ShareShell({ )} + <> + + + + + + + + + + + + + @@ -124,10 +155,6 @@ export default function ShareShell({ - - Table of contents - -
{readOnlyEditor && ( diff --git a/apps/client/src/features/share/hooks/use-toggle-toc.ts b/apps/client/src/features/share/hooks/use-toggle-toc.ts new file mode 100644 index 00000000..ec43086a --- /dev/null +++ b/apps/client/src/features/share/hooks/use-toggle-toc.ts @@ -0,0 +1,8 @@ +import { useAtom } from "jotai"; + +export function useToggleToc(tocAtom: any) { + const [tocState, setTocState] = useAtom(tocAtom); + return () => { + setTocState(!tocState); + } +}