From 4b2161369de32e852d28c600ab1a6a560b87a2bb Mon Sep 17 00:00:00 2001 From: Kieran Date: Tue, 19 Sep 2023 10:01:13 +0100 Subject: [PATCH] Prettier --- packages/app/src/Element/Note.tsx | 11 +---------- packages/app/src/Feed/FeedReactions.ts | 11 ++++------- packages/app/src/Feed/ThreadFeed.ts | 18 ++++++++---------- packages/app/src/Hooks/useThreadContext.tsx | 11 ++--------- packages/app/src/Pages/DeckLayout.tsx | 6 +++--- packages/app/src/Pages/Notifications.tsx | 10 +--------- packages/app/src/Pages/Root.tsx | 13 ++++++++++--- packages/app/src/Zapper.ts | 9 ++------- packages/app/src/lang.json | 3 +++ packages/app/src/translations/en.json | 1 + packages/system/src/nostr-link.ts | 10 +++++----- packages/system/src/request-builder.ts | 4 ++-- 12 files changed, 42 insertions(+), 65 deletions(-) diff --git a/packages/app/src/Element/Note.tsx b/packages/app/src/Element/Note.tsx index 40bcb8ee..d6932007 100644 --- a/packages/app/src/Element/Note.tsx +++ b/packages/app/src/Element/Note.tsx @@ -3,16 +3,7 @@ import React, { useMemo, useState, ReactNode } from "react"; import { useNavigate, Link } from "react-router-dom"; import { useInView } from "react-intersection-observer"; import { useIntl, FormattedMessage } from "react-intl"; -import { - TaggedNostrEvent, - HexKey, - EventKind, - NostrPrefix, - Lists, - EventExt, - parseZap, - NostrLink -} from "@snort/system"; +import { TaggedNostrEvent, HexKey, EventKind, NostrPrefix, Lists, EventExt, parseZap, NostrLink } from "@snort/system"; import { System } from "index"; import useEventPublisher from "Feed/EventPublisher"; diff --git a/packages/app/src/Feed/FeedReactions.ts b/packages/app/src/Feed/FeedReactions.ts index c9625ab9..0a429b00 100644 --- a/packages/app/src/Feed/FeedReactions.ts +++ b/packages/app/src/Feed/FeedReactions.ts @@ -12,19 +12,16 @@ export function useReactions(subId: string, ids: Array, others?: (rb: const aTags = ids.filter(a => a.type === NostrPrefix.Address); if (aTags.length > 0 || eTags.length > 0) { - const f = rb.withFilter() + const f = rb + .withFilter() .kinds( pref.enableReactions ? [EventKind.Reaction, EventKind.Repost, EventKind.ZapReceipt] : [EventKind.ZapReceipt, EventKind.Repost], ); - if(aTags.length > 0) { - f.tag("a", aTags.map(v => `${v.kind}:${v.author}:${v.id}`)); - } - if(eTags.length > 0) { - f.tag("e", eTags.map(v => v.id)); - } + aTags.forEach(v => f.replyToLink(v)); + eTags.forEach(v => f.replyToLink(v)); } others?.(rb); return rb.numFilters > 0 ? rb : null; diff --git a/packages/app/src/Feed/ThreadFeed.ts b/packages/app/src/Feed/ThreadFeed.ts index 5e3a6468..cefde939 100644 --- a/packages/app/src/Feed/ThreadFeed.ts +++ b/packages/app/src/Feed/ThreadFeed.ts @@ -14,13 +14,9 @@ export default function useThreadFeed(link: NostrLink) { sub.withOptions({ leaveOpen: true, }); - sub.withFilter() - .kinds([EventKind.TextNote]) - .link(link); + sub.withFilter().kinds([EventKind.TextNote]).link(link); if (allEvents.length > 0) { - const f = sub - .withFilter() - .kinds([EventKind.TextNote]); + const f = sub.withFilter().kinds([EventKind.TextNote]); allEvents.forEach(x => f.replyToLink(x)); } return sub; @@ -31,10 +27,12 @@ export default function useThreadFeed(link: NostrLink) { useEffect(() => { if (store.data) { const mainNotes = store.data?.filter(a => a.kind === EventKind.TextNote || a.kind === EventKind.Polls) ?? []; - const links = mainNotes.map(a => [ - NostrLink.fromEvent(a), - ...a.tags.filter(a => a[0] === "e" || a[0] === "a").map(v => NostrLink.fromTag(v)) - ]).flat(); + const links = mainNotes + .map(a => [ + NostrLink.fromEvent(a), + ...a.tags.filter(a => a[0] === "e" || a[0] === "a").map(v => NostrLink.fromTag(v)), + ]) + .flat(); setAllEvents(links); } }, [store.data?.length]); diff --git a/packages/app/src/Hooks/useThreadContext.tsx b/packages/app/src/Hooks/useThreadContext.tsx index ba6171b7..d719889a 100644 --- a/packages/app/src/Hooks/useThreadContext.tsx +++ b/packages/app/src/Hooks/useThreadContext.tsx @@ -1,12 +1,5 @@ import { unwrap } from "@snort/shared"; -import { - EventExt, - NostrLink, - NostrPrefix, - TaggedNostrEvent, - u256, - Thread as ThreadInfo, -} from "@snort/system"; +import { EventExt, NostrLink, NostrPrefix, TaggedNostrEvent, u256, Thread as ThreadInfo } from "@snort/system"; import useThreadFeed from "Feed/ThreadFeed"; import { findTag } from "SnortUtils"; import { ReactNode, createContext, useMemo, useState } from "react"; @@ -56,7 +49,7 @@ export function ThreadContextWrapper({ link, children }: { link: NostrLink; chil // Root is the parent of the current note or the current note if its a root note or the root of the thread const root = useMemo(() => { const currentNote = - feed.thread?.find( + feed.thread?.find( ne => ne.id === currentId || (link.type === NostrPrefix.Address && findTag(ne, "d") === currentId && ne.pubkey === link.author), diff --git a/packages/app/src/Pages/DeckLayout.tsx b/packages/app/src/Pages/DeckLayout.tsx index 45a5e230..ca7242d6 100644 --- a/packages/app/src/Pages/DeckLayout.tsx +++ b/packages/app/src/Pages/DeckLayout.tsx @@ -25,8 +25,8 @@ import useLogin from "Hooks/useLogin"; type Cols = "notes" | "articles" | "media" | "streams" | "notifications"; interface DeckScope { - thread?: NostrLink, - setThread: (e?: NostrLink) => void + thread?: NostrLink; + setThread: (e?: NostrLink) => void; } export const DeckContext = createContext(undefined); @@ -35,7 +35,7 @@ export function SnortDeckLayout() { const login = useLogin(); const navigate = useNavigate(); const [deckScope, setDeckScope] = useState({ - setThread: (e?: NostrLink) => setDeckScope(s => ({ ...s, thread: e })) + setThread: (e?: NostrLink) => setDeckScope(s => ({ ...s, thread: e })), }); useLoginFeed(); diff --git a/packages/app/src/Pages/Notifications.tsx b/packages/app/src/Pages/Notifications.tsx index 70de123e..f4e81b84 100644 --- a/packages/app/src/Pages/Notifications.tsx +++ b/packages/app/src/Pages/Notifications.tsx @@ -1,14 +1,6 @@ import "./Notifications.css"; import { useEffect, useMemo, useSyncExternalStore } from "react"; -import { - EventExt, - EventKind, - NostrEvent, - NostrLink, - NostrPrefix, - TaggedNostrEvent, - parseZap, -} from "@snort/system"; +import { EventExt, EventKind, NostrEvent, NostrLink, NostrPrefix, TaggedNostrEvent, parseZap } from "@snort/system"; import { unwrap } from "@snort/shared"; import { useUserProfile } from "@snort/system-react"; import { useInView } from "react-intersection-observer"; diff --git a/packages/app/src/Pages/Root.tsx b/packages/app/src/Pages/Root.tsx index 9a599133..fc488539 100644 --- a/packages/app/src/Pages/Root.tsx +++ b/packages/app/src/Pages/Root.tsx @@ -142,9 +142,16 @@ export const NotesTab = () => { <> - { - deckContext.setThread(NostrLink.fromEvent(ev)); - } : undefined} /> + { + deckContext.setThread(NostrLink.fromEvent(ev)); + } + : undefined + } + /> ); }; diff --git a/packages/app/src/Zapper.ts b/packages/app/src/Zapper.ts index 1a119d36..eb211ef8 100644 --- a/packages/app/src/Zapper.ts +++ b/packages/app/src/Zapper.ts @@ -1,10 +1,5 @@ import { LNURL } from "@snort/shared"; -import { - EventPublisher, - NostrEvent, - NostrLink, - SystemInterface -} from "@snort/system"; +import { EventPublisher, NostrEvent, NostrLink, SystemInterface } from "@snort/system"; import { generateRandomKey } from "Login"; import { isHex } from "SnortUtils"; import { LNWallet, WalletInvoiceState } from "Wallet"; @@ -203,7 +198,7 @@ export class Zapper { return svc; } } - }catch { + } catch { // nothing } } diff --git a/packages/app/src/lang.json b/packages/app/src/lang.json index f5218ce5..805232ab 100644 --- a/packages/app/src/lang.json +++ b/packages/app/src/lang.json @@ -11,6 +11,9 @@ "+aZY2h": { "defaultMessage": "Zap Type" }, + "+tShPg": { + "defaultMessage": "following" + }, "+vA//S": { "defaultMessage": "Logins" }, diff --git a/packages/app/src/translations/en.json b/packages/app/src/translations/en.json index 9fba5098..216b763e 100644 --- a/packages/app/src/translations/en.json +++ b/packages/app/src/translations/en.json @@ -3,6 +3,7 @@ "+PzQ9Y": "Payout Now", "+Vxixo": "Secret Group Chat", "+aZY2h": "Zap Type", + "+tShPg": "following", "+vA//S": "Logins", "+vIQlC": "Please make sure to save the following password in order to manage your handle in the future", "+vVZ/G": "Connect", diff --git a/packages/system/src/nostr-link.ts b/packages/system/src/nostr-link.ts index aedac1a7..42e56868 100644 --- a/packages/system/src/nostr-link.ts +++ b/packages/system/src/nostr-link.ts @@ -8,11 +8,11 @@ export class NostrLink { readonly id: string, readonly kind?: number, readonly author?: string, - readonly relays?: Array - ) { } + readonly relays?: Array, + ) {} encode(): string { - if(this.type === NostrPrefix.Note || this.type === NostrPrefix.PrivateKey || this.type === NostrPrefix.PublicKey) { + if (this.type === NostrPrefix.Note || this.type === NostrPrefix.PrivateKey || this.type === NostrPrefix.PublicKey) { return hexToBech32(this.type, this.id); } else { return encodeTLV(this.type, this.id, this.relays, this.kind, this.author); @@ -39,12 +39,12 @@ export class NostrLink { } else if (this.type === NostrPrefix.Event || this.type === NostrPrefix.Note) { return this.id === ev.id; } - + return false; } static fromTag(tag: Array) { - const relays = tag.length > 2 ? [tag[2]]: undefined; + const relays = tag.length > 2 ? [tag[2]] : undefined; switch (tag[0]) { case "e": { return new NostrLink(NostrPrefix.Event, tag[1], undefined, undefined, relays); diff --git a/packages/system/src/request-builder.ts b/packages/system/src/request-builder.ts index 03a0538f..480ed115 100644 --- a/packages/system/src/request-builder.ts +++ b/packages/system/src/request-builder.ts @@ -233,7 +233,7 @@ export class RequestFilterBuilder { * Get event from link */ link(link: NostrLink) { - if(link.type === NostrPrefix.Address) { + if (link.type === NostrPrefix.Address) { return this.tag("d", [link.id]) .kinds([unwrap(link.kind)]) .authors([unwrap(link.author)]); @@ -246,7 +246,7 @@ export class RequestFilterBuilder { * Get replies to link with e/a tags */ replyToLink(link: NostrLink) { - if(link.type === NostrPrefix.Address) { + if (link.type === NostrPrefix.Address) { return this.tag("a", [`${link.kind}:${link.author}:${link.id}`]); } else { return this.tag("e", [link.id]);