import useLinkStore from "@/store/links"; import useCollectionStore from "@/store/collections"; import useTagStore from "@/store/tags"; import MainLayout from "@/layouts/MainLayout"; import LinkCard from "@/components/LinkViews/LinkComponents/LinkCard"; import { useEffect, useState } from "react"; import useLinks from "@/hooks/useLinks"; import Link from "next/link"; import useWindowDimensions from "@/hooks/useWindowDimensions"; import React from "react"; import { toast } from "react-hot-toast"; import { MigrationFormat, MigrationRequest } from "@/types/global"; import DashboardItem from "@/components/DashboardItem"; import NewLinkModal from "@/components/ModalContent/NewLinkModal"; import PageHeader from "@/components/PageHeader"; export default function Dashboard() { const { collections } = useCollectionStore(); const { links } = useLinkStore(); const { tags } = useTagStore(); const [numberOfLinks, setNumberOfLinks] = useState(0); const [showLinks, setShowLinks] = useState(3); useLinks({ pinnedOnly: true, sort: 0 }); useEffect(() => { setNumberOfLinks( collections.reduce( (accumulator, collection) => accumulator + (collection._count as any).links, 0 ) ); }, [collections]); const handleNumberOfLinksToShow = () => { if (window.innerWidth > 1535) { setShowLinks(6); } else if (window.innerWidth > 1295) { setShowLinks(4); } else setShowLinks(3); }; const { width } = useWindowDimensions(); useEffect(() => { handleNumberOfLinksToShow(); }, [width]); 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..."); setTimeout(() => { location.reload(); }, 2000); }; reader.onerror = function (e) { console.log("Error:", e); }; } }; const [newLinkModal, setNewLinkModal] = useState(false); return (
View All
{links[0] ? (
{links.slice(0, showLinks).map((e, i) => ( ))}
) : (

View Your Recently Added Links Here!

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

{ setNewLinkModal(true); }} className="inline-flex items-center gap-2 text-sm btn btn-accent dark:border-violet-400 text-white" > Add New Link

Import From

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

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.

)}
{newLinkModal ? ( setNewLinkModal(false)} /> ) : undefined}
); }