fix: type errors

This commit is contained in:
verbiricha 2023-08-12 19:36:32 +02:00
parent 5584eaea0a
commit 52b3c12a46
19 changed files with 88 additions and 63 deletions

View File

@ -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.at(1) as string, e.at(2) as string]);
});
}
}
@ -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,10 @@ export function ChatMessage({
<div className="message-reaction-container">
{isCustomEmojiReaction && emoji ? (
<span className="message-reaction">
<EmojiComponent name={emoji.at(1)!} url={emoji.at(2)!} />
<EmojiComponent
name={emoji.at(1) as string}
url={emoji.at(2) as string}
/>
</span>
) : (
<span className="message-reaction">{e}</span>

View File

@ -12,7 +12,11 @@ export function LoggedInFollowButton({
value: string;
}) {
const login = useLogin();
const { tags, content, timestamp } = login!.follows;
if (!login) {
return null;
}
const { tags, content, timestamp } = login.follows;
const follows = tags.filter((t) => t.at(0) === tag);
const isFollowing = follows.find((t) => t.at(1) === value);

View File

@ -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, findTag(a, "p") ?? ""])),
];
System.ProfileLoader.TrackMetadata(pubkeys);
return () => System.ProfileLoader.UntrackMetadata(pubkeys);

View File

@ -19,7 +19,7 @@ function NewStream({ ev, onFinish }: StreamEditorProps) {
if (!currentProvider) {
setCurrentProvider(
ev !== undefined
? providers.find((a) => a.name.toLowerCase() === "manual")!
? providers.find((a) => a.name.toLowerCase() === "manual")
: providers.at(0)
);
}
@ -35,7 +35,11 @@ function NewStream({ ev, onFinish }: StreamEditorProps) {
onFinish={(ex) => {
currentProvider.updateStreamInfo(ex);
if (!ev) {
if (findTag(ex, "content-warning") && __XXX_HOST && __XXX === false) {
if (
findTag(ex, "content-warning") &&
__XXX_HOST &&
__XXX === false
) {
location.href = `${__XXX_HOST}/${eventLink(ex)}`;
} else {
navigate(`/${eventLink(ex)}`, {

View File

@ -18,7 +18,7 @@ export function ShareMenu({ ev }: { ev: NostrEvent }) {
const naddr = encodeTLV(
NostrPrefix.Address,
findTag(ev, "d")!,
findTag(ev, "d") ?? "",
undefined,
ev.kind,
ev.pubkey

View File

@ -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.at(1) as string).endsWith(`:${d}`));
}
const [dropStyle, dropRef] = useDrop(
@ -293,7 +293,9 @@ 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.at(1) as string).endsWith(`:${identifier}`)
);
const userCardsEv = await pub.generic((eb) => {
eb.kind(USER_CARDS).content("");
for (const tag of newTags) {
@ -408,7 +410,7 @@ export function StreamCardEditor({ pubkey, tags }: StreamCardEditorProps) {
<>
<div className="stream-cards">
{cards.map((ev) => (
<Card canEdit={isEditing} cards={cards} key={ev.id} ev={ev!} />
<Card canEdit={isEditing} cards={cards} key={ev.id} ev={ev} />
))}
{isEditing && <AddCard cards={cards} />}
</div>
@ -433,7 +435,7 @@ export function ReadOnlyStreamCards({ host }: StreamCardsProps) {
return (
<div className="stream-cards">
{cards.map((ev) => (
<Card cards={cards} key={ev!.id} ev={ev!} />
<Card cards={cards} key={ev.id} ev={ev} />
))}
</div>
);

View File

@ -50,14 +50,14 @@ interface TextareaProps {
}
export function Textarea({ emojis, ...props }: TextareaProps) {
const userDataProvider = async (token: string) => {
const userDataProvider = (token: string) => {
const cache = System.ProfileLoader.Cache;
if (cache instanceof UserProfileCache) {
return cache.search(token);
}
};
const emojiDataProvider = async (token: string) => {
const emojiDataProvider = (token: string) => {
const results = emojis
.map((t) => {
return {

View File

@ -11,6 +11,7 @@ import { useRequestBuilder } from "@snort/system-react";
import { USER_CARDS, CARD } from "const";
import { findTag } from "utils";
import { System } from "index";
import { getAddresses } from "utils";
export function useUserCards(
pubkey: string,
@ -29,16 +30,7 @@ export function useUserCards(
const subRelated = useMemo(() => {
if (!pubkey) return null;
const splitted = related.map((t) => t.at(1)!.split(":"));
const authors = splitted
.map((s) => s.at(1))
.filter((s) => s)
.map((s) => s as string);
const identifiers = splitted
.map((s) => s.at(2))
.filter((s) => s)
.map((s) => s as string);
const { authors, identifiers } = getAddresses(related);
const rb = new RequestBuilder(`cards:${pubkey}`);
rb.withOptions({ leaveOpen })
.withFilter()
@ -58,7 +50,8 @@ export function useUserCards(
const cards = useMemo(() => {
return related
.map((t) => {
const [k, pubkey, identifier] = t.at(1)!.split(":");
const ref = t.at(1) as string;
const [k, pubkey, identifier] = ref.split(":");
const kind = Number(k);
return (data ?? []).find(
(e) =>
@ -104,15 +97,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 authors = splitted
.map((s) => s.at(1))
.filter((s) => s)
.map((s) => s as string);
const identifiers = splitted
.map((s) => s.at(2))
.filter((s) => s)
.map((s) => s as string);
const { authors, identifiers } = getAddresses(related);
const rb = new RequestBuilder(`cards:${pubkey}`);
rb.withOptions({ leaveOpen })
@ -134,7 +119,8 @@ export function useCards(pubkey: string, leaveOpen = false): TaggedRawEvent[] {
const cards = useMemo(() => {
return related
.map((t) => {
const [k, pubkey, identifier] = t.at(1)!.split(":");
const ref = t.at(1) as string;
const [k, pubkey, identifier] = ref.split(":");
const kind = Number(k);
return cardEvents.find(
(e) =>

View File

@ -45,7 +45,11 @@ 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.at(1))
.filter((t) => t)
.map((t) => t as string)
.map((t) => t.split(":"));
const authors = splitted
.map((s) => s.at(1))
.filter((s) => s)

View File

@ -43,7 +43,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}:${link.author as string}:${link.id}`]);
return b;
}, [link, leaveOpen]);

View File

@ -131,7 +131,7 @@ export function getPublisher(session: LoginSession) {
}
case LoginType.PrivateKey: {
return new EventPublisher(
new PrivateKeySigner(session.privateKey!),
new PrivateKeySigner(session.privateKey as string),
session.pubkey
);
}

View File

@ -7,7 +7,7 @@ import { findTag } from "utils";
export function ChatPopout() {
const params = useParams();
const link = parseNostrLink(params.id!);
const link = parseNostrLink(params.id as string);
const ev = useCurrentStreamFeed(link, true);
const lnk = parseNostrLink(

View File

@ -52,7 +52,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(params.npub as string);
const placeholder = usePlaceholder(link.id);
const profile = useUserProfile(System, link.id);
const zapTarget = profile?.lud16 ?? profile?.lud06;

View File

@ -114,7 +114,7 @@ export function StreamPage() {
const params = useParams();
const location = useLocation();
const evPreload = getEventFromLocationState(location.state);
const link = parseNostrLink(params.id!);
const link = parseNostrLink(params.id as string);
const ev = useCurrentStreamFeed(link, true, evPreload);
const host = getHost(ev);
const goal = useZapGoal(host, link, true);

View File

@ -1,5 +1,5 @@
import "./tag.css";
import { useParams } from "react-router-dom";
import { useParams, Navigate } from "react-router-dom";
import { VideoTile } from "element/video-tile";
import { FollowTagButton } from "element/follow-button";
@ -8,17 +8,22 @@ import { useStreamsFeed } from "hooks/live-streams";
export function TagPage() {
const { tag } = useParams();
const { live } = useStreamsFeed(tag);
return (
<div className="tag-page">
<div className="tag-page-header">
<h1>#{tag}</h1>
<FollowTagButton tag={tag!} />
if (typeof tag === "string") {
return (
<div className="tag-page">
<div className="tag-page-header">
<h1>#{tag}</h1>
<FollowTagButton tag={tag as string} />
</div>
<div className="video-grid">
{live.map((e) => (
<VideoTile ev={e} key={e.id} />
))}
</div>
</div>
<div className="video-grid">
{live.map((e) => (
<VideoTile ev={e} key={e.id} />
))}
</div>
</div>
);
);
}
return <Navigate to="/" replace={true} />;
}

View File

@ -58,7 +58,7 @@ export class OwncastProvider implements StreamProvider {
body?: unknown
): Promise<T> {
const rsp = await fetch(`${this.#url}${path}`, {
method: method,
method,
body: body ? JSON.stringify(body) : undefined,
headers: {
"content-type": "application/json",

View File

@ -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",

View File

@ -109,7 +109,7 @@ export function getHost(ev?: NostrEvent) {
);
}
export async function openFile(): Promise<File | undefined> {
export function openFile(): Promise<File | undefined> {
return new Promise((resolve) => {
const elm = document.createElement("input");
elm.type = "file";
@ -141,3 +141,20 @@ export function getEventFromLocationState(state: unknown | undefined | null) {
? (state as NostrEvent)
: undefined;
}
export function getAddresses(tags: Tags) {
const splitted = tags
.map((t) => t.at(1))
.filter((t) => t)
.map((t) => t as string)
.map((t) => t.split(":"));
const authors = splitted
.map((s) => s.at(1))
.filter((s) => s)
.map((s) => s as string);
const identifiers = splitted
.map((s) => s.at(2))
.filter((s) => s)
.map((s) => s as string);
return { authors, identifiers };
}

View File

@ -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}`);
}