diff --git a/components/LinkViews/LinkComponents/LinkActions.tsx b/components/LinkViews/LinkComponents/LinkActions.tsx index acd651d..0aecf70 100644 --- a/components/LinkViews/LinkComponents/LinkActions.tsx +++ b/components/LinkViews/LinkComponents/LinkActions.tsx @@ -60,17 +60,13 @@ export default function LinkActions({ link, className, btnStyle }: Props) { <> {isPublicRoute ? (
setLinkModal(true)} > -
+
diff --git a/components/LinkViews/LinkComponents/LinkList.tsx b/components/LinkViews/LinkComponents/LinkList.tsx index da301b4..3ba5156 100644 --- a/components/LinkViews/LinkComponents/LinkList.tsx +++ b/components/LinkViews/LinkComponents/LinkList.tsx @@ -19,6 +19,7 @@ import { useCollections } from "@/hooks/store/collections"; import { useUser } from "@/hooks/store/user"; import { useLinks } from "@/hooks/store/links"; import useLocalSettingsStore from "@/store/localSettings"; +import LinkPin from "./LinkPin"; type Props = { link: LinkIncludingShortenedCollectionAndTags; @@ -134,11 +135,16 @@ export default function LinkCardCompact({ link, editMode }: Props) {
+ diff --git a/components/LinkViews/LinkComponents/LinkMasonry.tsx b/components/LinkViews/LinkComponents/LinkMasonry.tsx index 30983d7..196db11 100644 --- a/components/LinkViews/LinkComponents/LinkMasonry.tsx +++ b/components/LinkViews/LinkComponents/LinkMasonry.tsx @@ -24,6 +24,7 @@ import { useUser } from "@/hooks/store/user"; import { useGetLink, useLinks } from "@/hooks/store/links"; import useLocalSettingsStore from "@/store/localSettings"; import clsx from "clsx"; +import LinkPin from "./LinkPin"; type Props = { link: LinkIncludingShortenedCollectionAndTags; @@ -246,6 +247,10 @@ export default function LinkMasonry({ link, editMode, columns }: Props) { "top-3 right-3 group-hover:opacity-100 group-focus-within:opacity-100 opacity-0 duration-100" } /> + ); } diff --git a/components/LinkViews/LinkComponents/LinkPin.tsx b/components/LinkViews/LinkComponents/LinkPin.tsx index cf38d21..9156333 100644 --- a/components/LinkViews/LinkComponents/LinkPin.tsx +++ b/components/LinkViews/LinkComponents/LinkPin.tsx @@ -18,10 +18,10 @@ export default function LinkPin({ link, className, btnStyle }: Props) { return (
pinLink(link)} > -
+
{ return data; }, onSuccess: (data) => { - queryClient.invalidateQueries({ queryKey: ["links"] }); - queryClient.invalidateQueries({ queryKey: ["dashboardData"] }); + queryClient.setQueryData(["dashboardData"], (oldData: any) => { + if (!oldData?.links) return undefined; + return { + ...oldData, + links: oldData.links.map((e: any) => + e.id === data.response.id + ? { + ...e, + preview: `archives/preview/${e.collectionId}/${e.id}.jpeg`, + } + : e + ), + }; + }); - queryClient.invalidateQueries({ queryKey: ["collections"] }); - queryClient.invalidateQueries({ queryKey: ["tags"] }); - queryClient.invalidateQueries({ queryKey: ["publicLinks"] }); + queryClient.setQueriesData({ queryKey: ["links"] }, (oldData: any) => { + if (!oldData) return undefined; + return { + pages: oldData.pages.map((page: any) => + page.map((item: any) => + item.id === data.response.id + ? { + ...item, + preview: `archives/preview/${item.collectionId}/${item.id}.jpeg`, + updatedAt: new Date().toISOString(), + } + : item + ) + ), + pageParams: oldData.pageParams, + }; + }); }, }); }; diff --git a/lib/api/controllers/links/linkId/updateLinkById.ts b/lib/api/controllers/links/linkId/updateLinkById.ts index 7ba5953..9c79316 100644 --- a/lib/api/controllers/links/linkId/updateLinkById.ts +++ b/lib/api/controllers/links/linkId/updateLinkById.ts @@ -124,7 +124,7 @@ export default async function updateLinkById( })), }, pinnedBy: - data?.pinnedBy && data.pinnedBy[0].id === userId + data?.pinnedBy && data.pinnedBy[0]?.id === userId ? { connect: { id: userId } } : { disconnect: { id: userId } }, },