From 9b1506a64ea10276408f88bf03852f7bd5901524 Mon Sep 17 00:00:00 2001 From: daniel31x13 Date: Wed, 11 Sep 2024 01:38:38 -0400 Subject: [PATCH] add pin to hover view + add number of pins to dashboard + bug fixes --- components/DashboardItem.tsx | 7 +- .../LinkViews/LinkComponents/LinkActions.tsx | 45 ++------- .../LinkViews/LinkComponents/LinkCard.tsx | 21 ++-- .../LinkViews/LinkComponents/LinkMasonry.tsx | 16 +-- .../LinkViews/LinkComponents/LinkPin.tsx | 35 +++++++ components/ViewDropdown.tsx | 2 +- hooks/store/links.tsx | 40 +++++--- .../dashboard/getDashboardDataV2.ts | 8 +- .../links/linkId/updateLinkById.ts | 2 +- lib/client/pinLink.ts | 47 +++++++++ pages/dashboard.tsx | 98 ++++++++++--------- 11 files changed, 198 insertions(+), 123 deletions(-) create mode 100644 components/LinkViews/LinkComponents/LinkPin.tsx create mode 100644 lib/client/pinLink.ts diff --git a/components/DashboardItem.tsx b/components/DashboardItem.tsx index d255c4b..efc1303 100644 --- a/components/DashboardItem.tsx +++ b/components/DashboardItem.tsx @@ -14,12 +14,7 @@ export default function dashboardItem({

{name}

-

- {value < 1000 ? value : (value / 1000).toFixed(1) + "k"} -

-

- {value} -

+

{value || 0}

); diff --git a/components/LinkViews/LinkComponents/LinkActions.tsx b/components/LinkViews/LinkComponents/LinkActions.tsx index 2076932..acd651d 100644 --- a/components/LinkViews/LinkComponents/LinkActions.tsx +++ b/components/LinkViews/LinkComponents/LinkActions.tsx @@ -7,12 +7,12 @@ import usePermissions from "@/hooks/usePermissions"; import DeleteLinkModal from "@/components/ModalContent/DeleteLinkModal"; import { dropdownTriggerer } from "@/lib/client/utils"; import { useTranslation } from "next-i18next"; -import { useUser } from "@/hooks/store/user"; -import { useDeleteLink, useGetLink, useUpdateLink } from "@/hooks/store/links"; +import { useDeleteLink, useGetLink } from "@/hooks/store/links"; import toast from "react-hot-toast"; import LinkModal from "@/components/ModalContent/LinkModal"; import { useRouter } from "next/router"; import clsx from "clsx"; +import usePinLink from "@/lib/client/pinLink"; type Props = { link: LinkIncludingShortenedCollectionAndTags; @@ -27,41 +27,14 @@ export default function LinkActions({ link, className, btnStyle }: Props) { const permissions = usePermissions(link.collection.id as number); const getLink = useGetLink(); + const pinLink = usePinLink(); + const [editLinkModal, setEditLinkModal] = useState(false); const [linkModal, setLinkModal] = useState(false); const [deleteLinkModal, setDeleteLinkModal] = useState(false); - const { data: user = {} } = useUser(); - - const updateLink = useUpdateLink(); const deleteLink = useDeleteLink(); - const pinLink = async () => { - const isAlreadyPinned = link?.pinnedBy && link.pinnedBy[0] ? true : false; - - const load = toast.loading(t("updating")); - - await updateLink.mutateAsync( - { - ...link, - pinnedBy: isAlreadyPinned ? [{ id: undefined }] : [{ id: user.id }], - }, - { - onSettled: (data, error) => { - toast.dismiss(load); - - if (error) { - toast.error(error.message); - } else { - toast.success( - isAlreadyPinned ? t("link_unpinned") : t("link_pinned") - ); - } - }, - } - ); - }; - const updateArchive = async () => { const load = toast.loading(t("sending_request")); @@ -103,7 +76,7 @@ export default function LinkActions({ link, className, btnStyle }: Props) { ) : (
@@ -117,7 +90,7 @@ export default function LinkActions({ link, className, btnStyle }: Props) {