From cbf53f6e3075ef95e787075ac9e1a6a316950c61 Mon Sep 17 00:00:00 2001 From: Daniel Date: Mon, 24 Jul 2023 09:39:51 -0400 Subject: [PATCH] improvements + better error handling --- components/LinkCard.tsx | 20 +++++++++++-- components/Modal/Link/AddOrEditLink.tsx | 37 ++++++++++++------------- lib/api/controllers/links/postLink.ts | 20 +++++++++---- lib/api/getTitle.ts | 2 +- 4 files changed, 51 insertions(+), 28 deletions(-) diff --git a/components/LinkCard.tsx b/components/LinkCard.tsx index 873966f..2dd2b47 100644 --- a/components/LinkCard.tsx +++ b/components/LinkCard.tsx @@ -2,7 +2,11 @@ import { CollectionIncludingMembersAndLinkCount, LinkIncludingShortenedCollectionAndTags, } from "@/types/global"; -import { faFolder, faEllipsis } from "@fortawesome/free-solid-svg-icons"; +import { + faFolder, + faEllipsis, + faLink, +} from "@fortawesome/free-solid-svg-icons"; import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; import { useEffect, useState } from "react"; import Image from "next/image"; @@ -33,6 +37,14 @@ export default function LinkCard({ link, count, className }: Props) { const { account } = useAccountStore(); + let shortendURL; + + try { + shortendURL = new URL(link.url).host.toLowerCase(); + } catch (error) { + console.log(error); + } + const [collection, setCollection] = useState( collections.find( @@ -144,7 +156,7 @@ export default function LinkCard({ link, count, className }: Props) {

{count + 1}.

- {link.name} + {link.name || link.description}

@@ -159,6 +171,10 @@ export default function LinkCard({ link, count, className }: Props) {

+
+ +

{shortendURL}

+

{formattedDate}

diff --git a/components/Modal/Link/AddOrEditLink.tsx b/components/Modal/Link/AddOrEditLink.tsx index f1d2f85..205513c 100644 --- a/components/Modal/Link/AddOrEditLink.tsx +++ b/components/Modal/Link/AddOrEditLink.tsx @@ -11,6 +11,7 @@ import useCollectionStore from "@/store/collections"; import { useRouter } from "next/router"; import SubmitButton from "../../SubmitButton"; import { toast } from "react-hot-toast"; +import Link from "next/link"; type Props = | { @@ -70,8 +71,6 @@ export default function AddOrEditLink({ } }, []); - // const shortendURL = method === "UPDATE" ? new URL(link.url).host.toLowerCase() : undefined; - const setTags = (e: any) => { const tagNames = e.map((e: any) => { return { name: e.label }; @@ -119,27 +118,15 @@ export default function AddOrEditLink({ className="text-gray-500 my-2 text-center truncate w-full" title={link.url} > - Edit {link.url} + + {link.url} +

) : null}
-
-

- Name - -

- setLink({ ...link, name: e.target.value })} - type="text" - placeholder="e.g. Example Link" - className="w-full rounded-md p-2 border-sky-100 border-solid border outline-none focus:border-sky-700 duration-100" - /> -
- {method === "CREATE" ? ( -
+

URL @@ -173,7 +160,7 @@ export default function AddOrEditLink({ />

-
+

Tags

+ +
+

Name

+ setLink({ ...link, name: e.target.value })} + type="text" + placeholder="e.g. Example Link" + className="w-full rounded-md p-2 border-sky-100 border-solid border outline-none focus:border-sky-700 duration-100" + /> +
+

Description