el.xwx.moe/pages/collections/index.tsx

105 lines
3.7 KiB
TypeScript
Raw Normal View History

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";
import CollectionCard from "@/components/CollectionCard";
2023-06-13 23:40:23 -05:00
import { useState } from "react";
import MainLayout from "@/layouts/MainLayout";
2023-05-26 23:29:45 -05:00
import { useSession } from "next-auth/react";
2023-06-13 23:40:23 -05:00
import SortDropdown from "@/components/SortDropdown";
import { Sort } from "@/types/global";
import useSort from "@/hooks/useSort";
2023-12-01 16:44:34 -06:00
import NewCollectionModal from "@/components/ModalContent/NewCollectionModal";
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);
const [sortBy, setSortBy] = useState<Sort>(Sort.DateNewestFirst);
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-13 23:40:23 -05:00
useSort({ sortBy, setData: setSortedCollections, data: collections });
const [newCollectionModal, setNewCollectionModal] = useState(false);
2023-11-28 23:46:31 -06:00
return (
<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}
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>
</div>
2023-03-28 02:31:50 -05:00
</div>
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-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"
onClick={() => setNewCollectionModal(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}
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}
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&apos;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-12-01 16:42:45 -06:00
{newCollectionModal ? (
<NewCollectionModal onClose={() => setNewCollectionModal(false)} />
) : undefined}
</MainLayout>
);
}