import useCollectionStore from "@/store/collections"; import { faChartSimple, faChevronDown, faChevronRight, faClockRotateLeft, faFileImport, faThumbTack, } from "@fortawesome/free-solid-svg-icons"; import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; import MainLayout from "@/layouts/MainLayout"; import useLinkStore from "@/store/links"; import useTagStore from "@/store/tags"; import LinkCard from "@/components/LinkCard"; import { useEffect, useState } from "react"; import useLinks from "@/hooks/useLinks"; import Link from "next/link"; import useWindowDimensions from "@/hooks/useWindowDimensions"; import { faPlus } from "@fortawesome/free-solid-svg-icons"; import React from "react"; import useModalStore from "@/store/modals"; import { toast } from "react-hot-toast"; import { MigrationFormat, MigrationRequest } from "@/types/global"; import ClickAwayHandler from "@/components/ClickAwayHandler"; export default function Dashboard() { const { collections } = useCollectionStore(); const { links } = useLinkStore(); const { tags } = useTagStore(); const { setModal } = useModalStore(); const [numberOfLinks, setNumberOfLinks] = useState(0); const [showRecents, setShowRecents] = useState(3); const [linkPinDisclosure, setLinkPinDisclosure] = useState(() => { const storedValue = typeof window !== "undefined" && localStorage.getItem("linkPinDisclosure"); return storedValue ? storedValue === "true" : true; }); useLinks({ pinnedOnly: true, sort: 0 }); useEffect(() => { setNumberOfLinks( collections.reduce( (accumulator, collection) => accumulator + (collection._count as any).links, 0 ) ); }, [collections]); useEffect(() => { localStorage.setItem( "linkPinDisclosure", linkPinDisclosure ? "true" : "false" ); }, [linkPinDisclosure]); const handleNumberOfRecents = () => { if (window.innerWidth > 1550) { setShowRecents(6); } else if (window.innerWidth > 1295) { setShowRecents(4); } else setShowRecents(3); }; const { width } = useWindowDimensions(); useEffect(() => { handleNumberOfRecents(); }, [width]); const [importDropdown, setImportDropdown] = useState(false); const importBookmarks = async (e: any, format: MigrationFormat) => { const file: File = e.target.files[0]; if (file) { var reader = new FileReader(); reader.readAsText(file, "UTF-8"); reader.onload = async function (e) { const load = toast.loading("Importing..."); const request: string = e.target?.result as string; const body: MigrationRequest = { format, data: request, }; const response = await fetch("/api/v1/migration", { method: "POST", body: JSON.stringify(body), }); const data = await response.json(); toast.dismiss(load); toast.success("Imported the Bookmarks! Reloading the page..."); setImportDropdown(false); setTimeout(() => { location.reload(); }, 2000); }; reader.onerror = function (e) { console.log("Error:", e); }; } }; return (

Dashboard

{numberOfLinks}

{numberOfLinks === 1 ? "Link" : "Links"}

{collections.length}

{collections.length === 1 ? "Collection" : "Collections"}

{tags.length}

{tags.length === 1 ? "Tag" : "Tags"}

Recently Added Links

View All
{links[0] ? (
{links.slice(0, showRecents).map((e, i) => ( ))}
) : (

View Your Recently Added Links Here!

This section will view your latest added Links across every Collections you have access to.

{ setModal({ modal: "LINK", state: true, method: "CREATE", }); }} className="inline-flex gap-1 relative w-[11.4rem] items-center font-semibold select-none cursor-pointer p-2 px-3 rounded-md dark:hover:bg-sky-600 text-white bg-sky-700 hover:bg-sky-600 duration-100 group" > Create New Link
setImportDropdown(!importDropdown)} id="import-dropdown" className="flex gap-2 select-none text-sm cursor-pointer p-2 px-3 rounded-md border dark:hover:border-sky-600 text-black border-black dark:text-white dark:border-white hover:border-sky-500 hover:dark:border-sky-500 hover:text-sky-500 hover:dark:text-sky-500 duration-100 group" > Import Your Bookmarks
{importDropdown ? ( { const target = e.target as HTMLInputElement; if (target.id !== "import-dropdown") setImportDropdown(false); }} className={`absolute text-black dark:text-white top-10 left-0 w-52 py-1 shadow-md border border-sky-100 dark:border-neutral-700 bg-gray-50 dark:bg-neutral-800 rounded-md flex flex-col z-20`} >
) : null}
)}

Pinned Links

{links.some((e) => e.pinnedBy && e.pinnedBy[0]) ? ( ) : undefined}
{links.some((e) => e.pinnedBy && e.pinnedBy[0]) ? (
{links .filter((e) => e.pinnedBy && e.pinnedBy[0]) .map((e, i) => ( ))}
) : (

Pin Your Favorite Links Here!

You can Pin your favorite Links by clicking on the three dots on each Link and clicking{" "} Pin to Dashboard.

)}
); }