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,
|
|
|
|
} 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-11-29 08:41:24 -06:00
|
|
|
import NewCollectionModal from "@/components/Modals/NewCollectionModal";
|
2023-02-24 11:32:28 -06:00
|
|
|
|
2023-06-09 17:31:14 -05:00
|
|
|
export default function Collections() {
|
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-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-11-28 23:46:31 -06:00
|
|
|
const [newModalIsOpen, setNewModalIsOpen] = useState(false);
|
|
|
|
const closeNewModal = () => setNewModalIsOpen(false);
|
|
|
|
|
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-11-24 08:39:38 -06:00
|
|
|
className="sm:w-10 sm:h-10 w-6 h-6 text-primary drop-shadow"
|
2023-05-31 21:43:42 -05:00
|
|
|
/>
|
2023-10-24 16:03:33 -05:00
|
|
|
<div>
|
2023-11-24 07:39:55 -06:00
|
|
|
<p className="text-3xl capitalize font-thin">
|
2023-10-24 16:03:33 -05:00
|
|
|
Your Collections
|
|
|
|
</p>
|
|
|
|
|
2023-11-24 07:39:55 -06:00
|
|
|
<p>Collections you own</p>
|
2023-10-24 16:03:33 -05:00
|
|
|
</div>
|
2023-05-14 10:41:08 -05:00
|
|
|
</div>
|
2023-10-24 16:03:33 -05:00
|
|
|
<div className="relative mt-2">
|
2023-11-30 03:36:40 -06:00
|
|
|
<div className="dropdown dropdown-bottom">
|
|
|
|
<div
|
|
|
|
tabIndex={0}
|
|
|
|
role="button"
|
|
|
|
className="btn btn-ghost btn-sm btn-square text-neutral"
|
|
|
|
>
|
|
|
|
<FontAwesomeIcon
|
|
|
|
icon={faEllipsis}
|
|
|
|
title="More"
|
|
|
|
className="w-5 h-5"
|
|
|
|
/>
|
|
|
|
</div>
|
2023-11-30 03:39:51 -06:00
|
|
|
<ul className="dropdown-content z-[1] menu p-1 shadow bg-base-200 border border-neutral-content rounded-xl w-36 mt-1">
|
2023-11-30 03:36:40 -06:00
|
|
|
<li>
|
|
|
|
<div
|
|
|
|
className="px-2 py-1 rounded-lg"
|
|
|
|
role="button"
|
|
|
|
tabIndex={0}
|
|
|
|
onClick={() => {
|
|
|
|
(document?.activeElement as HTMLElement)?.blur();
|
2023-06-12 23:46:32 -05:00
|
|
|
setModal({
|
|
|
|
modal: "COLLECTION",
|
|
|
|
state: true,
|
|
|
|
method: "CREATE",
|
|
|
|
});
|
2023-11-30 03:36:40 -06:00
|
|
|
}}
|
|
|
|
>
|
|
|
|
New Collection
|
|
|
|
</div>
|
|
|
|
</li>
|
|
|
|
</ul>
|
|
|
|
</div>
|
2023-05-14 10:41:08 -05:00
|
|
|
</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-11-29 14:17:51 -06:00
|
|
|
<SortDropdown sortBy={sortBy} setSort={setSortBy} />
|
2023-04-30 15:54:40 -05:00
|
|
|
</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-11-29 08:41:24 -06:00
|
|
|
className="card card-compact shadow-md hover:shadow-none duration-200 border border-neutral-content p-5 bg-base-200 self-stretch min-h-[12rem] rounded-2xl cursor-pointer flex flex-col gap-4 justify-center items-center group btn"
|
2023-11-28 23:46:31 -06:00
|
|
|
onClick={() => setNewModalIsOpen(true)}
|
2023-04-30 15:54:40 -05:00
|
|
|
>
|
2023-11-24 07:39:55 -06:00
|
|
|
<p className="group-hover:opacity-0 duration-100">New Collection</p>
|
2023-05-25 09:17:20 -05:00
|
|
|
<FontAwesomeIcon
|
|
|
|
icon={faPlus}
|
2023-11-24 08:39:38 -06:00
|
|
|
className="w-8 h-8 text-primary 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}
|
2023-11-24 08:39:38 -06:00
|
|
|
className="sm:w-10 sm:h-10 w-6 h-6 text-primary drop-shadow"
|
2023-10-24 16:03:33 -05:00
|
|
|
/>
|
|
|
|
<div>
|
2023-11-24 07:39:55 -06:00
|
|
|
<p className="text-3xl capitalize font-thin">
|
2023-10-24 16:03:33 -05:00
|
|
|
Other Collections
|
|
|
|
</p>
|
|
|
|
|
2023-11-24 07:39:55 -06:00
|
|
|
<p>Shared collections you're a member of</p>
|
2023-10-24 16:03:33 -05:00
|
|
|
</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-11-29 08:41:24 -06:00
|
|
|
<NewCollectionModal
|
2023-11-28 23:46:31 -06:00
|
|
|
isOpen={newModalIsOpen}
|
|
|
|
onClose={closeNewModal}
|
2023-11-29 08:41:24 -06:00
|
|
|
modalId="new-collection-modal-1"
|
2023-11-28 23:46:31 -06:00
|
|
|
/>
|
2023-05-14 10:41:08 -05:00
|
|
|
</MainLayout>
|
2023-02-24 11:32:28 -06:00
|
|
|
);
|
|
|
|
}
|