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

115 lines
4.4 KiB
TypeScript
Raw Normal View History

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";
2023-12-16 09:33:33 -06:00
import PageHeader from "@/components/PageHeader";
import getServerSideProps from "@/lib/client/getServerSideProps";
import { useTranslation } from "next-i18next";
2024-07-30 13:57:09 -05:00
import { useCollections } from "@/hooks/store/collections";
2024-08-22 17:09:14 -05:00
import { dropdownTriggerer } from "@/lib/client/utils";
export default function Collections() {
const { t } = useTranslation();
const { data: collections = [] } = useCollections();
const [sortBy, setSortBy] = useState<Sort>(
Number(localStorage.getItem("sortBy")) ?? 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-12-16 09:33:33 -06:00
<div className="p-5 flex flex-col gap-5 w-full h-full">
2023-12-17 22:32:33 -06:00
<div className="flex justify-between">
2024-08-22 17:09:14 -05:00
<div className="flex items-center gap-3">
<PageHeader
icon={"bi-folder"}
title={t("collections")}
description={t("collections_you_own")}
/>
<div className="relative">
<div className={"dropdown dropdown-bottom font-normal"}>
<div
tabIndex={0}
role="button"
onMouseDown={dropdownTriggerer}
className="btn btn-ghost btn-sm btn-square text-neutral"
>
<i className={"bi-three-dots text-neutral text-2xl"}></i>
</div>
<ul className="dropdown-content z-[30] menu shadow bg-base-200 border border-neutral-content rounded-box mt-1">
<li>
<div
role="button"
tabIndex={0}
onClick={() => setNewCollectionModal(true)}
className="whitespace-nowrap"
>
{t("new_collection")}
</div>
</li>
</ul>
</div>
</div>
</div>
2023-12-17 22:32:33 -06:00
<div className="flex gap-3 justify-end">
<div className="relative mt-2">
<SortDropdown sortBy={sortBy} setSort={setSortBy} t={t} />
2023-12-17 22:32:33 -06:00
</div>
2023-04-30 15:54:40 -05:00
</div>
2023-03-28 02:31:50 -05:00
</div>
2023-12-23 11:11:47 -06:00
<div className="grid min-[1900px]:grid-cols-4 2xl:grid-cols-3 sm:grid-cols-2 grid-cols-1 gap-5">
2023-10-24 16:03:33 -05:00
{sortedCollections
2024-02-06 06:44:08 -06:00
.filter((e) => e.ownerId === data?.user.id && e.parentId === null)
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
>
<p className="group-hover:opacity-0 duration-100">
{t("new_collection")}
</p>
2023-12-17 22:32:33 -06:00
<i className="bi-plus-lg text-5xl group-hover:text-7xl group-hover:-mt-6 text-primary drop-shadow duration-100"></i>
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] && (
2023-10-24 16:03:33 -05:00
<>
<PageHeader
icon={"bi-folder"}
title={t("other_collections")}
description={t("other_collections_desc")}
/>
2023-10-24 16:03:33 -05:00
2023-12-23 11:11:47 -06:00
<div className="grid min-[1900px]:grid-cols-4 2xl:grid-cols-3 sm:grid-cols-2 grid-cols-1 gap-5">
2023-10-24 16:03:33 -05:00
{sortedCollections
.filter((e) => e.ownerId !== data?.user.id)
.map((e, i) => {
return <CollectionCard key={i} collection={e} />;
})}
</div>
</>
)}
2023-03-28 02:31:50 -05:00
</div>
{newCollectionModal && (
2023-12-01 16:42:45 -06:00
<NewCollectionModal onClose={() => setNewCollectionModal(false)} />
)}
</MainLayout>
);
}
export { getServerSideProps };