From 686875e203c9e55c3a32948f33c06c61496612a6 Mon Sep 17 00:00:00 2001 From: smolgrrr Date: Fri, 27 Oct 2023 23:53:36 +1100 Subject: [PATCH] fix key prop stuff --- client/src/components/Modals/LinkPreview.tsx | 5 +---- client/src/components/Modals/TextModal.tsx | 12 ++++++------ client/src/components/Thread/OPCard.tsx | 18 ++---------------- client/src/components/Thread/ReplyCard.tsx | 3 ++- 4 files changed, 11 insertions(+), 27 deletions(-) diff --git a/client/src/components/Modals/LinkPreview.tsx b/client/src/components/Modals/LinkPreview.tsx index b6aab13..e334557 100644 --- a/client/src/components/Modals/LinkPreview.tsx +++ b/client/src/components/Modals/LinkPreview.tsx @@ -2,17 +2,14 @@ import { getLinkPreview } from 'link-preview-js'; import { useState, useEffect } from 'react'; -const LinkModal = ({ key, url }: { key: string, url: string}) => { +const LinkModal = ({ url }: { url: string}) => { const [linkPreview, setLinkPreview] = useState(null); useEffect(() => { - const fetchLinkPreview = async () => { getLinkPreview(url) .then((preview) => setLinkPreview(preview as LinkPreview)) .catch((error) => console.error(error)); - }; - fetchLinkPreview(); }, [url]); if (!linkPreview) { diff --git a/client/src/components/Modals/TextModal.tsx b/client/src/components/Modals/TextModal.tsx index 1ed91c9..3d2efd5 100644 --- a/client/src/components/Modals/TextModal.tsx +++ b/client/src/components/Modals/TextModal.tsx @@ -20,10 +20,10 @@ const ContentPreview = ({ key, comment }: { key: string, comment: string }) => { }; useEffect(() => { - const urls = comment.match(/\bhttps?:\/\/\S+/gi); - if (urls && urls.length > 0) { - setUrl(url) - setFinalComment(finalComment.replace(url, '').trim()) + const findUrl = comment.match(/\bhttps?:\/\/\S+/gi); + if (findUrl && findUrl.length > 0) { + setUrl(findUrl[0]) + // setFinalComment(finalComment.replace(findUrl[0], '').trim()) } const match = comment.match(/\bnostr:([a-z0-9]+)/i); @@ -47,7 +47,7 @@ const ContentPreview = ({ key, comment }: { key: string, comment: string }) => {
{isExpanded ? finalComment : finalComment.slice(0, 240)} {finalComment.length > 240 && ( - )} @@ -55,7 +55,7 @@ const ContentPreview = ({ key, comment }: { key: string, comment: string }) => { )} {quoteEvents[0] && quoteEvents.length > 0 && ( - + )}
); diff --git a/client/src/components/Thread/OPCard.tsx b/client/src/components/Thread/OPCard.tsx index 5ec6cc7..af75249 100644 --- a/client/src/components/Thread/OPCard.tsx +++ b/client/src/components/Thread/OPCard.tsx @@ -7,6 +7,7 @@ import { useEffect, useState } from 'react'; import { subNote } from '../../utils/subscriptions'; import { getMetadata, uniqBy } from '../../utils/utils'; import { getLinkPreview } from 'link-preview-js'; +import ContentPreview from '../Modals/TextModal'; const colorCombos = [ 'from-red-400 to-yellow-500', @@ -105,22 +106,7 @@ const OPCard = ({ event, metadata, replyCount }: { event: Event, metadata: Event
- {isExpanded ? comment : truncatedComment} - {comment.length > 240 && ( - - )} - {linkPreview && linkPreview.images && linkPreview.images.length > 0 && ( -
- - {linkPreview.title} -
- {linkPreview.title} -
-
-
- )} +
{file !== "" && (
diff --git a/client/src/components/Thread/ReplyCard.tsx b/client/src/components/Thread/ReplyCard.tsx index ca952d6..6361a8a 100644 --- a/client/src/components/Thread/ReplyCard.tsx +++ b/client/src/components/Thread/ReplyCard.tsx @@ -6,6 +6,7 @@ import { nip19 } from 'nostr-tools'; import { useEffect, useState } from 'react'; import { subNote } from '../../utils/subscriptions'; import { getMetadata, uniqBy } from '../../utils/utils'; +import ContentPreview from '../Modals/TextModal'; const colorCombos = [ 'from-red-400 to-yellow-500', @@ -106,7 +107,7 @@ const ReplyCard = ({ event, metadata, replyCount, repliedTo }: { event: Event, m ))}
- {comment} +
{file !== "" && (