diff --git a/components/LinkCard.tsx b/components/LinkCard.tsx index 873966f..1f5dcd4 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"; @@ -31,8 +35,18 @@ export default function LinkCard({ link, count, className }: Props) { const { collections } = useCollectionStore(); + const { links } = useLinkStore(); + const { account } = useAccountStore(); + let shortendURL; + + try { + shortendURL = new URL(link.url).host.toLowerCase(); + } catch (error) { + console.log(error); + } + const [collection, setCollection] = useState( collections.find( @@ -46,7 +60,7 @@ export default function LinkCard({ link, count, className }: Props) { (e) => e.id === link.collection.id ) as CollectionIncludingMembersAndLinkCount ); - }, [collections]); + }, [collections, links]); const { removeLink, updateLink } = useLinkStore(); @@ -144,7 +158,7 @@ export default function LinkCard({ link, count, className }: Props) {

{count + 1}.

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

@@ -159,6 +173,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..e072abd 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,41 +118,29 @@ export default function AddOrEditLink({ className="text-gray-500 my-2 text-center truncate w-full" title={link.url} > - Edit {link.url} + + {link.url} +

) : null} -
+ {method === "CREATE" ? (
-

- Name +

+ Address (URL)

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

- URL - -

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

Collection

-
+

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