import LinkSidebar from "@/components/LinkSidebar"; import { ReactNode, useEffect, useState } from "react"; import ModalManagement from "@/components/ModalManagement"; import useModalStore from "@/store/modals"; import { useRouter } from "next/router"; import ClickAwayHandler from "@/components/ClickAwayHandler"; import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; import { faChevronLeft } from "@fortawesome/free-solid-svg-icons"; import useWindowDimensions from "@/hooks/useWindowDimensions"; import { faPen, faBoxesStacked, faTrashCan, } from "@fortawesome/free-solid-svg-icons"; import useLinkStore from "@/store/links"; import { CollectionIncludingMembersAndLinkCount, LinkIncludingShortenedCollectionAndTags, } from "@/types/global"; import { useSession } from "next-auth/react"; import useCollectionStore from "@/store/collections"; interface Props { children: ReactNode; } export default function LinkLayout({ children }: Props) { const { modal } = useModalStore(); const router = useRouter(); useEffect(() => { modal ? (document.body.style.overflow = "hidden") : (document.body.style.overflow = "auto"); }, [modal]); const [sidebar, setSidebar] = useState(false); const { width } = useWindowDimensions(); useEffect(() => { setSidebar(false); }, [width]); useEffect(() => { setSidebar(false); }, [router]); const toggleSidebar = () => { setSidebar(!sidebar); }; const session = useSession(); const userId = session.data?.user.id; const { setModal } = useModalStore(); const { links, removeLink } = useLinkStore(); const { collections } = useCollectionStore(); const [linkCollection, setLinkCollection] = useState(); const [link, setLink] = useState(); useEffect(() => { if (links[0]) setLink(links.find((e) => e.id === Number(router.query.id))); }, [links]); useEffect(() => { if (link) setLinkCollection(collections.find((e) => e.id === link?.collection?.id)); }, [link, collections]); return ( <>
{/*
*/}
{/*
*/}
{ if (router.pathname.startsWith("/public")) { router.push( `/public/collections/${ linkCollection?.id || link?.collection.id }` ); } else { router.push(`/dashboard`); } }} className="inline-flex gap-1 hover:opacity-60 items-center select-none cursor-pointer p-2 lg:p-0 lg:px-1 lg:my-2 text-neutral rounded-md duration-100" > Back{" "} to{" "} {router.pathname.startsWith("/public") ? linkCollection?.name || link?.collection?.name : "Dashboard"}
{link?.collection?.ownerId === userId || linkCollection?.members.some( (e) => e.userId === userId && e.canUpdate ) ? (
{ link ? setModal({ modal: "LINK", state: true, active: link, method: "UPDATE", }) : undefined; }} className={`hover:opacity-60 duration-100 py-2 px-2 cursor-pointer flex items-center gap-4 w-full rounded-md h-8`} >
) : undefined}
{ link ? setModal({ modal: "LINK", state: true, active: link, method: "FORMATS", }) : undefined; }} title="Preserved Formats" className={`hover:opacity-60 duration-100 py-2 px-2 cursor-pointer flex items-center gap-4 w-full rounded-md h-8`} >
{link?.collection?.ownerId === userId || linkCollection?.members.some( (e) => e.userId === userId && e.canDelete ) ? (
{ if (link?.id) { removeLink(link.id); router.back(); } }} title="Delete" className={`hover:opacity-60 duration-100 py-2 px-2 cursor-pointer flex items-center gap-4 w-full rounded-md h-8`} >
) : undefined}
{children} {sidebar ? (
setSidebar(false)} />
) : null}
); }