mirror of
https://github.com/docmost/docmost.git
synced 2026-08-28 01:07:08 +08:00
feat(share): add full width toggle for shared pages
This commit is contained in:
@@ -1,6 +1,11 @@
|
|||||||
import { atom } from "jotai";
|
import { atom } from "jotai";
|
||||||
|
import { atomWithStorage } from "jotai/utils";
|
||||||
import { ISharedPageTree } from "@/features/share/types/share.types";
|
import { ISharedPageTree } from "@/features/share/types/share.types";
|
||||||
import { SharedPageTreeNode } from "@/features/share/utils";
|
import { SharedPageTreeNode } from "@/features/share/utils";
|
||||||
|
|
||||||
export const sharedPageTreeAtom = atom<ISharedPageTree | null>(null);
|
export const sharedPageTreeAtom = atom<ISharedPageTree | null>(null);
|
||||||
export const sharedTreeDataAtom = atom<SharedPageTreeNode[] | null>(null);
|
export const sharedTreeDataAtom = atom<SharedPageTreeNode[] | null>(null);
|
||||||
|
export const sharedPageFullWidthAtom = atomWithStorage<boolean>(
|
||||||
|
"shared-page-full-width",
|
||||||
|
false,
|
||||||
|
);
|
||||||
@@ -14,7 +14,11 @@ import { readOnlyEditorAtom } from "@/features/editor/atoms/editor-atoms.ts";
|
|||||||
import { ThemeToggle } from "@/components/theme-toggle.tsx";
|
import { ThemeToggle } from "@/components/theme-toggle.tsx";
|
||||||
import { useAtomValue, useSetAtom } from "jotai";
|
import { useAtomValue, useSetAtom } from "jotai";
|
||||||
import { useAtom } from "jotai";
|
import { useAtom } from "jotai";
|
||||||
import { sharedPageTreeAtom, sharedTreeDataAtom } from "@/features/share/atoms/shared-page-atom";
|
import {
|
||||||
|
sharedPageFullWidthAtom,
|
||||||
|
sharedPageTreeAtom,
|
||||||
|
sharedTreeDataAtom,
|
||||||
|
} from "@/features/share/atoms/shared-page-atom";
|
||||||
import { buildSharedPageTree } from "@/features/share/utils";
|
import { buildSharedPageTree } from "@/features/share/utils";
|
||||||
import {
|
import {
|
||||||
desktopSidebarAtom,
|
desktopSidebarAtom,
|
||||||
@@ -27,7 +31,7 @@ import {
|
|||||||
mobileTableOfContentAsideAtom,
|
mobileTableOfContentAsideAtom,
|
||||||
tableOfContentAsideAtom,
|
tableOfContentAsideAtom,
|
||||||
} from "@/features/share/atoms/sidebar-atom.ts";
|
} from "@/features/share/atoms/sidebar-atom.ts";
|
||||||
import { IconList } from "@tabler/icons-react";
|
import { IconArrowsHorizontal, IconList } from "@tabler/icons-react";
|
||||||
import { useToggleToc } from "@/features/share/hooks/use-toggle-toc.ts";
|
import { useToggleToc } from "@/features/share/hooks/use-toggle-toc.ts";
|
||||||
import classes from "./share.module.css";
|
import classes from "./share.module.css";
|
||||||
import {
|
import {
|
||||||
@@ -55,6 +59,7 @@ export default function ShareShell({
|
|||||||
const [mobileTocOpened] = useAtom(mobileTableOfContentAsideAtom);
|
const [mobileTocOpened] = useAtom(mobileTableOfContentAsideAtom);
|
||||||
const toggleTocMobile = useToggleToc(mobileTableOfContentAsideAtom);
|
const toggleTocMobile = useToggleToc(mobileTableOfContentAsideAtom);
|
||||||
const toggleToc = useToggleToc(tableOfContentAsideAtom);
|
const toggleToc = useToggleToc(tableOfContentAsideAtom);
|
||||||
|
const [fullWidth, setFullWidth] = useAtom(sharedPageFullWidthAtom);
|
||||||
|
|
||||||
const { shareId } = useParams();
|
const { shareId } = useParams();
|
||||||
const { data } = useGetSharedPageTreeQuery(shareId);
|
const { data } = useGetSharedPageTreeQuery(shareId);
|
||||||
@@ -166,6 +171,20 @@ export default function ShareShell({
|
|||||||
<IconList size={20} stroke={2} />
|
<IconList size={20} stroke={2} />
|
||||||
</ActionIcon>
|
</ActionIcon>
|
||||||
</Tooltip>
|
</Tooltip>
|
||||||
|
|
||||||
|
<Tooltip label={t("Full width")} withArrow>
|
||||||
|
<ActionIcon
|
||||||
|
variant={fullWidth ? "light" : "default"}
|
||||||
|
style={fullWidth ? undefined : { border: "none" }}
|
||||||
|
aria-label={t("Full width")}
|
||||||
|
aria-pressed={fullWidth}
|
||||||
|
onClick={() => setFullWidth((v) => !v)}
|
||||||
|
visibleFrom="sm"
|
||||||
|
size="sm"
|
||||||
|
>
|
||||||
|
<IconArrowsHorizontal size={20} stroke={2} />
|
||||||
|
</ActionIcon>
|
||||||
|
</Tooltip>
|
||||||
</>
|
</>
|
||||||
|
|
||||||
<ThemeToggle />
|
<ThemeToggle />
|
||||||
|
|||||||
@@ -9,7 +9,10 @@ import { extractPageSlugId } from "@/lib";
|
|||||||
import { Error404 } from "@/components/ui/error-404.tsx";
|
import { Error404 } from "@/components/ui/error-404.tsx";
|
||||||
import ShareBranding from "@/features/share/components/share-branding.tsx";
|
import ShareBranding from "@/features/share/components/share-branding.tsx";
|
||||||
import { useAtomValue } from "jotai";
|
import { useAtomValue } from "jotai";
|
||||||
import { sharedTreeDataAtom } from "@/features/share/atoms/shared-page-atom.ts";
|
import {
|
||||||
|
sharedPageFullWidthAtom,
|
||||||
|
sharedTreeDataAtom,
|
||||||
|
} from "@/features/share/atoms/shared-page-atom.ts";
|
||||||
import { isPageInTree } from "@/features/share/utils.ts";
|
import { isPageInTree } from "@/features/share/utils.ts";
|
||||||
|
|
||||||
export default function SharedPage() {
|
export default function SharedPage() {
|
||||||
@@ -23,6 +26,7 @@ export default function SharedPage() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const sharedTreeData = useAtomValue(sharedTreeDataAtom);
|
const sharedTreeData = useAtomValue(sharedTreeDataAtom);
|
||||||
|
const fullWidth = useAtomValue(sharedPageFullWidthAtom);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (shareId && data) {
|
if (shareId && data) {
|
||||||
@@ -59,7 +63,7 @@ export default function SharedPage() {
|
|||||||
)}
|
)}
|
||||||
</Helmet>
|
</Helmet>
|
||||||
|
|
||||||
<Container size={900} p={0}>
|
<Container fluid={fullWidth} size={fullWidth ? undefined : 900} p={0}>
|
||||||
<ReadonlyPageEditor
|
<ReadonlyPageEditor
|
||||||
key={data.page.id}
|
key={data.page.id}
|
||||||
title={data.page.title}
|
title={data.page.title}
|
||||||
|
|||||||
Reference in New Issue
Block a user