2023-05-14 10:41:08 -05:00
|
|
|
import useCollectionStore from "@/store/collections";
|
2023-06-12 13:23:11 -05:00
|
|
|
import {
|
|
|
|
faChartSimple,
|
|
|
|
faChevronDown,
|
|
|
|
} from "@fortawesome/free-solid-svg-icons";
|
2023-05-14 10:41:08 -05:00
|
|
|
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
|
|
|
import MainLayout from "@/layouts/MainLayout";
|
|
|
|
import useLinkStore from "@/store/links";
|
|
|
|
import useTagStore from "@/store/tags";
|
2023-06-20 09:39:03 -05:00
|
|
|
import LinkCard from "@/components/LinkCard";
|
2023-05-14 10:41:08 -05:00
|
|
|
import Link from "next/link";
|
2023-06-11 17:28:37 -05:00
|
|
|
import CollectionCard from "@/components/CollectionCard";
|
2023-06-12 13:23:11 -05:00
|
|
|
import { Disclosure, Transition } from "@headlessui/react";
|
2023-05-14 10:41:08 -05:00
|
|
|
import { useEffect, useState } from "react";
|
2023-06-14 17:34:54 -05:00
|
|
|
import useLinks from "@/hooks/useLinks";
|
2023-05-14 10:41:08 -05:00
|
|
|
|
2023-06-09 17:31:14 -05:00
|
|
|
export default function Dashboard() {
|
2023-05-14 10:41:08 -05:00
|
|
|
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 [tagPinDisclosure, setTagPinDisclosure] = useState<boolean>(() => {
|
2023-07-08 05:35:43 -05:00
|
|
|
const storedValue =
|
|
|
|
typeof window !== "undefined" && localStorage.getItem("tagPinDisclosure");
|
2023-06-12 13:23:11 -05:00
|
|
|
return storedValue ? storedValue === "true" : true;
|
|
|
|
});
|
2023-05-14 10:41:08 -05:00
|
|
|
|
2023-06-12 13:23:11 -05:00
|
|
|
const [collectionPinDisclosure, setCollectionPinDisclosure] =
|
|
|
|
useState<boolean>(() => {
|
2023-07-08 05:35:43 -05:00
|
|
|
const storedValue =
|
|
|
|
typeof window !== "undefined" &&
|
|
|
|
localStorage.getItem("collectionPinDisclosure");
|
2023-06-12 13:23:11 -05:00
|
|
|
return storedValue ? storedValue === "true" : true;
|
2023-05-14 10:41:08 -05:00
|
|
|
});
|
|
|
|
|
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-14 17:34:54 -05:00
|
|
|
|
2023-06-16 08:02:02 -05:00
|
|
|
useEffect(() => {
|
|
|
|
setNumberOfLinks(
|
|
|
|
collections.reduce(
|
2023-06-20 09:39:03 -05:00
|
|
|
(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(
|
|
|
|
"tagPinDisclosure",
|
|
|
|
tagPinDisclosure ? "true" : "false"
|
2023-05-14 10:41:08 -05:00
|
|
|
);
|
2023-06-12 13:23:11 -05:00
|
|
|
}, [tagPinDisclosure]);
|
2023-05-31 21:43:42 -05:00
|
|
|
|
2023-06-12 13:23:11 -05:00
|
|
|
useEffect(() => {
|
|
|
|
localStorage.setItem(
|
|
|
|
"collectionPinDisclosure",
|
|
|
|
collectionPinDisclosure ? "true" : "false"
|
|
|
|
);
|
|
|
|
}, [collectionPinDisclosure]);
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
localStorage.setItem(
|
|
|
|
"linkPinDisclosure",
|
|
|
|
linkPinDisclosure ? "true" : "false"
|
|
|
|
);
|
|
|
|
}, [linkPinDisclosure]);
|
2023-05-14 10:41:08 -05:00
|
|
|
|
|
|
|
return (
|
|
|
|
// ml-80
|
|
|
|
<MainLayout>
|
|
|
|
<div className="p-5">
|
|
|
|
<div className="flex gap-3 items-center mb-5">
|
2023-05-31 21:43:42 -05:00
|
|
|
<div className="flex gap-2">
|
2023-05-14 10:41:08 -05:00
|
|
|
<FontAwesomeIcon
|
|
|
|
icon={faChartSimple}
|
2023-06-05 10:13:04 -05:00
|
|
|
className="sm:w-8 sm:h-8 w-6 h-6 mt-2 text-sky-500 drop-shadow"
|
2023-05-14 10:41:08 -05:00
|
|
|
/>
|
2023-05-31 21:43:42 -05:00
|
|
|
<p className="sm:text-4xl text-3xl capitalize bg-gradient-to-tr from-sky-500 to-slate-400 bg-clip-text text-transparent font-bold">
|
|
|
|
Dashboard
|
|
|
|
</p>
|
2023-05-14 10:41:08 -05:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
2023-06-16 08:02:02 -05:00
|
|
|
<br />
|
|
|
|
|
2023-06-12 13:23:11 -05:00
|
|
|
<div className="flex flex-col md:flex-row md:items-center justify-evenly gap-2 mb-10">
|
2023-05-14 10:41:08 -05:00
|
|
|
<div className="flex items-baseline gap-2">
|
2023-06-12 13:23:11 -05:00
|
|
|
<p className="font-bold text-6xl bg-gradient-to-tr from-sky-500 to-slate-400 bg-clip-text text-transparent">
|
2023-06-16 08:02:02 -05:00
|
|
|
{numberOfLinks}
|
2023-06-12 13:23:11 -05:00
|
|
|
</p>
|
2023-05-31 21:43:42 -05:00
|
|
|
<p className="text-sky-900 text-xl">
|
2023-06-16 08:02:02 -05:00
|
|
|
{numberOfLinks === 1 ? "Link" : "Links"}
|
2023-05-31 21:43:42 -05:00
|
|
|
</p>
|
2023-05-14 10:41:08 -05:00
|
|
|
</div>
|
|
|
|
|
|
|
|
<div className="flex items-baseline gap-2">
|
2023-06-12 13:23:11 -05:00
|
|
|
<p className="font-bold text-6xl bg-gradient-to-tr from-sky-500 to-slate-400 bg-clip-text text-transparent">
|
|
|
|
{collections.length}
|
|
|
|
</p>
|
2023-05-14 10:41:08 -05:00
|
|
|
<p className="text-sky-900 text-xl">Collections</p>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div className="flex items-baseline gap-2">
|
2023-06-12 13:23:11 -05:00
|
|
|
<p className="font-bold text-6xl bg-gradient-to-tr from-sky-500 to-slate-400 bg-clip-text text-transparent">
|
|
|
|
{tags.length}
|
|
|
|
</p>
|
2023-05-14 10:41:08 -05:00
|
|
|
<p className="text-sky-900 text-xl">Tags</p>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
2023-06-12 13:23:11 -05:00
|
|
|
{/* <hr className="my-5 border-sky-100" /> */}
|
|
|
|
<br />
|
|
|
|
|
|
|
|
<div className="flex flex-col 2xl:flex-row items-start justify-evenly 2xl:gap-2">
|
|
|
|
<Disclosure defaultOpen={linkPinDisclosure}>
|
2023-06-13 14:19:37 -05:00
|
|
|
<div className="flex flex-col gap-5 p-2 w-full mx-auto md:w-2/3">
|
2023-06-12 13:23:11 -05:00
|
|
|
<Disclosure.Button
|
|
|
|
onClick={() => {
|
|
|
|
setLinkPinDisclosure(!linkPinDisclosure);
|
|
|
|
}}
|
|
|
|
className="flex justify-between gap-2 items-baseline shadow active:shadow-inner duration-100 py-2 px-4 rounded-full"
|
|
|
|
>
|
|
|
|
<p className="text-sky-600 text-xl">Pinned Links</p>
|
|
|
|
|
|
|
|
<div className="text-sky-600 flex items-center gap-2">
|
|
|
|
{linkPinDisclosure ? "Hide" : "Show"}
|
2023-05-14 10:41:08 -05:00
|
|
|
<FontAwesomeIcon
|
2023-06-12 13:23:11 -05:00
|
|
|
icon={faChevronDown}
|
|
|
|
className={`w-4 h-4 text-sky-300 ${
|
|
|
|
linkPinDisclosure ? "rotate-reverse" : "rotate"
|
|
|
|
}`}
|
2023-05-14 10:41:08 -05:00
|
|
|
/>
|
|
|
|
</div>
|
2023-06-12 13:23:11 -05:00
|
|
|
</Disclosure.Button>
|
|
|
|
|
|
|
|
<Transition
|
|
|
|
enter="transition duration-100 ease-out"
|
|
|
|
enterFrom="transform opacity-0 -translate-y-3"
|
|
|
|
enterTo="transform opacity-100 translate-y-0"
|
|
|
|
leave="transition duration-100 ease-out"
|
|
|
|
leaveFrom="transform opacity-100 translate-y-0"
|
|
|
|
leaveTo="transform opacity-0 -translate-y-3"
|
|
|
|
>
|
2023-06-18 00:27:57 -05:00
|
|
|
<Disclosure.Panel className="grid grid-cols-1 xl:grid-cols-2 gap-5 w-full">
|
2023-06-15 07:39:30 -05:00
|
|
|
{links
|
2023-06-18 00:27:57 -05:00
|
|
|
.filter((e) => e.pinnedBy && e.pinnedBy[0])
|
2023-06-15 07:39:30 -05:00
|
|
|
.map((e, i) => (
|
2023-06-20 09:39:03 -05:00
|
|
|
<LinkCard key={i} link={e} count={i} />
|
2023-06-15 07:39:30 -05:00
|
|
|
))}
|
2023-06-12 13:23:11 -05:00
|
|
|
</Disclosure.Panel>
|
|
|
|
</Transition>
|
2023-05-14 10:41:08 -05:00
|
|
|
</div>
|
2023-06-12 13:23:11 -05:00
|
|
|
</Disclosure>
|
|
|
|
|
2023-06-13 14:19:37 -05:00
|
|
|
{/* <Disclosure defaultOpen={collectionPinDisclosure}>
|
2023-06-12 13:23:11 -05:00
|
|
|
<div className="flex flex-col gap-5 p-2 w-full">
|
|
|
|
<Disclosure.Button
|
|
|
|
onClick={() => {
|
|
|
|
setCollectionPinDisclosure(!collectionPinDisclosure);
|
|
|
|
}}
|
|
|
|
className="flex justify-between gap-2 items-baseline shadow active:shadow-inner duration-100 py-2 px-4 rounded-full"
|
|
|
|
>
|
|
|
|
<p className="text-sky-600 text-xl">Pinned Collections</p>
|
2023-05-14 10:41:08 -05:00
|
|
|
|
2023-06-12 13:23:11 -05:00
|
|
|
<div className="text-sky-600 flex items-center gap-2">
|
|
|
|
{collectionPinDisclosure ? "Hide" : "Show"}
|
2023-05-14 10:41:08 -05:00
|
|
|
<FontAwesomeIcon
|
2023-06-12 13:23:11 -05:00
|
|
|
icon={faChevronDown}
|
|
|
|
className={`w-4 h-4 text-sky-300 ${
|
|
|
|
collectionPinDisclosure ? "rotate-reverse" : "rotate"
|
|
|
|
}`}
|
2023-05-14 10:41:08 -05:00
|
|
|
/>
|
|
|
|
</div>
|
2023-06-12 13:23:11 -05:00
|
|
|
</Disclosure.Button>
|
|
|
|
<Transition
|
|
|
|
enter="transition duration-100 ease-out"
|
|
|
|
enterFrom="transform opacity-0 -translate-y-3"
|
|
|
|
enterTo="transform opacity-100 translate-y-0"
|
|
|
|
leave="transition duration-100 ease-out"
|
|
|
|
leaveFrom="transform opacity-100 translate-y-0"
|
|
|
|
leaveTo="transform opacity-0 -translate-y-3"
|
|
|
|
>
|
|
|
|
<Disclosure.Panel className="flex flex-col gap-5 w-full">
|
|
|
|
{collections.slice(0, 5).map((e, i) => (
|
|
|
|
<CollectionCard key={i} collection={e} />
|
|
|
|
))}
|
|
|
|
</Disclosure.Panel>
|
|
|
|
</Transition>
|
2023-05-14 10:41:08 -05:00
|
|
|
</div>
|
2023-06-13 14:19:37 -05:00
|
|
|
</Disclosure> */}
|
2023-05-15 13:29:51 -05:00
|
|
|
|
2023-06-13 14:19:37 -05:00
|
|
|
{/* <Disclosure defaultOpen={tagPinDisclosure}>
|
2023-06-12 13:23:11 -05:00
|
|
|
<div className="flex flex-col gap-5 p-2 w-full">
|
|
|
|
<Disclosure.Button
|
|
|
|
onClick={() => {
|
|
|
|
setTagPinDisclosure(!tagPinDisclosure);
|
|
|
|
}}
|
|
|
|
className="flex justify-between gap-2 items-baseline shadow active:shadow-inner duration-100 py-2 px-4 rounded-full"
|
|
|
|
>
|
|
|
|
<p className="text-sky-600 text-xl">Pinned Tags</p>
|
|
|
|
|
|
|
|
<div className="text-sky-600 flex items-center gap-2">
|
|
|
|
{tagPinDisclosure ? "Hide" : "Show"}
|
|
|
|
<FontAwesomeIcon
|
|
|
|
icon={faChevronDown}
|
|
|
|
className={`w-4 h-4 text-sky-300 ${
|
|
|
|
tagPinDisclosure ? "rotate-reverse" : "rotate"
|
|
|
|
}`}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</Disclosure.Button>
|
|
|
|
<Transition
|
|
|
|
enter="transition duration-100 ease-out"
|
|
|
|
enterFrom="transform opacity-0 -translate-y-3"
|
|
|
|
enterTo="transform opacity-100 translate-y-0"
|
|
|
|
leave="transition duration-100 ease-out"
|
|
|
|
leaveFrom="transform opacity-100 translate-y-0"
|
|
|
|
leaveTo="transform opacity-0 -translate-y-3"
|
|
|
|
>
|
|
|
|
<Disclosure.Panel className="flex gap-2 flex-wrap">
|
|
|
|
{tags.slice(0, 19).map((e, i) => (
|
|
|
|
<Link
|
|
|
|
href={`/tags/${e.id}`}
|
|
|
|
key={i}
|
|
|
|
className="px-2 py-1 bg-sky-200 rounded-full hover:opacity-60 duration-100 text-sky-700"
|
|
|
|
>
|
|
|
|
{e.name}
|
|
|
|
</Link>
|
|
|
|
))}
|
|
|
|
</Disclosure.Panel>
|
|
|
|
</Transition>
|
2023-05-15 13:29:51 -05:00
|
|
|
</div>
|
2023-06-13 14:19:37 -05:00
|
|
|
</Disclosure> */}
|
2023-05-14 10:41:08 -05:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</MainLayout>
|
|
|
|
);
|
|
|
|
}
|