From 824f7c27898d5a90bd9fa007593f2a38bd3f1197 Mon Sep 17 00:00:00 2001 From: Daniel Date: Thu, 25 May 2023 22:14:08 +0330 Subject: [PATCH] much improved collections listing page --- components/CollectionCard.tsx | 106 ++++++++++-- components/LinkList.tsx | 4 +- components/Navbar.tsx | 2 +- components/Sidebar/index.tsx | 24 +-- pages/collections/[id].tsx | 317 +++++++++++++++++++--------------- store/collections.ts | 4 +- 6 files changed, 287 insertions(+), 170 deletions(-) diff --git a/components/CollectionCard.tsx b/components/CollectionCard.tsx index 9d871f2..05cefc1 100644 --- a/components/CollectionCard.tsx +++ b/components/CollectionCard.tsx @@ -4,11 +4,21 @@ // You should have received a copy of the GNU General Public License along with this program. If not, see . 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 ( -
+
+
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" + > + +
-
+
-
-

- {collection.name} -

- -
-

{collection.description}

+

+ {collection.name} +

{collection.members + .sort((a, b) => a.userId - b.userId) .map((e, i) => { return ( ); }) - .reverse() - .slice(0, 3)} - {collection.members.length - 3 > 0 ? ( + .slice(0, 4)} + {collection.members.length - 4 > 0 ? (
+{collection.members.length - 3}
) : null}
-
+

{links.filter((e) => e.collectionId === collection.id).length}{" "} Links @@ -68,6 +94,52 @@ export default function ({ collection }: { collection: ExtendedCollection }) {

+ + {expandDropdown ? ( + , + onClick: () => { + toggleEditCollectionModal(); + setExpandDropdown(false); + }, + }, + { + name: "Delete Collection", + icon: , + 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 ? ( + + + + ) : null} + + {deleteCollectionModal ? ( + + + + ) : null}
); } diff --git a/components/LinkList.tsx b/components/LinkList.tsx index 6ec06f1..3c649fa 100644 --- a/components/LinkList.tsx +++ b/components/LinkList.tsx @@ -45,7 +45,7 @@ export default function ({ }; return ( -
+
{editModal ? ( @@ -124,7 +124,7 @@ export default function ({
diff --git a/components/Navbar.tsx b/components/Navbar.tsx index 9542a52..39efd3c 100644 --- a/components/Navbar.tsx +++ b/components/Navbar.tsx @@ -66,7 +66,7 @@ export default function () {
New Link diff --git a/components/Sidebar/index.tsx b/components/Sidebar/index.tsx index 4851204..b392a95 100644 --- a/components/Sidebar/index.tsx +++ b/components/Sidebar/index.tsx @@ -112,17 +112,19 @@ export default function ({ className }: { className?: string }) {

Collections

- {collections.map((e, i) => { - return ( - } - path={`/collections/${e.id}`} - className="capitalize" - /> - ); - })} + {collections + .sort((a, b) => a.name.localeCompare(b.name)) + .map((e, i) => { + return ( + } + path={`/collections/${e.id}`} + className="capitalize" + /> + ); + })}

Tags

diff --git a/pages/collections/[id].tsx b/pages/collections/[id].tsx index 9c10006..2b29068 100644 --- a/pages/collections/[id].tsx +++ b/pages/collections/[id].tsx @@ -19,6 +19,7 @@ import { faPenToSquare, faSort, faTrashCan, + faUser, } from "@fortawesome/free-solid-svg-icons"; import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; import { useRouter } from "next/router"; @@ -26,6 +27,7 @@ import { ChangeEvent, useEffect, useState } from "react"; import MainLayout from "@/layouts/MainLayout"; import RadioButton from "@/components/RadioButton"; import ClickAwayHandler from "@/components/ClickAwayHandler"; +import ImageWithFallback from "@/components/ImageWithFallback"; export default function () { const router = useRouter(); @@ -99,152 +101,193 @@ export default function () { return (
-
-
-
- -

{activeCollection?.name}

-
-
-
setExpandDropdown(!expandDropdown)} - id="edit-dropdown" - className="inline-flex rounded-md cursor-pointer hover:bg-white hover:border-sky-500 border-sky-100 border duration-100 p-1" - > +
+
+
+
+

+ {activeCollection?.name} +

- {expandDropdown ? ( - , - onClick: () => { - toggleLinkModal(); - setExpandDropdown(false); - }, - }, - { - name: "Edit Collection", - icon: , - onClick: () => { - toggleEditCollectionModal(); - setExpandDropdown(false); - }, - }, - { - name: "Delete Collection", - icon: , - onClick: () => { - toggleDeleteCollectionModal(); - setExpandDropdown(false); - }, - }, - ]} - onClickOutside={(e: Event) => { - const target = e.target as HTMLInputElement; - if (target.id !== "edit-dropdown") setExpandDropdown(false); - }} - className="absolute top-8 left-0 z-10 w-44" - /> - ) : null} +
- {linkModal ? ( - - - - ) : null} - - {editCollectionModal && activeCollection ? ( - - - - ) : null} - - {deleteCollectionModal && activeCollection ? ( - - - - ) : null} +
+
+
+ View Team +
+ {activeCollection?.members + .sort((a, b) => a.userId - b.userId) + .map((e, i) => { + return ( + +
+ +
+
+ ); + }) + .slice(0, 4)} + {activeCollection?.members.length && + activeCollection.members.length - 4 > 0 ? ( +
+ +{activeCollection?.members?.length - 3} +
+ ) : null} +
-
-
setSortDropdown(!sortDropdown)} - id="sort-dropdown" - className="inline-flex rounded-md cursor-pointer hover:bg-white hover:border-sky-500 border-sky-100 border duration-100 p-1" - > - -
- - {sortDropdown ? ( - { - const target = e.target as HTMLInputElement; - if (target.id !== "sort-dropdown") setSortDropdown(false); - }} - className="absolute top-8 right-0 shadow-md bg-gray-50 rounded-md p-2 z-10 border border-sky-100 w-48" - > -

- Sort by -

-
- - - - - - - - - - - +

{activeCollection?.description}

+
+
+
setSortDropdown(!sortDropdown)} + id="sort-dropdown" + className="inline-flex rounded-md cursor-pointer hover:bg-white hover:border-sky-500 border-sky-100 border duration-100 p-1" + > +
- - ) : null} + + {sortDropdown ? ( + { + const target = e.target as HTMLInputElement; + if (target.id !== "sort-dropdown") setSortDropdown(false); + }} + className="absolute top-8 right-0 shadow-md bg-gray-50 rounded-md p-2 z-10 border border-sky-100 w-48" + > +

+ Sort by +

+
+ + + + + + + + + + + +
+
+ ) : null} +
+
+
setExpandDropdown(!expandDropdown)} + id="edit-dropdown" + className="inline-flex rounded-md cursor-pointer hover:bg-white hover:border-sky-500 border-sky-100 border duration-100 p-1" + > + +
+ {expandDropdown ? ( + , + onClick: () => { + toggleLinkModal(); + setExpandDropdown(false); + }, + }, + { + name: "Edit Collection", + icon: , + onClick: () => { + toggleEditCollectionModal(); + setExpandDropdown(false); + }, + }, + { + name: "Delete Collection", + icon: , + onClick: () => { + toggleDeleteCollectionModal(); + setExpandDropdown(false); + }, + }, + ]} + onClickOutside={(e: Event) => { + const target = e.target as HTMLInputElement; + if (target.id !== "edit-dropdown") + setExpandDropdown(false); + }} + className="absolute top-8 right-0 z-10 w-44" + /> + ) : null} + + {linkModal ? ( + + + + ) : null} + + {editCollectionModal && activeCollection ? ( + + + + ) : null} + + {deleteCollectionModal && activeCollection ? ( + + + + ) : null} +
+
diff --git a/store/collections.ts b/store/collections.ts index 67fb8e4..6a2f9e2 100644 --- a/store/collections.ts +++ b/store/collections.ts @@ -23,6 +23,8 @@ const useCollectionStore = create()((set) => ({ const data = await response.json(); + console.log(data); + if (response.ok) set({ collections: data.response }); }, addCollection: async (body) => { @@ -36,8 +38,6 @@ const useCollectionStore = create()((set) => ({ const data = await response.json(); - console.log(data); - if (response.ok) set((state) => ({ collections: [...state.collections, data.response],