Skip to content

Commit

Permalink
add private pages to sidebar
Browse files Browse the repository at this point in the history
  • Loading branch information
Southclaws committed Oct 9, 2024
1 parent 670349b commit a5006a2
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,18 @@ export function ContentNavigationList() {
>
<LStack gap="1">
<CategoryList />
<DatagraphNavTree currentNode={nodeSlug} />
<DatagraphNavTree
label="Library"
href="/l"
currentNode={nodeSlug}
visibility={["published"]}
/>
<DatagraphNavTree
label="Private"
href="/drafts"
currentNode={nodeSlug}
visibility={["draft", "review", "unlisted"]}
/>
</LStack>

<LStack gap="1">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import Link from "next/link";

import { useNodeList } from "@/api/openapi-client/nodes";
import { Visibility } from "@/api/openapi-schema";
import { useSession } from "@/auth";
import { LibraryPageTree } from "@/components/library/LibraryPageTree/LibraryPageTree";
import { LStack } from "@/styled-system/jsx";
Expand All @@ -13,12 +14,17 @@ import { Unready } from "../../Unready";
import { NavigationHeader } from "../ContentNavigationList/NavigationHeader";

type Props = {
label: string;
href: string;
currentNode: string | undefined;
visibility: Visibility[];
};

export function useDatagraphNavTree() {
export function useDatagraphNavTree({ visibility }: Props) {
const session = useSession();
const { data, error } = useNodeList();
const { data, error } = useNodeList({
visibility,
});
if (!data) {
return {
ready: false as const,
Expand All @@ -35,16 +41,18 @@ export function useDatagraphNavTree() {
};
}

export function DatagraphNavTree({ currentNode }: Props) {
const { ready, error, data, canManageLibrary } = useDatagraphNavTree();
export function DatagraphNavTree(props: Props) {
const { ready, error, data, canManageLibrary } = useDatagraphNavTree(props);
if (!ready) {
return <Unready error={error} />;
}

const { label, href, currentNode } = props;

return (
<LStack gap="1">
<NavigationHeader
href="/l"
href={href}
controls={
canManageLibrary && (
<Link href="/l/new">
Expand All @@ -53,13 +61,13 @@ export function DatagraphNavTree({ currentNode }: Props) {
)
}
>
Library
{label}
</NavigationHeader>

<LibraryPageTree
currentNode={currentNode}
data={{
label: "Library",
label: label,
children: data.nodes,
}}
/>
Expand Down

0 comments on commit a5006a2

Please sign in to comment.