From 1d1e0b7f43962dad9c577c9bad611cbcce669bb1 Mon Sep 17 00:00:00 2001 From: smolgrrr Date: Sat, 28 Oct 2023 00:26:17 +1100 Subject: [PATCH] clean up --- client/package.json | 5 -- client/src/App.test.tsx | 9 --- client/src/components/Home.tsx | 5 +- client/src/components/Modals/QuoteEmbed.tsx | 59 +------------------ client/src/components/Modals/TextModal.tsx | 7 +-- .../src/components/PostCard/NewThreadCard.tsx | 2 +- client/src/components/PostCard/PostCard.tsx | 4 +- client/src/components/Settings.tsx | 3 +- client/src/components/Thread/OPCard.tsx | 21 +------ client/src/components/Thread/ReplyCard.tsx | 2 - client/src/components/Thread/Thread.tsx | 5 +- client/src/components/Thread/ThreadPost.tsx | 2 +- client/src/index.tsx | 6 -- client/src/reportWebVitals.ts | 15 ----- client/src/utils/subscriptions.ts | 1 - 15 files changed, 13 insertions(+), 133 deletions(-) delete mode 100644 client/src/App.test.tsx delete mode 100644 client/src/reportWebVitals.ts diff --git a/client/package.json b/client/package.json index e5cb027..e4fc5df 100644 --- a/client/package.json +++ b/client/package.json @@ -4,9 +4,6 @@ "private": true, "dependencies": { "@heroicons/react": "^2.0.18", - "@testing-library/jest-dom": "^5.17.0", - "@testing-library/react": "^13.4.0", - "@testing-library/user-event": "^13.5.0", "@types/jest": "^27.5.2", "@types/node": "^17.0.45", "@types/react": "^18.2.21", @@ -17,10 +14,8 @@ "react": "^18.2.0", "react-dom": "^18.2.0", "react-linkify": "^1.0.0-alpha", - "react-pull-to-refresh": "^2.0.1", "react-router-dom": "^6.15.0", "react-scripts": "5.0.1", - "react-swipe": "^6.0.4", "react-swipeable-views": "^0.14.0", "web-vitals": "^2.1.4", "workbox-background-sync": "^6.6.0", diff --git a/client/src/App.test.tsx b/client/src/App.test.tsx deleted file mode 100644 index 2a68616..0000000 --- a/client/src/App.test.tsx +++ /dev/null @@ -1,9 +0,0 @@ -import React from 'react'; -import { render, screen } from '@testing-library/react'; -import App from './App'; - -test('renders learn react link', () => { - render(); - const linkElement = screen.getByText(/learn react/i); - expect(linkElement).toBeInTheDocument(); -}); diff --git a/client/src/components/Home.tsx b/client/src/components/Home.tsx index 46d6448..89547d2 100644 --- a/client/src/components/Home.tsx +++ b/client/src/components/Home.tsx @@ -1,8 +1,8 @@ -import React, { useEffect, useState } from 'react'; +import { useEffect, useState } from 'react'; import PostCard from './PostCard/PostCard'; import NewThreadCard from './PostCard/NewThreadCard'; import { getPow } from '../utils/mine'; -import { relayInit, Event } from 'nostr-tools'; +import { Event } from 'nostr-tools'; import { subGlobalFeed } from '../utils/subscriptions'; import { uniqBy } from '../utils/utils'; @@ -11,7 +11,6 @@ const Home = () => { const onEvent = (event: Event) => { setEvents((prevEvents) => [...prevEvents, event]); - console.log(`${event.id} ${event.kind} ${event.tags}`); }; useEffect(() => { diff --git a/client/src/components/Modals/QuoteEmbed.tsx b/client/src/components/Modals/QuoteEmbed.tsx index d47bea5..f0eac77 100644 --- a/client/src/components/Modals/QuoteEmbed.tsx +++ b/client/src/components/Modals/QuoteEmbed.tsx @@ -1,13 +1,7 @@ -import CardContainer from '../PostCard/CardContainer'; -import { FolderIcon } from '@heroicons/react/24/outline'; import { parseContent } from '../../utils/content'; import { Event } from 'nostr-tools'; -import { nip19 } from 'nostr-tools'; -import { useEffect, useState } from 'react'; -import { subNote } from '../../utils/subscriptions'; import { getMetadata, uniqBy } from '../../utils/utils'; -import { getLinkPreview } from 'link-preview-js'; -import { subNoteOnce } from '../../utils/subscriptions'; +import ContentPreview from './TextModal'; const colorCombos = [ 'from-red-400 to-yellow-500', @@ -58,29 +52,14 @@ const timeAgo = (unixTime: number) => { }; const QuoteEmbed = ({ event, metadata }: { event: Event, metadata: Event | null}) => { - // Replace 10 with the actual number of comments for each post - const numberOfComments = 10; const { comment, file } = parseContent(event); const colorCombo = getColorFromHash(event.pubkey, colorCombos); - const [isExpanded, setIsExpanded] = useState(false); - const truncatedComment = comment.slice(0, 240); let metadataParsed = null; if (metadata !== null) { metadataParsed = getMetadata(metadata); } - const [linkPreview, setLinkPreview] = useState(null); - - useEffect(() => { - const urls = comment.match(/\bhttps?:\/\/\S+/gi); - if (urls && urls.length > 0) { - getLinkPreview(urls[0]) - .then((preview) => setLinkPreview(preview as LinkPreview)) - .catch((error) => console.error(error)); - } - }, [comment]); - return (
@@ -100,22 +79,7 @@ const QuoteEmbed = ({ event, metadata }: { event: Event, metadata: Event | null}
- {isExpanded ? comment : truncatedComment} - {comment.length > 240 && ( - - )} - {linkPreview && linkPreview.images && linkPreview.images.length > 0 && ( -
- - {linkPreview.title} -
- {linkPreview.title} -
-
-
- )} +
{file !== "" && (
@@ -130,23 +94,4 @@ const QuoteEmbed = ({ event, metadata }: { event: Event, metadata: Event | null} ); }; -interface LinkPreview { - url: string; - title: string; - siteName?: string; - description?: string; - mediaType: string; - contentType?: string; - images: string[]; - videos: { - url?: string; - secureUrl?: string; - type?: string; - width?: string; - height?: string; - [key: string]: any; - }[]; - [key: string]: any; -} - export default QuoteEmbed; \ No newline at end of file diff --git a/client/src/components/Modals/TextModal.tsx b/client/src/components/Modals/TextModal.tsx index 3d2efd5..3fe93dd 100644 --- a/client/src/components/Modals/TextModal.tsx +++ b/client/src/components/Modals/TextModal.tsx @@ -1,8 +1,6 @@ import QuoteEmbed from "./QuoteEmbed"; -import { getLinkPreview } from 'link-preview-js'; import { Event } from 'nostr-tools'; import { useEffect, useState } from "react"; -import { getMetadata, uniqBy } from '../../utils/utils'; import { subNoteOnce } from '../../utils/subscriptions'; import { nip19 } from "nostr-tools"; import LinkModal from "./LinkPreview"; @@ -16,14 +14,13 @@ const ContentPreview = ({ key, comment }: { key: string, comment: string }) => { // Define your callback function for subGlobalFeed const onEvent = (event: Event, relay: string) => { setQuoteEvents((prevEvents) => [...prevEvents, event]); - console.log(event.id + ' ' + event.kind + ' ' + event.tags); }; useEffect(() => { const findUrl = comment.match(/\bhttps?:\/\/\S+/gi); if (findUrl && findUrl.length > 0) { setUrl(findUrl[0]) - // setFinalComment(finalComment.replace(findUrl[0], '').trim()) + setFinalComment(finalComment.replace(findUrl[0], '').trim()) } const match = comment.match(/\bnostr:([a-z0-9]+)/i); @@ -33,7 +30,7 @@ const ContentPreview = ({ key, comment }: { key: string, comment: string }) => { subNoteOnce(id_to_hex, onEvent); setFinalComment(finalComment.replace('nostr:'+nostrQuoteID, '').trim()) } - }, [comment]); + }, [comment, finalComment]); const getMetadataEvent = (event: Event) => { const metadataEvent = quoteEvents.find(e => e.pubkey === event.pubkey && e.kind === 0); diff --git a/client/src/components/PostCard/NewThreadCard.tsx b/client/src/components/PostCard/NewThreadCard.tsx index 97c59d8..5049344 100644 --- a/client/src/components/PostCard/NewThreadCard.tsx +++ b/client/src/components/PostCard/NewThreadCard.tsx @@ -1,7 +1,7 @@ import CardContainer from './CardContainer'; import { ArrowUpTrayIcon, CpuChipIcon } from '@heroicons/react/24/outline'; import { useState } from 'react'; -import { Event, generatePrivateKey, getPublicKey, finishEvent, relayInit } from 'nostr-tools'; +import { generatePrivateKey, getPublicKey, finishEvent } from 'nostr-tools'; import { minePow } from '../../utils/mine'; import { publish } from '../../utils/relays'; import NostrImg from '../../utils/ImgUpload'; diff --git a/client/src/components/PostCard/PostCard.tsx b/client/src/components/PostCard/PostCard.tsx index 11f0971..c780107 100644 --- a/client/src/components/PostCard/PostCard.tsx +++ b/client/src/components/PostCard/PostCard.tsx @@ -3,7 +3,7 @@ import { FolderIcon } from '@heroicons/react/24/outline'; import { parseContent } from '../../utils/content'; import { Event } from 'nostr-tools'; import { nip19 } from 'nostr-tools'; -import { getMetadata, uniqBy } from '../../utils/utils'; +import { getMetadata } from '../../utils/utils'; import ContentPreview from'../Modals/TextModal'; const colorCombos = [ @@ -89,7 +89,7 @@ const PostCard = ({ key, event, metadata, replyCount }: { key: string, event: Ev
- +
{file !== "" && (
diff --git a/client/src/components/Settings.tsx b/client/src/components/Settings.tsx index 6baa8dd..68f967f 100644 --- a/client/src/components/Settings.tsx +++ b/client/src/components/Settings.tsx @@ -1,5 +1,4 @@ -import React, { useState, useEffect } from 'react'; -import {generatePrivateKey, getPublicKey} from 'nostr-tools'; +import React, { useState } from 'react'; // import {powEvent} from './system'; // import {publish} from './relays'; diff --git a/client/src/components/Thread/OPCard.tsx b/client/src/components/Thread/OPCard.tsx index af75249..247d33b 100644 --- a/client/src/components/Thread/OPCard.tsx +++ b/client/src/components/Thread/OPCard.tsx @@ -2,11 +2,7 @@ import CardContainer from '../PostCard/CardContainer'; import { FolderIcon } from '@heroicons/react/24/outline'; import { parseContent } from '../../utils/content'; import { Event } from 'nostr-tools'; -import { nip19 } from 'nostr-tools'; -import { useEffect, useState } from 'react'; -import { subNote } from '../../utils/subscriptions'; -import { getMetadata, uniqBy } from '../../utils/utils'; -import { getLinkPreview } from 'link-preview-js'; +import { getMetadata } from '../../utils/utils'; import ContentPreview from '../Modals/TextModal'; const colorCombos = [ @@ -58,28 +54,13 @@ const timeAgo = (unixTime: number) => { }; const OPCard = ({ event, metadata, replyCount }: { event: Event, metadata: Event | null, replyCount: number}) => { - // Replace 10 with the actual number of comments for each post - const numberOfComments = 10; const { comment, file } = parseContent(event); const colorCombo = getColorFromHash(event.pubkey, colorCombos); - const [isExpanded, setIsExpanded] = useState(false); - const truncatedComment = comment.slice(0, 240); let metadataParsed = null; if (metadata !== null) { metadataParsed = getMetadata(metadata); } - - const [linkPreview, setLinkPreview] = useState(null); - - useEffect(() => { - const urls = comment.match(/\bhttps?:\/\/\S+/gi); - if (urls && urls.length > 0) { - getLinkPreview(urls[0]) - .then((preview) => setLinkPreview(preview as LinkPreview)) - .catch((error) => console.error(error)); - } - }, [comment]); return ( <> diff --git a/client/src/components/Thread/ReplyCard.tsx b/client/src/components/Thread/ReplyCard.tsx index 6361a8a..33e3b3e 100644 --- a/client/src/components/Thread/ReplyCard.tsx +++ b/client/src/components/Thread/ReplyCard.tsx @@ -3,8 +3,6 @@ import { FolderIcon } from '@heroicons/react/24/outline'; import { parseContent } from '../../utils/content'; import { Event } from 'nostr-tools'; 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'; diff --git a/client/src/components/Thread/Thread.tsx b/client/src/components/Thread/Thread.tsx index 0fd9946..f06229c 100644 --- a/client/src/components/Thread/Thread.tsx +++ b/client/src/components/Thread/Thread.tsx @@ -3,11 +3,9 @@ import { useState } from "react"; import { Event, nip19 } from "nostr-tools" import { subNote } from '../../utils/subscriptions'; import { useEffect } from 'react'; -import PostCard from '../PostCard/PostCard'; import { uniqBy } from '../../utils/utils'; import { DocumentTextIcon, FolderPlusIcon } from '@heroicons/react/24/outline'; -import { ArrowUpTrayIcon, CpuChipIcon } from '@heroicons/react/24/outline'; -import { generatePrivateKey, getPublicKey, finishEvent, relayInit } from 'nostr-tools'; +import { generatePrivateKey, getPublicKey, finishEvent } from 'nostr-tools'; import { minePow } from '../../utils/mine'; import { publish } from '../../utils/relays'; import ThreadPost from './ThreadPost'; @@ -28,7 +26,6 @@ const Thread = () => { // Define your callback function for subGlobalFeed const onEvent = (event: Event, relay: string) => { setEvents((prevEvents) => [...prevEvents, event]); - console.log(event.id + ' ' + event.kind + ' ' + event.tags); }; useEffect(() => { diff --git a/client/src/components/Thread/ThreadPost.tsx b/client/src/components/Thread/ThreadPost.tsx index 3c14761..27f3dcc 100644 --- a/client/src/components/Thread/ThreadPost.tsx +++ b/client/src/components/Thread/ThreadPost.tsx @@ -1,7 +1,7 @@ import { useParams } from 'react-router-dom'; import { useState } from "react"; import { ArrowUpTrayIcon, CpuChipIcon } from '@heroicons/react/24/outline'; -import { generatePrivateKey, getPublicKey, finishEvent, relayInit } from 'nostr-tools'; +import { generatePrivateKey, getPublicKey, finishEvent } from 'nostr-tools'; import { minePow } from '../../utils/mine'; import { publish } from '../../utils/relays'; import NostrImg from '../../utils/ImgUpload'; diff --git a/client/src/index.tsx b/client/src/index.tsx index 39219e2..949820f 100644 --- a/client/src/index.tsx +++ b/client/src/index.tsx @@ -3,7 +3,6 @@ import ReactDOM from 'react-dom/client'; import './index.css'; import App from './App'; import * as serviceWorkerRegistration from './serviceWorkerRegistration'; -import reportWebVitals from './reportWebVitals'; const root = ReactDOM.createRoot( document.getElementById('root') as HTMLElement @@ -18,8 +17,3 @@ root.render( // unregister() to register() below. Note this comes with some pitfalls. // Learn more about service workers: https://cra.link/PWA serviceWorkerRegistration.unregister(); - -// If you want to start measuring performance in your app, pass a function -// to log results (for example: reportWebVitals(console.log)) -// or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals -reportWebVitals(); diff --git a/client/src/reportWebVitals.ts b/client/src/reportWebVitals.ts deleted file mode 100644 index 49a2a16..0000000 --- a/client/src/reportWebVitals.ts +++ /dev/null @@ -1,15 +0,0 @@ -import { ReportHandler } from 'web-vitals'; - -const reportWebVitals = (onPerfEntry?: ReportHandler) => { - if (onPerfEntry && onPerfEntry instanceof Function) { - import('web-vitals').then(({ getCLS, getFID, getFCP, getLCP, getTTFB }) => { - getCLS(onPerfEntry); - getFID(onPerfEntry); - getFCP(onPerfEntry); - getLCP(onPerfEntry); - getTTFB(onPerfEntry); - }); - } -}; - -export default reportWebVitals; diff --git a/client/src/utils/subscriptions.ts b/client/src/utils/subscriptions.ts index 71b62f3..d36f053 100644 --- a/client/src/utils/subscriptions.ts +++ b/client/src/utils/subscriptions.ts @@ -1,6 +1,5 @@ import {sub, subOnce, unsubAll} from './relays'; import { Event } from 'nostr-tools'; -import { getPow } from './mine'; type SubCallback = ( event: Event,