much improved collections listing page

This commit is contained in:
Daniel
2023-05-25 22:14:08 +03:30
parent 0f5f93eaff
commit 824f7c2789
6 changed files with 287 additions and 170 deletions
+89 -17
View File
@@ -4,11 +4,21 @@
// You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import { faChevronRight, faUser } from "@fortawesome/free-solid-svg-icons";
import {
faUser,
faPenToSquare,
faTrashCan,
faEllipsis,
} from "@fortawesome/free-solid-svg-icons";
import Link from "next/link";
import { ExtendedCollection } from "@/types/global";
import useLinkStore from "@/store/links";
import ImageWithFallback from "./ImageWithFallback";
import Dropdown from "./Dropdown";
import { useState } from "react";
import Modal from "@/components/Modal";
import EditCollection from "@/components/Modal/EditCollection";
import DeleteCollection from "@/components/Modal/DeleteCollection";
export default function ({ collection }: { collection: ExtendedCollection }) {
const { links } = useLinkStore();
@@ -18,25 +28,42 @@ export default function ({ collection }: { collection: ExtendedCollection }) {
day: "numeric",
});
const [expandDropdown, setExpandDropdown] = useState(false);
const [editCollectionModal, setEditCollectionModal] = useState(false);
const [deleteCollectionModal, setDeleteCollectionModal] = useState(false);
const toggleEditCollectionModal = () => {
setEditCollectionModal(!editCollectionModal);
};
const toggleDeleteCollectionModal = () => {
setDeleteCollectionModal(!deleteCollectionModal);
};
return (
<div className="p-5 bg-gradient-to-tr from-sky-100 from-10% via-gray-100 via-20% self-stretch min-h-[12rem] rounded-md cursor-pointer shadow duration-100 hover:shadow-none group">
<div className="p-5 bg-gradient-to-tr from-sky-100 from-10% via-gray-100 via-20% self-stretch min-h-[12rem] rounded-md cursor-pointer shadow duration-100 hover:shadow-none group relative">
<div
onClick={() => setExpandDropdown(!expandDropdown)}
id="edit-dropdown"
className="inline-flex absolute top-5 right-5 rounded-md cursor-pointer hover:bg-white hover:border-sky-500 border-sky-100 border duration-100 p-1"
>
<FontAwesomeIcon
icon={faEllipsis}
id="edit-dropdown"
className="w-5 h-5 text-gray-500"
/>
</div>
<Link href={`/collections/${collection.id}`}>
<div className="flex flex-col gap-2 justify-between h-full">
<div className="flex flex-col gap-2 justify-between h-full select-none">
<div>
<div className="flex justify-between text-sky-600 items-center mb-2">
<p className="text-2xl w-max font-bold capitalize">
{collection.name}
</p>
<FontAwesomeIcon
icon={faChevronRight}
className="w-3 h-3 group-hover:w-5 group-hover:h-5 duration-100 text-gray-500"
/>
</div>
<p className="text-gray-500">{collection.description}</p>
<p className="text-2xl w-max font-bold capitalize text-sky-600">
{collection.name}
</p>
</div>
<div className="flex justify-between items-center">
<div className="text-sky-400 flex items-center w-full">
{collection.members
.sort((a, b) => a.userId - b.userId)
.map((e, i) => {
return (
<ImageWithFallback
@@ -50,15 +77,14 @@ export default function ({ collection }: { collection: ExtendedCollection }) {
</ImageWithFallback>
);
})
.reverse()
.slice(0, 3)}
{collection.members.length - 3 > 0 ? (
.slice(0, 4)}
{collection.members.length - 4 > 0 ? (
<div className="h-10 w-10 text-white flex items-center justify-center rounded-full border-[3px] bg-sky-500 border-sky-100 -mr-3">
+{collection.members.length - 3}
</div>
) : null}
</div>
<div className="text-right w-full">
<div className="text-right w-40">
<p className="text-sky-500 font-bold text-sm">
{links.filter((e) => e.collectionId === collection.id).length}{" "}
Links
@@ -68,6 +94,52 @@ export default function ({ collection }: { collection: ExtendedCollection }) {
</div>
</div>
</Link>
{expandDropdown ? (
<Dropdown
items={[
{
name: "Edit Collection",
icon: <FontAwesomeIcon icon={faPenToSquare} />,
onClick: () => {
toggleEditCollectionModal();
setExpandDropdown(false);
},
},
{
name: "Delete Collection",
icon: <FontAwesomeIcon icon={faTrashCan} />,
onClick: () => {
toggleDeleteCollectionModal();
setExpandDropdown(false);
},
},
]}
onClickOutside={(e: Event) => {
const target = e.target as HTMLInputElement;
if (target.id !== "edit-dropdown") setExpandDropdown(false);
}}
className="absolute top-[3.2rem] right-5 z-10 w-44"
/>
) : null}
{editCollectionModal ? (
<Modal toggleModal={toggleEditCollectionModal}>
<EditCollection
toggleCollectionModal={toggleEditCollectionModal}
collection={collection}
/>
</Modal>
) : null}
{deleteCollectionModal ? (
<Modal toggleModal={toggleDeleteCollectionModal}>
<DeleteCollection
collection={collection}
toggleDeleteCollectionModal={toggleDeleteCollectionModal}
/>
</Modal>
) : null}
</div>
);
}