diff --git a/components/CollectionCard.tsx b/components/CollectionCard.tsx index 506445e..a85a7ee 100644 --- a/components/CollectionCard.tsx +++ b/components/CollectionCard.tsx @@ -18,12 +18,17 @@ export default function ({ collection }: { collection: Collection }) { return (
-
-

{collection.name}

- +
+
+

{collection.name}

+ +
+

+ {collection.description} +

{formattedDate}

diff --git a/components/Modal/AddCollection.tsx b/components/Modal/AddCollection.tsx index 04d207a..d2674b7 100644 --- a/components/Modal/AddCollection.tsx +++ b/components/Modal/AddCollection.tsx @@ -42,7 +42,7 @@ export default function AddCollection({ toggleCollectionModal }: Props) { } type="text" placeholder="e.g. Example Collection" - className="w-96 rounded-md p-3 border-sky-100 border-solid border text-sm outline-none focus:border-sky-500 duration-100" + className="w-56 sm:w-96 rounded-md p-3 border-sky-100 border-solid border text-sm outline-none focus:border-sky-500 duration-100" />
@@ -55,7 +55,7 @@ export default function AddCollection({ toggleCollectionModal }: Props) { } type="text" placeholder="Collection description (Optional)" - className="w-96 rounded-md p-3 border-sky-100 border-solid border text-sm outline-none focus:border-sky-500 duration-100" + className="w-56 sm:w-96 rounded-md p-3 border-sky-100 border-solid border text-sm outline-none focus:border-sky-500 duration-100" /> diff --git a/lib/api/controllers/collections/postCollection.ts b/lib/api/controllers/collections/postCollection.ts index 2a26b72..569d223 100644 --- a/lib/api/controllers/collections/postCollection.ts +++ b/lib/api/controllers/collections/postCollection.ts @@ -8,7 +8,7 @@ import { Collection } from "@prisma/client"; import { existsSync, mkdirSync } from "fs"; export default async function (collection: Collection, userId: number) { - if (!collection) + if (!collection || collection.name.trim() === "") return { response: "Please enter a valid collection.", status: 400, diff --git a/pages/collections/[id].tsx b/pages/collections/[id].tsx index 84aea87..748a427 100644 --- a/pages/collections/[id].tsx +++ b/pages/collections/[id].tsx @@ -5,6 +5,8 @@ import Dropdown from "@/components/Dropdown"; import LinkList from "@/components/LinkList"; +import Modal from "@/components/Modal"; +import AddLink from "@/components/Modal/AddLink"; import useCollectionStore from "@/store/collections"; import useLinkStore from "@/store/links"; import { ExtendedLink } from "@/types/global"; @@ -27,10 +29,15 @@ export default function () { const { collections } = useCollectionStore(); const [expandDropdown, setExpandDropdown] = useState(false); + const [linkModal, setLinkModal] = useState(false); const [activeCollection, setActiveCollection] = useState(); const [linksByCollection, setLinksByCollection] = useState(links); + const toggleLinkModal = () => { + setLinkModal(!linkModal); + }; + useEffect(() => { setLinksByCollection( links.filter((e) => e.collection.id === Number(router.query.id)) @@ -67,6 +74,10 @@ export default function () { { name: "Add Link Here", icon: , + onClick: () => { + toggleLinkModal(); + setExpandDropdown(false); + }, }, { name: "Edit Collection", @@ -84,6 +95,12 @@ export default function () { className="absolute top-7 left-0 z-10 w-44" /> ) : null} + + {linkModal ? ( + + + + ) : null} {linksByCollection.map((e, i) => { diff --git a/pages/collections/index.tsx b/pages/collections/index.tsx index f6e8bf8..15b9f2b 100644 --- a/pages/collections/index.tsx +++ b/pages/collections/index.tsx @@ -4,7 +4,12 @@ // You should have received a copy of the GNU General Public License along with this program. If not, see . import useCollectionStore from "@/store/collections"; -import { faAdd, faBox, faEllipsis } from "@fortawesome/free-solid-svg-icons"; +import { + faAdd, + faBox, + faEllipsis, + faPlus, +} from "@fortawesome/free-solid-svg-icons"; import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; import CollectionCard from "@/components/CollectionCard"; import Dropdown from "@/components/Dropdown"; @@ -18,7 +23,7 @@ export default function () { const [linkModal, setLinkModal] = useState(false); - const toggleLinkModal = () => { + const toggleCollectionModal = () => { setLinkModal(!linkModal); }; @@ -49,7 +54,7 @@ export default function () { name: "New", icon: , onClick: () => { - toggleLinkModal(); + toggleCollectionModal(); setExpandDropdown(false); }, }, @@ -64,8 +69,8 @@ export default function () { {linkModal ? ( - - + + ) : null} @@ -73,6 +78,14 @@ export default function () { {collections.map((e, i) => { return ; })} + +
+

New Collection

+ +
); diff --git a/store/collections.ts b/store/collections.ts index a629aa8..bcf4639 100644 --- a/store/collections.ts +++ b/store/collections.ts @@ -35,6 +35,8 @@ const useCollectionStore = create()((set) => ({ const data = await response.json(); + console.log(data); + if (response.ok) set((state) => ({ collections: [...state.collections, data.response],