From 8e6c396620471e26007ab16c4e353b32bdf59d28 Mon Sep 17 00:00:00 2001 From: smolgrrr Date: Mon, 30 Oct 2023 21:31:08 +1100 Subject: [PATCH] we up --- client/src/components/Thread/ReplyCard.tsx | 10 +++++--- client/src/components/Thread/Thread.tsx | 27 ++------------------- client/src/components/Thread/ThreadPost.tsx | 6 +++-- 3 files changed, 13 insertions(+), 30 deletions(-) diff --git a/client/src/components/Thread/ReplyCard.tsx b/client/src/components/Thread/ReplyCard.tsx index e1625e1..37f8599 100644 --- a/client/src/components/Thread/ReplyCard.tsx +++ b/client/src/components/Thread/ReplyCard.tsx @@ -5,6 +5,7 @@ import { Event } from 'nostr-tools'; import { nip19 } from 'nostr-tools'; import { getMetadata, uniqBy } from '../../utils/utils'; import ContentPreview from '../Modals/TextModal'; +import { useEffect } from 'react'; const colorCombos = [ 'from-red-400 to-yellow-500', @@ -63,7 +64,7 @@ const ReplyCard = ({ event, metadata, replyCount, repliedTo }: { event: Event, m metadataParsed = getMetadata(metadata); } - // const replyPubkeys = event.tags.filter(tag => tag[0] === 'p'); + const replyPubkeys = event.tags.filter(tag => tag[0] === 'p'); // const getMetadataEvent = (event: Event) => { // const metadataEvent = uniqEvents.find(e => e.pubkey === event.pubkey && e.kind === 0); @@ -72,6 +73,9 @@ const ReplyCard = ({ event, metadata, replyCount, repliedTo }: { event: Event, m // } // return null; // } + useEffect(() => { + console.log(repliedTo) + }, []); return ( <> @@ -100,9 +104,9 @@ const ReplyCard = ({ event, metadata, replyCount, repliedTo }: { event: Event, m
Reply to: - {uniqBy(repliedTo, 'pubkey').map((event, index) => ( + {repliedTo.map((event, index) => ( <> - + {/* */}
))} diff --git a/client/src/components/Thread/Thread.tsx b/client/src/components/Thread/Thread.tsx index f06229c..e748ccb 100644 --- a/client/src/components/Thread/Thread.tsx +++ b/client/src/components/Thread/Thread.tsx @@ -19,7 +19,6 @@ const Thread = () => { const { id } = useParams(); const [events, setEvents] = useState([]); // Initialize state let decodeResult = nip19.decode(id as string); - const [comment, setComment] = useState(""); const [showForm, setShowForm] = useState(false); const [postType, setPostType] = useState(""); @@ -41,28 +40,6 @@ const Thread = () => { }; }, []); // Empty dependency array means this useEffect runs once when the component mounts - const handleSubmit = async (event: React.FormEvent) => { - event.preventDefault(); - let sk = generatePrivateKey(); - - try { - const event = minePow({ - kind: 1, - tags: [], - content: comment, - created_at: Math.floor(Date.now() / 1000), - pubkey: getPublicKey(sk), - }, difficulty); - - const signedEvent = finishEvent(event, sk); - await publish(signedEvent); - console.log(signedEvent.id); - - } catch (error) { - setComment(comment + " " + error); - } - }; - const uniqEvents = events.length > 0 ? uniqBy(events, "id") : []; const getMetadataEvent = (event: Event) => { @@ -78,7 +55,7 @@ const Thread = () => { } const repliedList = (event: Event): Event[] => { - return uniqEvents.filter(e => event.tags.some(tag => tag[0] === 'p' && tag[1] === e.pubkey) && e.kind === 0); + return uniqEvents.filter(e => event.tags.some(tag => tag[0] === 'p' && tag[1] === e.pubkey)); } if (!uniqEvents[0]) { @@ -127,7 +104,7 @@ const Thread = () => { />
- +
{/* This is the white line separator */} {uniqEvents diff --git a/client/src/components/Thread/ThreadPost.tsx b/client/src/components/Thread/ThreadPost.tsx index 1e893c0..89032a3 100644 --- a/client/src/components/Thread/ThreadPost.tsx +++ b/client/src/components/Thread/ThreadPost.tsx @@ -1,13 +1,13 @@ import { useParams } from 'react-router-dom'; import { useState, useMemo, useEffect } from "react"; import { ArrowUpTrayIcon, CpuChipIcon } from '@heroicons/react/24/outline'; -import { generatePrivateKey, getPublicKey, finishEvent } from 'nostr-tools'; +import { generatePrivateKey, getPublicKey, finishEvent, Event as NostrEvent } from 'nostr-tools'; import { publish } from '../../utils/relays'; import NostrImg from '../../utils/ImgUpload'; import { nip19 } from 'nostr-tools'; -const ThreadPost = ({ state, type }: { state: Boolean, type: String }) => { +const ThreadPost = ({ OPEvent, state, type }: { OPEvent: NostrEvent, state: Boolean, type: String }) => { const { id } = useParams(); const [comment, setComment] = useState(""); const [file, setFile] = useState(""); @@ -47,8 +47,10 @@ const ThreadPost = ({ state, type }: { state: Boolean, type: String }) => { let modifiedComment = comment + " " + file; if (type === 'r') { tags.push(["e", id as string]) + tags.push(["p", OPEvent.pubkey]) } else if (type === 'q') { tags.push(["q", id as string]) + tags.push(["p", OPEvent.pubkey]) modifiedComment += ' nostr:' + nip19.noteEncode(id); }