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"; import EditLinkModal from "@/components/ModalContent/EditLinkModal"; import Link from "next/link"; 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]); const [editLinkModal, setEditLinkModal] = useState(false); return ( <>
{/*
*/}
{/*
*/} {router.pathname.startsWith("/public") ? linkCollection?.name || link?.collection?.name : "Dashboard"}
{link?.collection?.ownerId === userId || linkCollection?.members.some( (e) => e.userId === userId && e.canUpdate ) ? (
{ setEditLinkModal(true); }} className={`btn btn-ghost btn-square btn-sm`} >
) : 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}
{link && editLinkModal ? ( setEditLinkModal(false)} activeLink={link} /> ) : undefined}
); }