From 1aaa9db229d2b49350820d290d2f7aa59dcb9acc Mon Sep 17 00:00:00 2001 From: Daniel Date: Fri, 16 Jun 2023 16:32:02 +0330 Subject: [PATCH] minor improvement --- pages/dashboard.tsx | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) 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"}