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

139 lines
4.9 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,
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";
2023-10-09 07:35:33 -05:00
import { useTheme } from "next-themes";
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);
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
2023-07-13 17:19:49 -05:00
icon={faFolder}
2023-08-30 23:17:27 -05:00
className="sm:w-8 sm:h-8 w-6 h-6 mt-2 text-sky-500 dark:text-sky-500 drop-shadow"
2023-05-31 21:43:42 -05:00
/>
2023-08-14 22:25:25 -05:00
<p className="sm:text-4xl text-3xl capitalize text-black dark:text-white">
2023-05-31 21:43:42 -05:00
All Collections
</p>
</div>
<div className="relative">
<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"
>
<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"
/>
</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-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
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>
{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-07-18 11:28:58 -05:00
<div className="grid 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-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-03-28 02:31:50 -05:00
</div>
</MainLayout>
);
}