diff --git a/pages/dashboard.tsx b/pages/dashboard.tsx index 590c469..83e35c4 100644 --- a/pages/dashboard.tsx +++ b/pages/dashboard.tsx @@ -19,6 +19,8 @@ export default function Dashboard() { const { links } = useLinkStore(); const { tags } = useTagStore(); + const [numberOfLinks, setNumberOfLinks] = useState(0); + const [tagPinDisclosure, setTagPinDisclosure] = useState(() => { const storedValue = localStorage.getItem("tagPinDisclosure"); return storedValue ? storedValue === "true" : true; @@ -37,6 +39,15 @@ export default function Dashboard() { useLinks({ pinnedOnly: true, sort: 0 }); + useEffect(() => { + setNumberOfLinks( + collections.reduce( + (accumulator, collection) => accumulator + collection._count.links, + 0 + ) + ); + }, [collections]); + useEffect(() => { localStorage.setItem( "tagPinDisclosure", @@ -74,18 +85,15 @@ export default function Dashboard() { +
+

- {collections.reduce( - (accumulator, collection) => - accumulator + collection._count.links, - 0 - )} + {numberOfLinks}

- Links - {/* {links.length == 1 ? "Links" : "Link"} */} + {numberOfLinks === 1 ? "Link" : "Links"}