import { graphql, useStaticQuery } from "gatsby" import { sort } from "ramda" import React, { FC, HTMLAttributes } from "react" import { useLockBodyScroll } from "../../hooks/useLockBodyScroll" import useSidebar from "../../hooks/useSidebar" import { IAllArchivesQuery, IFileOrFolder } from "../../types" import { humanize } from "../../utils" import { Sidebar } from "../Sidebar" import useBuildTree from "./../../hooks/useBuildTree" import * as SC from "./styles" const ALL_ARCHIVES = graphql` query { allFile(filter: { sourceInstanceName: { eq: "what-is-archive" } }) { edges { node { relativePath } } } } ` function Tree({ item }: { item: IFileOrFolder }) { const { setOpenOnMobile } = useSidebar() const { unlock } = useLockBodyScroll() return ( { setOpenOnMobile(false) unlock() }} > {humanize(item.title)} ) } export const ArchivesSidebar: FC> = props => { const archives = useStaticQuery(ALL_ARCHIVES) const tree = useBuildTree(archives, "/archives") const sortedTree = sort((a, b) => a.title.localeCompare(b.title), tree) return ( {sortedTree.map(node => ( ))} ) }