import { useState } from "react"; import { CollectionIncludingMembersAndLinkCount, LinkIncludingShortenedCollectionAndTags, } from "@/types/global"; import usePermissions from "@/hooks/usePermissions"; import EditLinkModal from "@/components/ModalContent/EditLinkModal"; import DeleteLinkModal from "@/components/ModalContent/DeleteLinkModal"; import PreservedFormatsModal from "@/components/ModalContent/PreservedFormatsModal"; import { dropdownTriggerer } from "@/lib/client/utils"; import { useTranslation } from "next-i18next"; import { useUser } from "@/hooks/store/user"; import { useDeleteLink, useUpdateLink } from "@/hooks/store/links"; type Props = { link: LinkIncludingShortenedCollectionAndTags; collection: CollectionIncludingMembersAndLinkCount; position?: string; toggleShowInfo?: () => void; linkInfo?: boolean; alignToTop?: boolean; flipDropdown?: boolean; }; export default function LinkActions({ link, toggleShowInfo, position, linkInfo, alignToTop, flipDropdown, }: Props) { const { t } = useTranslation(); const permissions = usePermissions(link.collection.id as number); const [editLinkModal, setEditLinkModal] = useState(false); const [deleteLinkModal, setDeleteLinkModal] = useState(false); const [preservedFormatsModal, setPreservedFormatsModal] = useState(false); const { data: user = {} } = useUser(); const updateLink = useUpdateLink(); const deleteLink = useDeleteLink(); const pinLink = async () => { const isAlreadyPinned = link?.pinnedBy && link.pinnedBy[0]; await updateLink.mutateAsync({ ...link, pinnedBy: isAlreadyPinned ? undefined : [{ id: user.id }], }); }; return ( <>
{editLinkModal ? ( setEditLinkModal(false)} activeLink={link} /> ) : undefined} {deleteLinkModal ? ( setDeleteLinkModal(false)} activeLink={link} /> ) : undefined} {preservedFormatsModal ? ( setPreservedFormatsModal(false)} activeLink={link} /> ) : undefined} {/* {expandedLink ? ( setExpandedLink(false)} link={link} /> ) : undefined} */} ); }