From 1260e8c093ec5fe827794d287bd1fcef41b6cc43 Mon Sep 17 00:00:00 2001 From: daniel31x13 Date: Sun, 18 Aug 2024 16:39:43 -0400 Subject: [PATCH] fixes --- components/Dropdown.tsx | 5 +- .../InputSelect/CollectionSelection.tsx | 4 +- .../LinkViews/LinkComponents/LinkActions.tsx | 221 +++++++------- .../EditCollectionSharingModal.tsx | 2 +- components/ModalContent/UploadFileModal.tsx | 2 +- components/ToggleDarkMode.tsx | 3 +- lib/api/controllers/migration/exportData.ts | 27 -- lib/api/generatePreview.ts | 2 +- pages/dashboard.tsx | 2 +- pages/public/collections/[id].tsx | 272 +++++++++--------- 10 files changed, 268 insertions(+), 272 deletions(-) diff --git a/components/Dropdown.tsx b/components/Dropdown.tsx index d1944c8..90371d8 100644 --- a/components/Dropdown.tsx +++ b/components/Dropdown.tsx @@ -61,8 +61,7 @@ export default function Dropdown({ }, [points, dropdownHeight]); return ( - !points || - (pos && ( + (!points || pos) && ( { setDropdownHeight(e.height); @@ -104,6 +103,6 @@ export default function Dropdown({ ); })} - )) + ) ); } diff --git a/components/InputSelect/CollectionSelection.tsx b/components/InputSelect/CollectionSelection.tsx index 64c25d7..81bef39 100644 --- a/components/InputSelect/CollectionSelection.tsx +++ b/components/InputSelect/CollectionSelection.tsx @@ -104,7 +104,7 @@ export default function CollectionSelection({ onChange={onChange} options={options} styles={styles} - defaultValue={showDefaultValue && defaultValue} + defaultValue={showDefaultValue ? defaultValue : null} components={{ Option: customOption, }} @@ -120,7 +120,7 @@ export default function CollectionSelection({ onChange={onChange} options={options} styles={styles} - defaultValue={showDefaultValue && defaultValue} + defaultValue={showDefaultValue ? defaultValue : null} components={{ Option: customOption, }} diff --git a/components/LinkViews/LinkComponents/LinkActions.tsx b/components/LinkViews/LinkComponents/LinkActions.tsx index 9081e47..f93f969 100644 --- a/components/LinkViews/LinkComponents/LinkActions.tsx +++ b/components/LinkViews/LinkComponents/LinkActions.tsx @@ -12,22 +12,20 @@ import { useTranslation } from "next-i18next"; import { useUser } from "@/hooks/store/user"; import { useDeleteLink, useUpdateLink } from "@/hooks/store/links"; import toast from "react-hot-toast"; +import LinkDetailModal from "@/components/ModalContent/LinkDetailModal"; +import { useRouter } from "next/router"; 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) { @@ -36,6 +34,7 @@ export default function LinkActions({ const permissions = usePermissions(link.collection.id as number); const [editLinkModal, setEditLinkModal] = useState(false); + const [linkDetailModal, setLinkDetailModal] = useState(false); const [deleteLinkModal, setDeleteLinkModal] = useState(false); const [preservedFormatsModal, setPreservedFormatsModal] = useState(false); @@ -70,120 +69,137 @@ export default function LinkActions({ ); }; + const router = useRouter(); + + const isPublicRoute = router.pathname.startsWith("/public") ? true : false; + return ( <> -
+ {isPublicRoute ? (
setLinkDetailModal(true)} > - +
+ +
-
    -
  • -
    { - (document?.activeElement as HTMLElement)?.blur(); - pinLink(); - }} - className="whitespace-nowrap" - > - {link?.pinnedBy && link.pinnedBy[0] - ? t("unpin") - : t("pin_to_dashboard")} -
    -
  • - {linkInfo !== undefined && toggleShowInfo && ( +
    + +
    +
      + {permissions === true || + (permissions?.canUpdate && ( +
    • +
      { + (document?.activeElement as HTMLElement)?.blur(); + pinLink(); + }} + className="whitespace-nowrap" + > + {link?.pinnedBy && link.pinnedBy[0] + ? t("unpin") + : t("pin_to_dashboard")} +
      +
    • + ))}
    • { (document?.activeElement as HTMLElement)?.blur(); - toggleShowInfo(); + setLinkDetailModal(true); }} className="whitespace-nowrap" > - {!linkInfo ? t("show_link_details") : t("hide_link_details")} + {t("show_link_details")}
    • - )} - {(permissions === true || permissions?.canUpdate) && ( -
    • -
      { - (document?.activeElement as HTMLElement)?.blur(); - setEditLinkModal(true); - }} - className="whitespace-nowrap" - > - {t("edit_link")} -
      -
    • - )} - {link.type === "url" && ( -
    • -
      { - (document?.activeElement as HTMLElement)?.blur(); - setPreservedFormatsModal(true); - }} - className="whitespace-nowrap" - > - {t("preserved_formats")} -
      -
    • - )} - {(permissions === true || permissions?.canDelete) && ( -
    • -
      { - (document?.activeElement as HTMLElement)?.blur(); - e.shiftKey - ? async () => { - const load = toast.loading(t("deleting")); + {(permissions === true || permissions?.canUpdate) && ( +
    • +
      { + (document?.activeElement as HTMLElement)?.blur(); + setEditLinkModal(true); + }} + className="whitespace-nowrap" + > + {t("edit_link")} +
      +
    • + )} + {link.type === "url" && ( +
    • +
      { + (document?.activeElement as HTMLElement)?.blur(); + setPreservedFormatsModal(true); + }} + className="whitespace-nowrap" + > + {t("preserved_formats")} +
      +
    • + )} + {(permissions === true || permissions?.canDelete) && ( +
    • +
      { + (document?.activeElement as HTMLElement)?.blur(); + e.shiftKey + ? async () => { + const load = toast.loading(t("deleting")); - await deleteLink.mutateAsync(link.id as number, { - onSettled: (data, error) => { - toast.dismiss(load); - - if (error) { - toast.error(error.message); - } else { - toast.success(t("deleted")); - } - }, - }); - } - : setDeleteLinkModal(true); - }} - className="whitespace-nowrap" - > - {t("delete")} -
      -
    • - )} -
    -
+ await deleteLink.mutateAsync(link.id as number, { + onSettled: (data, error) => { + toast.dismiss(load); + if (error) { + toast.error(error.message); + } else { + toast.success(t("deleted")); + } + }, + }); + } + : setDeleteLinkModal(true); + }} + className="whitespace-nowrap" + > + {t("delete")} + + + )} + + + )} {editLinkModal && ( setEditLinkModal(false)} @@ -202,6 +218,13 @@ export default function LinkActions({ link={link} /> )} + {linkDetailModal && ( + setLinkDetailModal(false)} + onEdit={() => setEditLinkModal(true)} + link={link} + /> + )} ); } diff --git a/components/ModalContent/EditCollectionSharingModal.tsx b/components/ModalContent/EditCollectionSharingModal.tsx index 9f84cb1..04c44b0 100644 --- a/components/ModalContent/EditCollectionSharingModal.tsx +++ b/components/ModalContent/EditCollectionSharingModal.tsx @@ -132,7 +132,7 @@ export default function EditCollectionSharingModal({ )} {collection.isPublic && ( -
+

{t("sharable_link_guide")}

{publicCollectionURL} diff --git a/components/ModalContent/UploadFileModal.tsx b/components/ModalContent/UploadFileModal.tsx index 1627bb1..cf5cf47 100644 --- a/components/ModalContent/UploadFileModal.tsx +++ b/components/ModalContent/UploadFileModal.tsx @@ -150,7 +150,7 @@ export default function UploadFileModal({ onClose }: Props) {