From 91311e63466573fa6baf356ed719b0b8959535c2 Mon Sep 17 00:00:00 2001 From: smolgrrr Date: Fri, 19 Apr 2024 19:27:30 +1000 Subject: [PATCH] rm boards --- client/src/App.tsx | 4 - client/src/components/Board.tsx | 130 ------------------- client/src/components/Boards.tsx | 85 ------------ client/src/components/Forms/PostFormCard.tsx | 8 +- client/src/components/Header/Header.tsx | 11 -- client/src/components/Settings.tsx | 2 +- client/src/utils/subscriptions.ts | 92 ------------- 7 files changed, 2 insertions(+), 330 deletions(-) delete mode 100644 client/src/components/Board.tsx delete mode 100644 client/src/components/Boards.tsx diff --git a/client/src/App.tsx b/client/src/App.tsx index eaa17e4..32f3bd1 100644 --- a/client/src/App.tsx +++ b/client/src/App.tsx @@ -6,8 +6,6 @@ import Thread from "./components/Thread"; import Header from "./components/Header/Header"; import AddToHomeScreenPrompt from "./components/Modals/CheckMobile/CheckMobile"; import Notifications from "./components/Notifications"; -import Board from "./components/Board"; -import Boards from "./components/Boards"; function App() { return ( @@ -18,8 +16,6 @@ function App() { } /> } /> } /> - } /> - } /> diff --git a/client/src/components/Board.tsx b/client/src/components/Board.tsx deleted file mode 100644 index 1485f6b..0000000 --- a/client/src/components/Board.tsx +++ /dev/null @@ -1,130 +0,0 @@ -import { useEffect, useState, useCallback } from "react"; -import PostCard from "./Modals/NoteCard"; -import { uniqBy } from "../utils/otherUtils"; // Assume getPow is a correct import now -import { subBoardFeed, subProfile} from "../utils/subscriptions"; -import { verifyPow } from "../utils/mine"; -import { Event, nip19 } from "nostr-tools"; -import NewNoteCard from "./Forms/PostFormCard"; -import RepostCard from "./Modals/RepostCard"; -import OptionsBar from "./Modals/OptionsBar"; -import { useParams } from "react-router-dom"; - -const DEFAULT_DIFFICULTY = 20; - -const useUniqEvents = (pubkey: string) => { - const [events, setEvents] = useState([]); - const age = Number(localStorage.getItem("age")) || 24; - - useEffect(() => { - const onEvent = (event: Event) => setEvents((prevEvents) => [...prevEvents, event]); - console.log(events) - const unsubscribe = subBoardFeed(pubkey, onEvent, age); - - return unsubscribe; - }, [pubkey]); - - const uniqEvents = uniqBy(events, "id"); - - const noteEvents = uniqEvents.filter(event => event.kind === 1 || event.kind === 6); - const metadataEvents = uniqEvents.filter(event => event.kind === 0); - const pinnedEvents = uniqEvents.filter(event => event.pubkey === pubkey && !event.tags.some((tag) => tag[0] === "e")); - - return { pinnedEvents, noteEvents, metadataEvents }; -}; - -const Board = () => { - const { id } = useParams(); - const filterDifficulty = localStorage.getItem("filterDifficulty") || DEFAULT_DIFFICULTY; - const [sortByTime, setSortByTime] = useState(localStorage.getItem('sortBy') !== 'false'); - const [setAnon, setSetAnon] = useState(localStorage.getItem('anonMode') !== 'false'); - - let decodeResult = nip19.decode(id as string); - let pubkey = decodeResult.data as string; - const {pinnedEvents, noteEvents, metadataEvents } = useUniqEvents(pubkey); - - const [delayedSort, setDelayedSort] = useState(false) - - const postEvents: Event[] = noteEvents - .filter((event) => - verifyPow(event) >= Number(filterDifficulty) && - event.kind !== 0 && - (event.kind !== 1 || !event.tags.some((tag) => tag[0] === "e")) - ) - - // Delayed filtering - useEffect(() => { - const timer = setTimeout(() => { - setDelayedSort(true); - }, 3000); - - return () => clearTimeout(timer); - }, []); - - let sortedEvents = [...postEvents] - .sort((a, b) => - sortByTime ? b.created_at - a.created_at : verifyPow(b) - verifyPow(a) - ) - - if (delayedSort) { - sortedEvents = sortedEvents.filter( - !setAnon ? (e) => !metadataEvents.some((metadataEvent) => metadataEvent.pubkey === e.pubkey) : () => true - ); - } else { - sortedEvents = sortedEvents.filter((e) => setAnon || e.tags.some((tag) => tag[0] === "client" && tag[1] === 'getwired.app')); - } - - const toggleSort = useCallback(() => { - setSortByTime(prev => { - const newValue = !prev; - localStorage.setItem('sortBy', String(newValue)); - return newValue; - }); - }, []); - - const toggleAnon = useCallback(() => { - setSetAnon(prev => { - const newValue = !prev; - localStorage.setItem('anonMode', String(newValue)); - return newValue; - }); - }, []); - - const countReplies = (event: Event) => { - return noteEvents.filter((e) => e.tags.some((tag) => tag[0] === "e" && tag[1] === event.id)).length; - }; - - // Render the component - return ( -
-
- -
- -
- {pinnedEvents.map((event) => ( -
- e.pubkey === event.pubkey && e.kind === 0) || null} - replyCount={countReplies(event)} - /> -
- ))} - {sortedEvents.map((event) => ( - event.kind === 1 ? - e.pubkey === event.pubkey && e.kind === 0) || null} - replyCount={countReplies(event)} - /> - : - - ))} -
-
- ); -}; - -export default Board; diff --git a/client/src/components/Boards.tsx b/client/src/components/Boards.tsx deleted file mode 100644 index b526234..0000000 --- a/client/src/components/Boards.tsx +++ /dev/null @@ -1,85 +0,0 @@ -import React, { useState } from 'react'; - -export const DefaultBoards = [ - ['Bitcoin', 'npub19nrn4l0s39kpwww7pgk9jddj8lzekqxmtrll8r2a57chtq3zx6sq00vetn', 'btc'], - ['Technology', 'npub1mltf3r3tskdxfjlq6ltt2n73xs29wcza3sjfw75ggxz3p8fpcg4qe44h9v', 'g'], - ['Television & Film', 'npub1cpeuaea3cymx42fmmx2ur82t5qnckqv85qy5q2nhzhxwzael5v4sksfe29', 'tv'], - ['Vidya', 'npub19t2dt6deqaleq59fdaq576tnqdzwkyzwptxfa2tck0v66w29xagqe7yqll', 'v'], - ['Politically Incorrect', 'npub19znf32s8s7qpkpfrck0suyym3m3wtrwpnldj76u0qwjtms3dcftsqs6r87', 'pol'] -]; - -const Boards = () => { - const [addedBoards, setAddedBoards] = useState(JSON.parse(localStorage.getItem('addedBoards') as string) || []); - const [boardName, setBoardName] = useState(''); - const [boardPubkey, setboardPubkey] = useState('') - - const handleSubmit = (e: React.FormEvent) => { - e.preventDefault(); - const newBoards = [...addedBoards, [boardName, boardPubkey]]; - setAddedBoards(newBoards); - localStorage.setItem('addedBoards', JSON.stringify(newBoards)); - }; - - const clearBoards = () => { - localStorage.setItem('addedBoards', JSON.stringify([])); - setAddedBoards([]); - }; - - return ( -
-

Boards

-
- {/* Map over DefaultBoards and addedBoards and display them */} -
    - {DefaultBoards.map((board, index) => ( -
  • /{board[0]}/
  • - ))} - {addedBoards.map((board: string[], index: number) => ( -
  • /{board[0]}/
  • - ))} -
- -
-
-
- -
- setBoardName(e.target.value)} - className="w-full px-3 py-2 border rounded-md bg-black" - /> - setboardPubkey(e.target.value)} - className="w-full px-3 py-2 border rounded-md bg-black" - /> -
-
-
- - -
-
-
- ); -}; - -export default Boards; diff --git a/client/src/components/Forms/PostFormCard.tsx b/client/src/components/Forms/PostFormCard.tsx index 6483ab1..8023ab2 100644 --- a/client/src/components/Forms/PostFormCard.tsx +++ b/client/src/components/Forms/PostFormCard.tsx @@ -16,13 +16,11 @@ import "./Form.css"; interface FormProps { refEvent?: NostrEvent; tagType?: 'Reply' | 'Quote' | ''; - board?: string; } const NewNoteCard = ({ refEvent, - tagType, - board + tagType }: FormProps) => { const ref = useRef(null); const [comment, setComment] = useState(""); @@ -62,10 +60,6 @@ const NewNoteCard = ({ } } - if (board) { - unsigned.tags.push(['d', nip19.decode(board).data as string]); - } - const handleDifficultyChange = (event: Event) => { const customEvent = event as CustomEvent; const { difficulty } = customEvent.detail; diff --git a/client/src/components/Header/Header.tsx b/client/src/components/Header/Header.tsx index 9686d49..16fc599 100644 --- a/client/src/components/Header/Header.tsx +++ b/client/src/components/Header/Header.tsx @@ -3,7 +3,6 @@ import { BellIcon, ArchiveBoxIcon } from "@heroicons/react/24/outline"; -import { DefaultBoards } from "../Boards"; export default function Header() { return ( @@ -17,11 +16,6 @@ export default function Header() { -
- {DefaultBoards.map((board) => ( - /{board[2]}/ - ))} -
- ); } diff --git a/client/src/components/Settings.tsx b/client/src/components/Settings.tsx index 3a04cb9..f986d4e 100644 --- a/client/src/components/Settings.tsx +++ b/client/src/components/Settings.tsx @@ -8,7 +8,7 @@ type TestResponse = { }; const Settings = () => { - const [filterDifficulty, setFilterDifficulty] = useState(localStorage.getItem('filterDifficulty') || 20); + const [filterDifficulty, setFilterDifficulty] = useState(localStorage.getItem('filterDifficulty') || 21); const [difficulty, setDifficulty] = useState(localStorage.getItem('difficulty') || 21); const [age, setAge] = useState(localStorage.getItem('age') || 24); const [showAdvancedSettings, setShowAdvancedSettings] = useState(false); diff --git a/client/src/utils/subscriptions.ts b/client/src/utils/subscriptions.ts index 055d2ff..3acab62 100644 --- a/client/src/utils/subscriptions.ts +++ b/client/src/utils/subscriptions.ts @@ -262,98 +262,6 @@ export const subNotifications = ( }); }; -/** subscribe to global feed */ -export const subBoardFeed = ( - board: string, - onEvent: SubCallback, - age: number - ) => { - console.info('subscribe to board feed'); - unsubAll(); - const now = Math.floor(Date.now() * 0.001); - const pubkeys = new Set(); - const notes = new Set(); - const prefix = Math.floor(16 / 4); // 4 bits in each '0' character - sub({ // get past events - cb: (evt, relay) => { - pubkeys.add(evt.pubkey); - notes.add(evt.id); - onEvent(evt, relay); - }, - filter: { - ...(prefix && { ids: ['0'.repeat(prefix)] }), - "#d": [board], - kinds: [1, 6], - since: Math.floor((Date.now() * 0.001) - (age * 60 * 60)), - limit: 500, - }, - unsub: true - }); - sub({ - cb: (evt, relay) => { - onEvent(evt, relay); - }, - filter: { - authors: [board], - kinds: [1, 7], - limit: 25, - }, - unsub: true, - }); - - setTimeout(() => { - // get profile info - sub({ - cb: onEvent, - filter: { - authors: Array.from(pubkeys), - kinds: [0], - limit: pubkeys.size, - }, - unsub: true, - }); - pubkeys.clear(); - - sub({ - cb: onEvent, - filter: { - '#e': Array.from(notes), - kinds: [1], - }, - unsub: true, - }); - - notes.clear(); - }, 2000); - - // subscribe to future notes, reactions and profile updates - sub({ - cb: (evt, relay) => { - onEvent(evt, relay); - if ( - evt.kind !== 1 - || pubkeys.has(evt.pubkey) - ) { - return; - } - subOnce({ // get profile data - relay, - cb: onEvent, - filter: { - authors: [evt.pubkey], - kinds: [0], - limit: 1, - } - }); - }, - filter: { - ...(prefix && { ids: ['0'.repeat(prefix)] }), - kinds: [1], - since: now, - }, - }); -}; - export const subProfile = ( pubkey: string, onEvent: SubCallback,