el.xwx.moe/pages/dashboard.tsx

152 lines
5.7 KiB
TypeScript
Raw Normal View History

import useCollectionStore from "@/store/collections";
2023-06-12 13:23:11 -05:00
import {
faChartSimple,
faChevronDown,
faThumbTack,
2023-06-12 13:23:11 -05:00
} 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";
export default function Dashboard() {
const { collections } = useCollectionStore();
const { links } = useLinkStore();
const { tags } = useTagStore();
2023-06-16 08:02:02 -05:00
const [numberOfLinks, setNumberOfLinks] = useState(0);
2023-06-12 13:23:11 -05:00
const [linkPinDisclosure, setLinkPinDisclosure] = useState<boolean>(() => {
2023-07-08 05:35:43 -05:00
const storedValue =
typeof window !== "undefined" &&
localStorage.getItem("linkPinDisclosure");
2023-06-12 13:23:11 -05:00
return storedValue ? storedValue === "true" : true;
});
2023-06-15 07:39:30 -05:00
useLinks({ pinnedOnly: true, sort: 0 });
2023-06-16 08:02:02 -05:00
useEffect(() => {
setNumberOfLinks(
collections.reduce(
(accumulator, collection) =>
accumulator + (collection._count as any).links,
2023-06-16 08:02:02 -05:00
0
)
);
}, [collections]);
2023-06-12 13:23:11 -05:00
useEffect(() => {
localStorage.setItem(
"linkPinDisclosure",
linkPinDisclosure ? "true" : "false"
);
}, [linkPinDisclosure]);
return (
<MainLayout>
2023-09-01 17:04:11 -05:00
<div style={{ flex: "1 1 auto" }} className="p-5 flex flex-col gap-5">
<div className="flex gap-3 items-center">
2023-05-31 21:43:42 -05:00
<div className="flex gap-2">
<FontAwesomeIcon
icon={faChartSimple}
2023-08-30 23:17:27 -05:00
className="sm:w-8 sm:h-8 w-6 h-6 mt-2 text-sky-500 dark:text-sky-500 drop-shadow"
/>
<p className="sm:text-4xl text-3xl text-black dark:text-white">
2023-05-31 21:43:42 -05:00
Dashboard
</p>
</div>
</div>
<div className="flex flex-col md:flex-row md:items-center gap-5">
2023-09-01 17:04:11 -05:00
<div className="sky-shadow flex flex-col justify-center items-center gap-2 md:w-full rounded-2xl p-10 border border-sky-100 dark:border-neutral-700 bg-gray-50 dark:bg-neutral-800">
2023-08-30 23:17:27 -05:00
<p className="font-bold text-6xl text-sky-500 dark:text-sky-500">
2023-08-11 00:11:02 -05:00
{numberOfLinks}
</p>
<p className="text-black dark:text-white text-xl">
2023-06-16 08:02:02 -05:00
{numberOfLinks === 1 ? "Link" : "Links"}
2023-05-31 21:43:42 -05:00
</p>
</div>
2023-09-01 17:04:11 -05:00
<div className="sky-shadow flex flex-col justify-center items-center gap-2 md:w-full rounded-2xl p-10 border border-sky-100 dark:border-neutral-700 bg-gray-50 dark:bg-neutral-800">
2023-08-30 23:17:27 -05:00
<p className="font-bold text-6xl text-sky-500 dark:text-sky-500">
2023-06-12 13:23:11 -05:00
{collections.length}
</p>
2023-08-11 00:11:02 -05:00
<p className="text-black dark:text-white text-xl">
2023-07-18 10:34:43 -05:00
{collections.length === 1 ? "Collection" : "Collections"}
</p>
</div>
2023-09-01 17:04:11 -05:00
<div className="sky-shadow flex flex-col justify-center items-center gap-2 md:w-full rounded-2xl p-10 border border-sky-100 dark:border-neutral-700 bg-gray-50 dark:bg-neutral-800">
2023-08-30 23:17:27 -05:00
<p className="font-bold text-6xl text-sky-500 dark:text-sky-500">
2023-08-11 00:11:02 -05:00
{tags.length}
</p>
<p className="text-black dark:text-white text-xl">
2023-07-18 10:34:43 -05:00
{tags.length === 1 ? "Tag" : "Tags"}
</p>
</div>
</div>
<div className="flex justify-between items-center">
<div className="flex gap-2 items-center">
<FontAwesomeIcon
icon={faThumbTack}
2023-08-30 23:17:27 -05:00
className="w-5 h-5 text-sky-500 dark:text-sky-500 drop-shadow"
/>
<p className="text-2xl text-black dark:text-white">Pinned Links</p>
</div>
{links.some((e) => e.pinnedBy && e.pinnedBy[0]) ? (
<button
className="text-black dark:text-white flex items-center gap-2 cursor-pointer"
onClick={() => setLinkPinDisclosure(!linkPinDisclosure)}
>
{linkPinDisclosure ? "Show Less" : "Show More"}
<FontAwesomeIcon
icon={faChevronDown}
className={`w-4 h-4 text-black dark:text-white ${
linkPinDisclosure ? "rotate-reverse" : "rotate"
}`}
/>
</button>
) : undefined}
</div>
2023-06-12 13:23:11 -05:00
2023-09-01 17:04:11 -05:00
<div
style={{ flex: "1 1 auto" }}
className="flex flex-col 2xl:flex-row items-start justify-evenly 2xl:gap-2"
>
2023-07-18 10:34:43 -05:00
{links.some((e) => e.pinnedBy && e.pinnedBy[0]) ? (
<div
className={`grid overflow-hidden 2xl:grid-cols-3 xl:grid-cols-2 grid-cols-1 gap-5 w-full ${
linkPinDisclosure ? "h-full" : "h-44"
}`}
>
{links
.filter((e) => e.pinnedBy && e.pinnedBy[0])
.map((e, i) => (
<LinkCard key={i} link={e} count={i} />
))}
</div>
2023-07-18 10:34:43 -05:00
) : (
2023-09-01 17:04:11 -05:00
<div
style={{ flex: "1 1 auto" }}
className="sky-shadow flex flex-col justify-center h-full border border-solid border-sky-100 dark:border-neutral-700 w-full mx-auto p-10 rounded-2xl bg-gray-50 dark:bg-neutral-800"
>
2023-08-11 00:11:02 -05:00
<p className="text-center text-2xl text-black dark:text-white">
2023-09-01 17:04:11 -05:00
Pin Your Favorite Links Here!
2023-07-18 10:34:43 -05:00
</p>
2023-09-06 22:13:58 -05:00
<p className="text-center mx-auto max-w-96 w-fit text-gray-500 dark:text-gray-300 text-sm mt-2">
You can Pin your favorite Links by clicking on the three dots on
each Link and clicking{" "}
<span className="font-semibold">Pin to Dashboard</span>.
2023-07-18 10:34:43 -05:00
</p>
</div>
2023-07-18 10:34:43 -05:00
)}
</div>
</div>
</MainLayout>
);
}