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

136 lines
4.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 {
faBox,
faEllipsis,
faPlus,
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";
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";
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";
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 [sortDropdown, setSortDropdown] = useState(false);
const [sortBy, setSortBy] = useState<Sort>(Sort.DateNewestFirst);
const [sortedCollections, setSortedCollections] = useState(collections);
2023-04-23 08:26:39 -05:00
2023-05-26 23:29:45 -05:00
const session = useSession();
2023-06-12 23:46:32 -05:00
const { setModal } = useModalStore();
2023-06-13 23:40:23 -05:00
useSort({ sortBy, setData: setSortedCollections, data: collections });
return (
<MainLayout>
2023-04-30 15:54:40 -05:00
<div className="p-5">
<div className="flex gap-3 items-center justify-between mb-5">
2023-05-31 21:43:42 -05:00
<div className="flex gap-3 items-end">
<div className="flex gap-2">
<FontAwesomeIcon
icon={faBox}
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-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">
All Collections
</p>
</div>
<div className="relative">
<div
onClick={() => setExpandDropdown(!expandDropdown)}
2023-05-27 22:21:35 -05:00
id="expand-dropdown"
2023-05-31 13:33:01 -05:00
className="inline-flex rounded-md cursor-pointer hover:bg-slate-200 duration-100 p-1"
>
<FontAwesomeIcon
icon={faEllipsis}
2023-05-27 22:21:35 -05:00
id="expand-dropdown"
className="w-5 h-5 text-gray-500"
/>
</div>
{expandDropdown ? (
<Dropdown
items={[
{
2023-05-27 22:21:35 -05:00
name: "New Collection",
onClick: () => {
2023-06-12 23:46:32 -05:00
setModal({
modal: "COLLECTION",
state: true,
method: "CREATE",
});
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);
}}
className="absolute top-8 left-0 w-36"
/>
) : null}
</div>
2023-03-28 02:31:50 -05:00
</div>
2023-04-30 15:54:40 -05:00
<div className="relative">
<div
onClick={() => setSortDropdown(!sortDropdown)}
id="sort-dropdown"
2023-05-31 13:33:01 -05:00
className="inline-flex rounded-md cursor-pointer hover:bg-slate-200 duration-100 p-1"
2023-04-30 15:54:40 -05:00
>
<FontAwesomeIcon
icon={faSort}
id="sort-dropdown"
2023-05-01 15:00:23 -05:00
className="w-5 h-5 text-gray-500"
2023-04-30 15:54:40 -05:00
/>
</div>
{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-06-12 13:23:11 -05:00
<div className="grid 2xl:grid-cols-4 xl:grid-cols-3 sm:grid-cols-2 grid-cols-1 gap-5">
{sortedCollections.map((e, i) => {
2023-04-30 15:54:40 -05:00
return <CollectionCard key={i} collection={e} />;
})}
2023-04-23 08:26:39 -05:00
2023-04-30 15:54:40 -05:00
<div
2023-05-31 13:33:01 -05:00
className="p-5 self-stretch bg-gradient-to-tr from-sky-100 from-10% via-gray-100 via-20% 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-05-25 09:17:20 -05:00
<p className="text-sky-900 group-hover:opacity-0 duration-100">
New Collection
</p>
<FontAwesomeIcon
icon={faPlus}
className="w-8 h-8 text-sky-500 group-hover:w-12 group-hover:h-12 group-hover:-mt-10 duration-100"
/>
2023-04-30 15:54:40 -05:00
</div>
2023-04-25 07:39:46 -05:00
</div>
2023-03-28 02:31:50 -05:00
</div>
</MainLayout>
);
}