2023-03-22 18:11:54 -05:00
|
|
|
import useCollectionStore from "@/store/collections";
|
2023-04-25 07:39:46 -05:00
|
|
|
import {
|
|
|
|
faEllipsis,
|
2023-07-13 17:19:49 -05:00
|
|
|
faFolder,
|
2023-04-25 07:39:46 -05:00
|
|
|
faPlus,
|
2023-05-14 10:41:08 -05:00
|
|
|
faSort,
|
2023-04-25 07:39:46 -05:00
|
|
|
} from "@fortawesome/free-solid-svg-icons";
|
2023-03-28 02:31:50 -05:00
|
|
|
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
2023-02-24 11:32:28 -06:00
|
|
|
import CollectionCard from "@/components/CollectionCard";
|
2023-03-28 02:31:50 -05:00
|
|
|
import Dropdown from "@/components/Dropdown";
|
2023-06-13 23:40:23 -05:00
|
|
|
import { useState } from "react";
|
2023-05-14 10:41:08 -05:00
|
|
|
import MainLayout from "@/layouts/MainLayout";
|
2023-05-26 23:29:45 -05:00
|
|
|
import { useSession } from "next-auth/react";
|
2023-06-12 23:46:32 -05:00
|
|
|
import useModalStore from "@/store/modals";
|
2023-06-13 23:40:23 -05:00
|
|
|
import SortDropdown from "@/components/SortDropdown";
|
|
|
|
import { Sort } from "@/types/global";
|
|
|
|
import useSort from "@/hooks/useSort";
|
2023-10-09 07:35:33 -05:00
|
|
|
import { useTheme } from "next-themes";
|
2023-02-24 11:32:28 -06:00
|
|
|
|
2023-06-09 17:31:14 -05:00
|
|
|
export default function Collections() {
|
2023-10-09 07:35:33 -05:00
|
|
|
const { theme } = useTheme();
|
|
|
|
|
2023-03-22 18:11:54 -05:00
|
|
|
const { collections } = useCollectionStore();
|
2023-04-23 08:26:39 -05:00
|
|
|
const [expandDropdown, setExpandDropdown] = useState(false);
|
2023-05-14 10:41:08 -05:00
|
|
|
const [sortDropdown, setSortDropdown] = useState(false);
|
2023-06-14 17:34:54 -05:00
|
|
|
const [sortBy, setSortBy] = useState<Sort>(Sort.DateNewestFirst);
|
2023-05-15 15:45:06 -05:00
|
|
|
const [sortedCollections, setSortedCollections] = useState(collections);
|
2023-04-23 08:26:39 -05:00
|
|
|
|
2023-10-24 16:03:33 -05:00
|
|
|
const { data } = useSession();
|
2023-05-26 23:29:45 -05:00
|
|
|
|
2023-06-12 23:46:32 -05:00
|
|
|
const { setModal } = useModalStore();
|
2023-05-14 10:41:08 -05:00
|
|
|
|
2023-06-13 23:40:23 -05:00
|
|
|
useSort({ sortBy, setData: setSortedCollections, data: collections });
|
2023-05-15 15:45:06 -05:00
|
|
|
|
2023-02-24 11:32:28 -06:00
|
|
|
return (
|
2023-05-14 10:41:08 -05:00
|
|
|
<MainLayout>
|
2023-04-30 15:54:40 -05:00
|
|
|
<div className="p-5">
|
2023-10-24 16:03:33 -05:00
|
|
|
<div className="flex gap-3 justify-between mb-5">
|
|
|
|
<div className="flex gap-3">
|
|
|
|
<div className="flex items-center gap-3">
|
2023-05-31 21:43:42 -05:00
|
|
|
<FontAwesomeIcon
|
2023-07-13 17:19:49 -05:00
|
|
|
icon={faFolder}
|
2023-10-24 16:03:33 -05:00
|
|
|
className="sm:w-10 sm:h-10 w-6 h-6 text-sky-500 dark:text-sky-500 drop-shadow"
|
2023-05-31 21:43:42 -05:00
|
|
|
/>
|
2023-10-24 16:03:33 -05:00
|
|
|
<div>
|
|
|
|
<p className="text-3xl capitalize text-black dark:text-white font-thin">
|
|
|
|
Your Collections
|
|
|
|
</p>
|
|
|
|
|
|
|
|
<p className="capitalize text-black dark:text-white">
|
|
|
|
Collections you own
|
|
|
|
</p>
|
|
|
|
</div>
|
2023-05-14 10:41:08 -05:00
|
|
|
</div>
|
2023-10-24 16:03:33 -05:00
|
|
|
<div className="relative mt-2">
|
2023-05-14 10:41:08 -05:00
|
|
|
<div
|
|
|
|
onClick={() => setExpandDropdown(!expandDropdown)}
|
2023-05-27 22:21:35 -05:00
|
|
|
id="expand-dropdown"
|
2023-08-14 22:25:25 -05:00
|
|
|
className="inline-flex rounded-md cursor-pointer hover:bg-slate-200 hover:dark:bg-neutral-700 duration-100 p-1"
|
2023-05-14 10:41:08 -05:00
|
|
|
>
|
|
|
|
<FontAwesomeIcon
|
|
|
|
icon={faEllipsis}
|
2023-05-27 22:21:35 -05:00
|
|
|
id="expand-dropdown"
|
2023-08-22 17:34:46 -05:00
|
|
|
className="w-5 h-5 text-gray-500 dark:text-gray-300"
|
2023-05-14 10:41:08 -05:00
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
{expandDropdown ? (
|
|
|
|
<Dropdown
|
|
|
|
items={[
|
|
|
|
{
|
2023-05-27 22:21:35 -05:00
|
|
|
name: "New Collection",
|
2023-05-14 10:41:08 -05:00
|
|
|
onClick: () => {
|
2023-06-12 23:46:32 -05:00
|
|
|
setModal({
|
|
|
|
modal: "COLLECTION",
|
|
|
|
state: true,
|
|
|
|
method: "CREATE",
|
|
|
|
});
|
2023-05-14 10:41:08 -05:00
|
|
|
setExpandDropdown(false);
|
|
|
|
},
|
|
|
|
},
|
|
|
|
]}
|
|
|
|
onClickOutside={(e: Event) => {
|
|
|
|
const target = e.target as HTMLInputElement;
|
2023-05-27 22:21:35 -05:00
|
|
|
if (target.id !== "expand-dropdown")
|
|
|
|
setExpandDropdown(false);
|
2023-05-14 10:41:08 -05:00
|
|
|
}}
|
2023-10-24 16:03:33 -05:00
|
|
|
className="absolute top-8 sm:left-0 right-0 sm:right-auto w-36"
|
2023-05-14 10:41:08 -05:00
|
|
|
/>
|
|
|
|
) : null}
|
|
|
|
</div>
|
2023-03-28 02:31:50 -05:00
|
|
|
</div>
|
2023-05-14 10:41:08 -05:00
|
|
|
|
2023-10-24 16:03:33 -05:00
|
|
|
<div className="relative mt-2">
|
2023-04-30 15:54:40 -05:00
|
|
|
<div
|
2023-05-14 10:41:08 -05:00
|
|
|
onClick={() => setSortDropdown(!sortDropdown)}
|
|
|
|
id="sort-dropdown"
|
2023-08-14 22:25:25 -05:00
|
|
|
className="inline-flex rounded-md cursor-pointer hover:bg-slate-200 hover:dark:bg-neutral-700 duration-100 p-1"
|
2023-04-30 15:54:40 -05:00
|
|
|
>
|
|
|
|
<FontAwesomeIcon
|
2023-05-14 10:41:08 -05:00
|
|
|
icon={faSort}
|
|
|
|
id="sort-dropdown"
|
2023-08-22 17:34:46 -05:00
|
|
|
className="w-5 h-5 text-gray-500 dark:text-gray-300"
|
2023-04-30 15:54:40 -05:00
|
|
|
/>
|
|
|
|
</div>
|
2023-05-14 10:41:08 -05:00
|
|
|
|
|
|
|
{sortDropdown ? (
|
2023-06-13 23:40:23 -05:00
|
|
|
<SortDropdown
|
|
|
|
sortBy={sortBy}
|
|
|
|
setSort={setSortBy}
|
|
|
|
toggleSortDropdown={() => setSortDropdown(!sortDropdown)}
|
|
|
|
/>
|
2023-04-30 15:54:40 -05:00
|
|
|
) : null}
|
|
|
|
</div>
|
2023-03-28 02:31:50 -05:00
|
|
|
</div>
|
2023-05-14 10:41:08 -05:00
|
|
|
|
2023-07-18 11:28:58 -05:00
|
|
|
<div className="grid xl:grid-cols-3 sm:grid-cols-2 grid-cols-1 gap-5">
|
2023-10-24 16:03:33 -05:00
|
|
|
{sortedCollections
|
2023-10-24 16:11:25 -05:00
|
|
|
.filter((e) => e.ownerId === data?.user.id)
|
2023-10-24 16:03:33 -05:00
|
|
|
.map((e, i) => {
|
|
|
|
return <CollectionCard key={i} collection={e} />;
|
|
|
|
})}
|
2023-04-23 08:26:39 -05:00
|
|
|
|
2023-04-30 15:54:40 -05:00
|
|
|
<div
|
2023-10-09 07:35:33 -05:00
|
|
|
className="p-5 bg-gray-50 dark:bg-neutral-800 self-stretch border border-solid border-sky-100 dark:border-neutral-700 min-h-[12rem] rounded-2xl cursor-pointer shadow duration-100 hover:shadow-none flex flex-col gap-4 justify-center items-center group"
|
2023-06-12 23:46:32 -05:00
|
|
|
onClick={() => {
|
|
|
|
setModal({
|
|
|
|
modal: "COLLECTION",
|
|
|
|
state: true,
|
|
|
|
method: "CREATE",
|
|
|
|
});
|
|
|
|
}}
|
2023-04-30 15:54:40 -05:00
|
|
|
>
|
2023-08-11 00:11:02 -05:00
|
|
|
<p className="text-black dark:text-white group-hover:opacity-0 duration-100">
|
2023-05-25 09:17:20 -05:00
|
|
|
New Collection
|
|
|
|
</p>
|
|
|
|
<FontAwesomeIcon
|
|
|
|
icon={faPlus}
|
2023-08-30 23:17:27 -05:00
|
|
|
className="w-8 h-8 text-sky-500 dark:text-sky-500 group-hover:w-12 group-hover:h-12 group-hover:-mt-10 duration-100"
|
2023-05-25 09:17:20 -05:00
|
|
|
/>
|
2023-04-30 15:54:40 -05:00
|
|
|
</div>
|
2023-04-25 07:39:46 -05:00
|
|
|
</div>
|
2023-10-24 16:03:33 -05:00
|
|
|
|
|
|
|
{sortedCollections.filter((e) => e.ownerId !== data?.user.id)[0] ? (
|
|
|
|
<>
|
|
|
|
<div className="flex items-center gap-3 my-5">
|
|
|
|
<FontAwesomeIcon
|
|
|
|
icon={faFolder}
|
|
|
|
className="sm:w-10 sm:h-10 w-6 h-6 text-sky-500 dark:text-sky-500 drop-shadow"
|
|
|
|
/>
|
|
|
|
<div>
|
|
|
|
<p className="text-3xl capitalize text-black dark:text-white font-thin">
|
|
|
|
Other Collections
|
|
|
|
</p>
|
|
|
|
|
|
|
|
<p className="capitalize text-black dark:text-white">
|
|
|
|
Shared collections you're a member of
|
|
|
|
</p>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div className="grid xl:grid-cols-3 sm:grid-cols-2 grid-cols-1 gap-5">
|
|
|
|
{sortedCollections
|
|
|
|
.filter((e) => e.ownerId !== data?.user.id)
|
|
|
|
.map((e, i) => {
|
|
|
|
return <CollectionCard key={i} collection={e} />;
|
|
|
|
})}
|
|
|
|
</div>
|
|
|
|
</>
|
|
|
|
) : undefined}
|
2023-03-28 02:31:50 -05:00
|
|
|
</div>
|
2023-05-14 10:41:08 -05:00
|
|
|
</MainLayout>
|
2023-02-24 11:32:28 -06:00
|
|
|
);
|
|
|
|
}
|