From 80a2b3fc29be90aa9fc49ddcb20804b4d6d215f2 Mon Sep 17 00:00:00 2001 From: smolgrrr Date: Wed, 25 Oct 2023 18:53:34 +1100 Subject: [PATCH] various tings alright --- client/package.json | 2 + .../src/components/PostCard/CardContainer.tsx | 2 +- .../src/components/PostCard/NewThreadCard.tsx | 129 ++++++++++------- client/src/components/PostCard/PostCard.tsx | 4 +- client/src/components/Settings.tsx | 81 ++++++----- client/src/components/Thread/Thread.tsx | 58 +++----- client/src/components/Thread/ThreadPost.tsx | 133 ++++++++++++++++++ client/src/index.css | 1 + client/src/utils/ImgUpload.ts | 56 +++++--- 9 files changed, 313 insertions(+), 153 deletions(-) create mode 100644 client/src/components/Thread/ThreadPost.tsx diff --git a/client/package.json b/client/package.json index 2e01785..88dbeb1 100644 --- a/client/package.json +++ b/client/package.json @@ -15,8 +15,10 @@ "nostr-tools": "latest", "react": "^18.2.0", "react-dom": "^18.2.0", + "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/components/PostCard/CardContainer.tsx b/client/src/components/PostCard/CardContainer.tsx index ff84b3d..cc0467b 100644 --- a/client/src/components/PostCard/CardContainer.tsx +++ b/client/src/components/PostCard/CardContainer.tsx @@ -2,7 +2,7 @@ import { PropsWithChildren } from 'react'; export default function CardContainer({ children }: PropsWithChildren) { return ( -
+
{children}
); diff --git a/client/src/components/PostCard/NewThreadCard.tsx b/client/src/components/PostCard/NewThreadCard.tsx index 83c0cba..97c59d8 100644 --- a/client/src/components/PostCard/NewThreadCard.tsx +++ b/client/src/components/PostCard/NewThreadCard.tsx @@ -1,15 +1,17 @@ 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 { Event, generatePrivateKey, getPublicKey, finishEvent, relayInit } from 'nostr-tools'; import { minePow } from '../../utils/mine'; import { publish } from '../../utils/relays'; +import NostrImg from '../../utils/ImgUpload'; const difficulty = 20 const NewThreadCard: React.FC = () => { const [comment, setComment] = useState(""); - + const [file, setFile] = useState(""); + const handleSubmit = async (event: React.FormEvent) => { event.preventDefault(); let sk = generatePrivateKey(); @@ -18,73 +20,98 @@ const NewThreadCard: React.FC = () => { const event = minePow({ kind: 1, tags: [], - content: comment, + content: comment + " " + file, created_at: Math.floor(Date.now() / 1000), pubkey: getPublicKey(sk), }, difficulty); const signedEvent = finishEvent(event, sk); await publish(signedEvent); - console.log(signedEvent.id); - + + setComment("") + setFile("") } catch (error) { setComment(comment + " " + error); } }; - // async function attachFile(file_input: File | null) { - // try { - // if (file_input) { - // const rx = await NostrImg(file_input); - // if (rx.url) { - // setComment(comment + " " + rx.url); - // } else if (rx?.error) { - // setComment(comment + " " + rx.error); - // } - // } - // } catch (error: unknown) { - // if (error instanceof Error) { - // setComment(comment + " " + error?.message); - // } - // } - // } + async function attachFile(file_input: File | null) { + try { + if (file_input) { + const rx = await NostrImg(file_input); + if (rx.url) { + setFile(rx.url); + } else if (rx?.error) { + setFile(rx.error); + } + } + } catch (error: unknown) { + if (error instanceof Error) { + setFile(error?.message); + } + } + } return ( <> -
- -