diff --git a/components/LinkCard.tsx b/components/LinkCard.tsx index 86637c0..04903fa 100644 --- a/components/LinkCard.tsx +++ b/components/LinkCard.tsx @@ -240,7 +240,7 @@ export default function LinkCard({ link, count, className }: Props) { if (target.id !== "expand-dropdown" + link.id) setExpandDropdown(false); }} - className="absolute top-12 right-5 w-fit" + className="absolute top-12 right-5 w-40" /> ) : null} diff --git a/components/Navbar.tsx b/components/Navbar.tsx index 158dae2..9f8984f 100644 --- a/components/Navbar.tsx +++ b/components/Navbar.tsx @@ -11,6 +11,7 @@ import useAccountStore from "@/store/account"; import ProfilePhoto from "@/components/ProfilePhoto"; import useModalStore from "@/store/modals"; import { useTheme } from "next-themes"; +import useWindowDimensions from "@/hooks/useWindowDimensions"; export default function Navbar() { const { setModal } = useModalStore(); @@ -33,7 +34,11 @@ export default function Navbar() { const [sidebar, setSidebar] = useState(false); - window.addEventListener("resize", () => setSidebar(false)); + const { width } = useWindowDimensions(); + + useEffect(() => { + setSidebar(false); + }, [width]); useEffect(() => { setSidebar(false); diff --git a/components/NoLinksFound.tsx b/components/NoLinksFound.tsx index 97b8dce..0d61f6e 100644 --- a/components/NoLinksFound.tsx +++ b/components/NoLinksFound.tsx @@ -11,7 +11,7 @@ export default function NoLinksFound({ text }: Props) { const { setModal } = useModalStore(); return ( -
{text || "You haven't created any Links Here"}
diff --git a/hooks/useInitialData.tsx b/hooks/useInitialData.tsx index a0bd1c4..c6b1ea3 100644 --- a/hooks/useInitialData.tsx +++ b/hooks/useInitialData.tsx @@ -2,7 +2,6 @@ import useCollectionStore from "@/store/collections"; import { useEffect } from "react"; import { useSession } from "next-auth/react"; import useTagStore from "@/store/tags"; -import useLinkStore from "@/store/links"; import useAccountStore from "@/store/account"; export default function useInitialData() { diff --git a/hooks/useLinks.tsx b/hooks/useLinks.tsx index 7f8d84e..56024b0 100644 --- a/hooks/useLinks.tsx +++ b/hooks/useLinks.tsx @@ -7,11 +7,14 @@ import useLinkStore from "@/store/links"; export default function useLinks( { sort, - searchFilter, - searchQuery, - pinnedOnly, collectionId, tagId, + pinnedOnly, + searchQueryString, + searchByName, + searchByUrl, + searchByDescription, + searchByTags, }: LinkRequestQuery = { sort: 0 } ) { const { links, setLinks, resetLinks } = useLinkStore(); @@ -20,20 +23,37 @@ export default function useLinks( const { reachedBottom, setReachedBottom } = useDetectPageBottom(); const getLinks = async (isInitialCall: boolean, cursor?: number) => { - const requestBody: LinkRequestQuery = { - cursor, + const params = { sort, - searchFilter, - searchQuery, - pinnedOnly, + cursor, collectionId, tagId, + pinnedOnly, + searchQueryString, + searchByName, + searchByUrl, + searchByDescription, + searchByTags, }; - const encodedData = encodeURIComponent(JSON.stringify(requestBody)); + const buildQueryString = (params: LinkRequestQuery) => { + return Object.keys(params) + .filter((key) => params[key as keyof LinkRequestQuery] !== undefined) + .map( + (key) => + `${encodeURIComponent(key)}=${encodeURIComponent( + params[key as keyof LinkRequestQuery] as string + )}` + ) + .join("&"); + }; + + const queryString = buildQueryString(params); const response = await fetch( - `/api/v1/links?body=${encodeURIComponent(encodedData)}` + `/api/v1/${ + router.asPath === "/dashboard" ? "dashboard" : "links" + }?${queryString}` ); const data = await response.json(); @@ -45,7 +65,15 @@ export default function useLinks( resetLinks(); getLinks(true); - }, [router, sort, searchFilter]); + }, [ + router, + sort, + searchQueryString, + searchByName, + searchByUrl, + searchByDescription, + searchByTags, + ]); useEffect(() => { if (reachedBottom) getLinks(false, links?.at(-1)?.id); diff --git a/hooks/useWindowDimensions.tsx b/hooks/useWindowDimensions.tsx new file mode 100644 index 0000000..bea7246 --- /dev/null +++ b/hooks/useWindowDimensions.tsx @@ -0,0 +1,25 @@ +import React, { useState, useEffect } from "react"; + +export default function useWindowDimensions() { + const [dimensions, setDimensions] = useState({ + height: window.innerHeight, + width: window.innerWidth, + }); + + useEffect(() => { + function handleResize() { + setDimensions({ + height: window.innerHeight, + width: window.innerWidth, + }); + } + + window.addEventListener("resize", handleResize); + + return () => { + window.removeEventListener("resize", handleResize); + }; + }, []); + + return dimensions; +} diff --git a/layouts/MainLayout.tsx b/layouts/MainLayout.tsx index 48ecbb8..f3f17cb 100644 --- a/layouts/MainLayout.tsx +++ b/layouts/MainLayout.tsx @@ -26,7 +26,7 @@ export default function MainLayout({ children }: Props) {+ Recently Added Links +
++ View Your Recently Added Links Here! +
++ This section will view your latest added Links across every + Collections you have access to. +
+ +