From 16c54185bbc86e0ce422cb1937d381e8f4716295 Mon Sep 17 00:00:00 2001 From: Kieran Date: Tue, 22 Aug 2023 22:48:37 +0100 Subject: [PATCH] cleanup --- public/index.html | 1 - src/element/chat-message.tsx | 30 +++++++++--------- src/element/follow-button.tsx | 4 ++- src/element/live-chat.css | 2 -- src/element/live-chat.tsx | 4 +-- src/element/new-stream.tsx | 3 +- src/element/share-menu.tsx | 6 ++-- src/element/stream-cards.tsx | 8 ++--- src/element/textarea.tsx | 4 +-- {public => src}/fonts/outfit/outfit.css | 0 .../fonts/outfit/outfit_400_latin-ext.woff2 | Bin .../fonts/outfit/outfit_400_latin.woff2 | Bin .../fonts/outfit/outfit_500_latin-ext.woff2 | Bin .../fonts/outfit/outfit_500_latin.woff2 | Bin .../fonts/outfit/outfit_600_latin-ext.woff2 | Bin .../fonts/outfit/outfit_600_latin.woff2 | Bin .../fonts/outfit/outfit_700_latin-ext.woff2 | Bin .../fonts/outfit/outfit_700_latin.woff2 | Bin src/hooks/cards.ts | 8 ++--- src/hooks/emoji.tsx | 2 +- src/hooks/goals.ts | 3 +- src/index.tsx | 1 + src/login.ts | 4 +-- src/pages/chat-popout.tsx | 3 +- src/pages/profile-page.tsx | 3 +- src/pages/stream-page.tsx | 3 +- src/pages/tag.tsx | 3 +- src/providers/owncast.ts | 2 +- src/providers/zsz.ts | 2 +- src/utils.ts | 2 +- src/wish/index.ts | 6 ++-- webpack.config.js | 2 +- 32 files changed, 57 insertions(+), 49 deletions(-) rename {public => src}/fonts/outfit/outfit.css (100%) rename {public => src}/fonts/outfit/outfit_400_latin-ext.woff2 (100%) rename {public => src}/fonts/outfit/outfit_400_latin.woff2 (100%) rename {public => src}/fonts/outfit/outfit_500_latin-ext.woff2 (100%) rename {public => src}/fonts/outfit/outfit_500_latin.woff2 (100%) rename {public => src}/fonts/outfit/outfit_600_latin-ext.woff2 (100%) rename {public => src}/fonts/outfit/outfit_600_latin.woff2 (100%) rename {public => src}/fonts/outfit/outfit_700_latin-ext.woff2 (100%) rename {public => src}/fonts/outfit/outfit_700_latin.woff2 (100%) diff --git a/public/index.html b/public/index.html index 068ece2..759e512 100644 --- a/public/index.html +++ b/public/index.html @@ -10,7 +10,6 @@ zap.stream - diff --git a/src/element/chat-message.tsx b/src/element/chat-message.tsx index f472c23..23b2543 100644 --- a/src/element/chat-message.tsx +++ b/src/element/chat-message.tsx @@ -65,7 +65,7 @@ export function ChatMessage({ inView?.isIntersecting ? ev.pubkey : undefined ); const shouldShowMuteButton = - ev.pubkey !== streamer && ev.pubkey != login?.pubkey; + ev.pubkey !== streamer && ev.pubkey !== login?.pubkey; const zapTarget = profile?.lud16 ?? profile?.lud06; const zaps = useMemo(() => { return reactions @@ -111,8 +111,8 @@ export function ChatMessage({ const pub = login?.publisher(); if (emoji.native) { reply = await pub?.react(ev, emoji.native || "+1"); - } else { - const e = getEmojiById(emoji.id!); + } else if (emoji.id) { + const e = getEmojiById(emoji.id); if (e) { reply = await pub?.generic((eb) => { return eb @@ -120,7 +120,7 @@ export function ChatMessage({ .content(`:${emoji.id}:`) .tag(["e", ev.id]) .tag(["p", ev.pubkey]) - .tag(["emoji", e.at(1)!, e.at(2)!]); + .tag(["emoji", e[1], e[2]]); }); } } @@ -141,7 +141,7 @@ export function ChatMessage({ setShowEmojiPicker(!showEmojiPicker); } - async function muteUser(e: React.MouseEvent) { + function muteUser(e: React.MouseEvent) { e.stopPropagation(); mute(); } @@ -194,7 +194,7 @@ export function ChatMessage({
{isCustomEmojiReaction && emoji ? ( - + ) : ( {e} @@ -210,16 +210,16 @@ export function ChatMessage({ style={ isTablet ? { - display: showZapDialog || isHovering ? "flex" : "none", - } + display: showZapDialog || isHovering ? "flex" : "none", + } : { - position: "fixed", - top: topOffset ? topOffset - 12 : 0, - left: leftOffset ? leftOffset - 32 : 0, - opacity: showZapDialog || isHovering ? 1 : 0, - pointerEvents: - showZapDialog || isHovering ? "auto" : "none", - } + position: "fixed", + top: topOffset ? topOffset - 12 : 0, + left: leftOffset ? leftOffset - 32 : 0, + opacity: showZapDialog || isHovering ? 1 : 0, + pointerEvents: + showZapDialog || isHovering ? "auto" : "none", + } } > {zapTarget && ( diff --git a/src/element/follow-button.tsx b/src/element/follow-button.tsx index b14123b..a2ac276 100644 --- a/src/element/follow-button.tsx +++ b/src/element/follow-button.tsx @@ -12,7 +12,9 @@ export function LoggedInFollowButton({ value: string; }) { const login = useLogin(); - const { tags, content, timestamp } = login!.follows; + if (!login) return; + + const { tags, content, timestamp } = login.follows; const follows = tags.filter((t) => t.at(0) === tag); const isFollowing = follows.find((t) => t.at(1) === value); diff --git a/src/element/live-chat.css b/src/element/live-chat.css index 4f79691..8abd69e 100644 --- a/src/element/live-chat.css +++ b/src/element/live-chat.css @@ -325,8 +325,6 @@ text-transform: lowercase; color: #fff; font-size: 12px; - font-family: Outfit; - font-style: normal; font-weight: 500; line-height: 18px; } diff --git a/src/element/live-chat.tsx b/src/element/live-chat.tsx index fb917bd..04c2fe1 100644 --- a/src/element/live-chat.tsx +++ b/src/element/live-chat.tsx @@ -8,7 +8,7 @@ import { parseZap, encodeTLV, } from "@snort/system"; -import { unixNow } from "@snort/shared"; +import { unixNow, unwrap } from "@snort/shared"; import { useEffect, useMemo } from "react"; import uniqBy from "lodash.uniqby"; @@ -96,7 +96,7 @@ export function LiveChat({ const login = useLogin(); useEffect(() => { const pubkeys = [ - ...new Set(feed.zaps.flatMap((a) => [a.pubkey, findTag(a, "p")!])), + ...new Set(feed.zaps.flatMap((a) => [a.pubkey, unwrap(findTag(a, "p"))])), ]; System.ProfileLoader.TrackMetadata(pubkeys); return () => System.ProfileLoader.UntrackMetadata(pubkeys); diff --git a/src/element/new-stream.tsx b/src/element/new-stream.tsx index 38d87a4..ec216dd 100644 --- a/src/element/new-stream.tsx +++ b/src/element/new-stream.tsx @@ -9,6 +9,7 @@ import { StreamEditor, StreamEditorProps } from "./stream-editor"; import { useNavigate } from "react-router-dom"; import { eventLink, findTag } from "utils"; import { NostrProviderDialog } from "./nostr-provider-dialog"; +import { unwrap } from "@snort/shared"; function NewStream({ ev, onFinish }: StreamEditorProps) { const providers = useStreamProvider(); @@ -19,7 +20,7 @@ function NewStream({ ev, onFinish }: StreamEditorProps) { if (!currentProvider) { setCurrentProvider( ev !== undefined - ? providers.find((a) => a.name.toLowerCase() === "manual")! + ? unwrap(providers.find((a) => a.name.toLowerCase() === "manual")) : providers.at(0) ); } diff --git a/src/element/share-menu.tsx b/src/element/share-menu.tsx index f04aa4a..0995b34 100644 --- a/src/element/share-menu.tsx +++ b/src/element/share-menu.tsx @@ -1,9 +1,11 @@ import { Menu, MenuItem } from "@szhsin/react-menu"; import * as Dialog from "@radix-ui/react-dialog"; +import { unwrap } from "@snort/shared"; +import { NostrEvent, NostrPrefix, encodeTLV } from "@snort/system"; + import { Icon } from "./icon"; import { useState } from "react"; import { Textarea } from "./textarea"; -import { NostrEvent, NostrPrefix, encodeTLV } from "@snort/system"; import { findTag } from "utils"; import AsyncButton from "./async-button"; import { useLogin } from "hooks/login"; @@ -18,7 +20,7 @@ export function ShareMenu({ ev }: { ev: NostrEvent }) { const naddr = encodeTLV( NostrPrefix.Address, - findTag(ev, "d")!, + unwrap(findTag(ev, "d")), undefined, ev.kind, ev.pubkey diff --git a/src/element/stream-cards.tsx b/src/element/stream-cards.tsx index 16ea55e..6f4db7f 100644 --- a/src/element/stream-cards.tsx +++ b/src/element/stream-cards.tsx @@ -100,7 +100,7 @@ function Card({ canEdit, ev, cards }: CardProps) { ); function findTagByIdentifier(d: string) { - return tags.find((t) => t.at(1)!.endsWith(`:${d}`)); + return tags.find((t) => t[1].endsWith(`:${d}`)); } const [dropStyle, dropRef] = useDrop( @@ -293,7 +293,7 @@ function EditCard({ card, cards }: EditCardProps) { async function onCancel() { const pub = login?.publisher(); if (pub) { - const newTags = tags.filter((t) => !t.at(1)!.endsWith(`:${identifier}`)); + const newTags = tags.filter((t) => !t[1].endsWith(`:${identifier}`)); const userCardsEv = await pub.generic((eb) => { eb.kind(USER_CARDS).content(""); for (const tag of newTags) { @@ -408,7 +408,7 @@ export function StreamCardEditor({ pubkey, tags }: StreamCardEditorProps) { <>
{cards.map((ev) => ( - + ))} {isEditing && }
@@ -433,7 +433,7 @@ export function ReadOnlyStreamCards({ host }: StreamCardsProps) { return (
{cards.map((ev) => ( - + ))}
); diff --git a/src/element/textarea.tsx b/src/element/textarea.tsx index eec8f44..14f569f 100644 --- a/src/element/textarea.tsx +++ b/src/element/textarea.tsx @@ -53,11 +53,11 @@ export function Textarea({ emojis, ...props }: TextareaProps) { const userDataProvider = async (token: string) => { const cache = System.ProfileLoader.Cache; if (cache instanceof UserProfileCache) { - return cache.search(token); + return await cache.search(token); } }; - const emojiDataProvider = async (token: string) => { + const emojiDataProvider = (token: string) => { const results = emojis .map((t) => { return { diff --git a/public/fonts/outfit/outfit.css b/src/fonts/outfit/outfit.css similarity index 100% rename from public/fonts/outfit/outfit.css rename to src/fonts/outfit/outfit.css diff --git a/public/fonts/outfit/outfit_400_latin-ext.woff2 b/src/fonts/outfit/outfit_400_latin-ext.woff2 similarity index 100% rename from public/fonts/outfit/outfit_400_latin-ext.woff2 rename to src/fonts/outfit/outfit_400_latin-ext.woff2 diff --git a/public/fonts/outfit/outfit_400_latin.woff2 b/src/fonts/outfit/outfit_400_latin.woff2 similarity index 100% rename from public/fonts/outfit/outfit_400_latin.woff2 rename to src/fonts/outfit/outfit_400_latin.woff2 diff --git a/public/fonts/outfit/outfit_500_latin-ext.woff2 b/src/fonts/outfit/outfit_500_latin-ext.woff2 similarity index 100% rename from public/fonts/outfit/outfit_500_latin-ext.woff2 rename to src/fonts/outfit/outfit_500_latin-ext.woff2 diff --git a/public/fonts/outfit/outfit_500_latin.woff2 b/src/fonts/outfit/outfit_500_latin.woff2 similarity index 100% rename from public/fonts/outfit/outfit_500_latin.woff2 rename to src/fonts/outfit/outfit_500_latin.woff2 diff --git a/public/fonts/outfit/outfit_600_latin-ext.woff2 b/src/fonts/outfit/outfit_600_latin-ext.woff2 similarity index 100% rename from public/fonts/outfit/outfit_600_latin-ext.woff2 rename to src/fonts/outfit/outfit_600_latin-ext.woff2 diff --git a/public/fonts/outfit/outfit_600_latin.woff2 b/src/fonts/outfit/outfit_600_latin.woff2 similarity index 100% rename from public/fonts/outfit/outfit_600_latin.woff2 rename to src/fonts/outfit/outfit_600_latin.woff2 diff --git a/public/fonts/outfit/outfit_700_latin-ext.woff2 b/src/fonts/outfit/outfit_700_latin-ext.woff2 similarity index 100% rename from public/fonts/outfit/outfit_700_latin-ext.woff2 rename to src/fonts/outfit/outfit_700_latin-ext.woff2 diff --git a/public/fonts/outfit/outfit_700_latin.woff2 b/src/fonts/outfit/outfit_700_latin.woff2 similarity index 100% rename from public/fonts/outfit/outfit_700_latin.woff2 rename to src/fonts/outfit/outfit_700_latin.woff2 diff --git a/src/hooks/cards.ts b/src/hooks/cards.ts index 582f809..ad4376f 100644 --- a/src/hooks/cards.ts +++ b/src/hooks/cards.ts @@ -29,7 +29,7 @@ export function useUserCards( const subRelated = useMemo(() => { if (!pubkey) return null; - const splitted = related.map((t) => t.at(1)!.split(":")); + const splitted = related.map((t) => t[1].split(":")); const authors = splitted .map((s) => s.at(1)) .filter((s) => s) @@ -58,7 +58,7 @@ export function useUserCards( const cards = useMemo(() => { return related .map((t) => { - const [k, pubkey, identifier] = t.at(1)!.split(":"); + const [k, pubkey, identifier] = t[1].split(":"); const kind = Number(k); return (data ?? []).find( (e) => @@ -104,7 +104,7 @@ export function useCards(pubkey: string, leaveOpen = false): TaggedRawEvent[] { const subRelated = useMemo(() => { if (!pubkey) return null; - const splitted = related.map((t) => t.at(1)!.split(":")); + const splitted = related.map((t) => t[1].split(":")); const authors = splitted .map((s) => s.at(1)) .filter((s) => s) @@ -134,7 +134,7 @@ export function useCards(pubkey: string, leaveOpen = false): TaggedRawEvent[] { const cards = useMemo(() => { return related .map((t) => { - const [k, pubkey, identifier] = t.at(1)!.split(":"); + const [k, pubkey, identifier] = t[1].split(":"); const kind = Number(k); return cardEvents.find( (e) => diff --git a/src/hooks/emoji.tsx b/src/hooks/emoji.tsx index 3d77faf..c152515 100644 --- a/src/hooks/emoji.tsx +++ b/src/hooks/emoji.tsx @@ -45,7 +45,7 @@ export function useUserEmojiPacks(pubkey?: string, userEmoji?: Tags) { const subRelated = useMemo(() => { if (!pubkey) return null; - const splitted = related.map((t) => t.at(1)!.split(":")); + const splitted = related.map((t) => t[1].split(":")); const authors = splitted .map((s) => s.at(1)) .filter((s) => s) diff --git a/src/hooks/goals.ts b/src/hooks/goals.ts index 0321b0e..cee6762 100644 --- a/src/hooks/goals.ts +++ b/src/hooks/goals.ts @@ -9,6 +9,7 @@ import { parseZap, } from "@snort/system"; import { useRequestBuilder } from "@snort/system-react"; +import { unwrap } from "@snort/shared"; import { GOAL } from "const"; import { System } from "index"; @@ -43,7 +44,7 @@ export function useZapGoal(host: string, link: NostrLink, leaveOpen = false) { b.withFilter() .kinds([GOAL]) .authors([host]) - .tag("a", [`${link.kind}:${link.author!}:${link.id}`]); + .tag("a", [`${link.kind}:${unwrap(link.author)}:${link.id}`]); return b; }, [link, leaveOpen]); diff --git a/src/index.tsx b/src/index.tsx index 613a99d..60cb3c3 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -1,5 +1,6 @@ import "@szhsin/react-menu/dist/index.css"; import "./index.css"; +import "./fonts/outfit/outfit.css"; import React from "react"; import ReactDOM from "react-dom/client"; diff --git a/src/login.ts b/src/login.ts index dbb5b7a..c857932 100644 --- a/src/login.ts +++ b/src/login.ts @@ -1,6 +1,6 @@ import { bytesToHex } from "@noble/curves/abstract/utils"; import { schnorr } from "@noble/curves/secp256k1"; -import { ExternalStore } from "@snort/shared"; +import { ExternalStore, unwrap } from "@snort/shared"; import { EventPublisher, Nip7Signer, PrivateKeySigner } from "@snort/system"; import type { EmojiPack, Tags } from "types"; @@ -131,7 +131,7 @@ export function getPublisher(session: LoginSession) { } case LoginType.PrivateKey: { return new EventPublisher( - new PrivateKeySigner(session.privateKey!), + new PrivateKeySigner(unwrap(session.privateKey)), session.pubkey ); } diff --git a/src/pages/chat-popout.tsx b/src/pages/chat-popout.tsx index 392de5e..adc4e75 100644 --- a/src/pages/chat-popout.tsx +++ b/src/pages/chat-popout.tsx @@ -2,12 +2,13 @@ import "./chat-popout.css"; import { LiveChat } from "element/live-chat"; import { useParams } from "react-router-dom"; import { NostrPrefix, encodeTLV, parseNostrLink } from "@snort/system"; +import { unwrap } from "@snort/shared"; import { useCurrentStreamFeed } from "hooks/current-stream-feed"; import { findTag } from "utils"; export function ChatPopout() { const params = useParams(); - const link = parseNostrLink(params.id!); + const link = parseNostrLink(unwrap(params.id)); const ev = useCurrentStreamFeed(link, true); const lnk = parseNostrLink( diff --git a/src/pages/profile-page.tsx b/src/pages/profile-page.tsx index b4ad6fd..9ba74a3 100644 --- a/src/pages/profile-page.tsx +++ b/src/pages/profile-page.tsx @@ -10,6 +10,7 @@ import { encodeTLV, } from "@snort/system"; import { useUserProfile } from "@snort/system-react"; +import { unwrap } from "@snort/shared"; import { Profile } from "element/profile"; import { Icon } from "element/icon"; import { SendZapsDialog } from "element/send-zap"; @@ -52,7 +53,7 @@ const defaultBanner = "https://void.cat/d/Hn1AdN5UKmceuDkgDW847q.webp"; export function ProfilePage() { const navigate = useNavigate(); const params = useParams(); - const link = parseNostrLink(params.npub!); + const link = parseNostrLink(unwrap(params.npub)); const placeholder = usePlaceholder(link.id); const profile = useUserProfile(System, link.id); const zapTarget = profile?.lud16 ?? profile?.lud06; diff --git a/src/pages/stream-page.tsx b/src/pages/stream-page.tsx index e34c154..01ac6b3 100644 --- a/src/pages/stream-page.tsx +++ b/src/pages/stream-page.tsx @@ -1,5 +1,6 @@ import "./stream-page.css"; import { parseNostrLink, TaggedRawEvent } from "@snort/system"; +import { unwrap } from "@snort/shared"; import { useLocation, useNavigate, useParams } from "react-router-dom"; import { Helmet } from "react-helmet"; @@ -114,7 +115,7 @@ export function StreamPage() { const params = useParams(); const location = useLocation(); const evPreload = getEventFromLocationState(location.state); - const link = parseNostrLink(params.id!); + const link = parseNostrLink(unwrap(params.id)); const ev = useCurrentStreamFeed(link, true, evPreload); const host = getHost(ev); const goal = useZapGoal(host, link, true); diff --git a/src/pages/tag.tsx b/src/pages/tag.tsx index fa86be4..234c328 100644 --- a/src/pages/tag.tsx +++ b/src/pages/tag.tsx @@ -1,5 +1,6 @@ import "./tag.css"; import { useParams } from "react-router-dom"; +import { unwrap } from "@snort/shared"; import { VideoTile } from "element/video-tile"; import { FollowTagButton } from "element/follow-button"; @@ -12,7 +13,7 @@ export function TagPage() {

#{tag}

- +
{live.map((e) => ( diff --git a/src/providers/owncast.ts b/src/providers/owncast.ts index b828a65..58d6bc5 100644 --- a/src/providers/owncast.ts +++ b/src/providers/owncast.ts @@ -58,7 +58,7 @@ export class OwncastProvider implements StreamProvider { body?: unknown ): Promise { const rsp = await fetch(`${this.#url}${path}`, { - method: method, + method, body: body ? JSON.stringify(body) : undefined, headers: { "content-type": "application/json", diff --git a/src/providers/zsz.ts b/src/providers/zsz.ts index a84bcdc..2514901 100644 --- a/src/providers/zsz.ts +++ b/src/providers/zsz.ts @@ -103,7 +103,7 @@ export class Nip103StreamProvider implements StreamProvider { .tag(["method", method]); }); const rsp = await fetch(u, { - method: method, + method, body: body ? JSON.stringify(body) : undefined, headers: { "content-type": "application/json", diff --git a/src/utils.ts b/src/utils.ts index 331980c..57e9454 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -109,7 +109,7 @@ export function getHost(ev?: NostrEvent) { ); } -export async function openFile(): Promise { +export function openFile(): Promise { return new Promise((resolve) => { const elm = document.createElement("input"); elm.type = "file"; diff --git a/src/wish/index.ts b/src/wish/index.ts index a9ef6f7..e43188e 100644 --- a/src/wish/index.ts +++ b/src/wish/index.ts @@ -503,7 +503,7 @@ export class WISH extends TypedEventTarget { }, }); const body = await resp.text(); - if (resp.status != 201) { + if (resp.status !== 201) { throw new Error(`Unexpected status code ${resp.status}: ${body}`); } @@ -611,7 +611,7 @@ export class WISH extends TypedEventTarget { throw new Error(`Unexpected status code ${resp.status}: ${body}`); } - async WithEndpoint(endpoint: string, trickle: boolean) { + WithEndpoint(endpoint: string, trickle: boolean) { if (endpoint === "") { throw new Error("Endpoint cannot be empty"); } @@ -637,7 +637,7 @@ export class WISH extends TypedEventTarget { method: "DELETE", mode: "cors", }); - if (resp.status != 200) { + if (resp.status !== 200) { const body = await resp.text(); throw new Error(`Unexpected status code ${resp.status}: ${body}`); } diff --git a/webpack.config.js b/webpack.config.js index 140f67d..25805f7 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -45,7 +45,7 @@ const config = { { from: "public/robots.txt" }, { from: "public/icons.svg" }, { from: "public/logo.png" }, - { from: "_headers" }, + { from: "_headers" } ], }), new HtmlWebpackPlugin({