forked from Kieran/zap.stream
nip5 handles
This commit is contained in:
parent
c191a7684a
commit
7cba67e4c1
@ -37,8 +37,9 @@ export function useZaps(goal: NostrEvent, leaveOpen = false) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function useZapGoal(host: string, link: NostrLink, leaveOpen = false) {
|
export function useZapGoal(host: string, link?: NostrLink, leaveOpen = false) {
|
||||||
const sub = useMemo(() => {
|
const sub = useMemo(() => {
|
||||||
|
if (!link) return null;
|
||||||
const b = new RequestBuilder(`goals:${host.slice(0, 12)}`);
|
const b = new RequestBuilder(`goals:${host.slice(0, 12)}`);
|
||||||
b.withOptions({ leaveOpen });
|
b.withOptions({ leaveOpen });
|
||||||
b.withFilter()
|
b.withFilter()
|
||||||
|
@ -11,7 +11,7 @@ import { RootPage } from "pages/root";
|
|||||||
import { TagPage } from "pages/tag";
|
import { TagPage } from "pages/tag";
|
||||||
import { LayoutPage } from "pages/layout";
|
import { LayoutPage } from "pages/layout";
|
||||||
import { ProfilePage } from "pages/profile-page";
|
import { ProfilePage } from "pages/profile-page";
|
||||||
import { StreamPage } from "pages/stream-page";
|
import { StreamPageHandler } from "pages/stream-page";
|
||||||
import { ChatPopout } from "pages/chat-popout";
|
import { ChatPopout } from "pages/chat-popout";
|
||||||
import { LoginStore } from "login";
|
import { LoginStore } from "login";
|
||||||
import { StreamProvidersPage } from "pages/providers";
|
import { StreamProvidersPage } from "pages/providers";
|
||||||
@ -54,7 +54,7 @@ const router = createBrowserRouter([
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
path: "/:id",
|
path: "/:id",
|
||||||
element: <StreamPage />,
|
element: <StreamPageHandler />,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
path: "/providers/:id?",
|
path: "/providers/:id?",
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import "./stream-page.css";
|
import "./stream-page.css";
|
||||||
import { parseNostrLink, TaggedRawEvent } from "@snort/system";
|
import { NostrLink, NostrPrefix, TaggedRawEvent, tryParseNostrLink } from "@snort/system";
|
||||||
import { unwrap } from "@snort/shared";
|
import { fetchNip05Pubkey } from "@snort/shared";
|
||||||
import { useLocation, useNavigate, useParams } from "react-router-dom";
|
import { useLocation, useNavigate, useParams } from "react-router-dom";
|
||||||
import { Helmet } from "react-helmet";
|
import { Helmet } from "react-helmet";
|
||||||
|
|
||||||
@ -10,6 +10,7 @@ import {
|
|||||||
findTag,
|
findTag,
|
||||||
getEventFromLocationState,
|
getEventFromLocationState,
|
||||||
getHost,
|
getHost,
|
||||||
|
hexToBech32,
|
||||||
} from "utils";
|
} from "utils";
|
||||||
import { Profile, getName } from "element/profile";
|
import { Profile, getName } from "element/profile";
|
||||||
import { LiveChat } from "element/live-chat";
|
import { LiveChat } from "element/live-chat";
|
||||||
@ -32,6 +33,7 @@ import {
|
|||||||
isContentWarningAccepted,
|
isContentWarningAccepted,
|
||||||
} from "element/content-warning";
|
} from "element/content-warning";
|
||||||
import { useCurrentStreamFeed } from "hooks/current-stream-feed";
|
import { useCurrentStreamFeed } from "hooks/current-stream-feed";
|
||||||
|
import { useEffect, useState } from "react";
|
||||||
|
|
||||||
function ProfileInfo({ ev, goal }: { ev?: NostrEvent; goal?: TaggedRawEvent }) {
|
function ProfileInfo({ ev, goal }: { ev?: NostrEvent; goal?: TaggedRawEvent }) {
|
||||||
const login = useLogin();
|
const login = useLogin();
|
||||||
@ -111,14 +113,41 @@ function ProfileInfo({ ev, goal }: { ev?: NostrEvent; goal?: TaggedRawEvent }) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function StreamPage() {
|
export function StreamPageHandler() {
|
||||||
const params = useParams();
|
const params = useParams();
|
||||||
const location = useLocation();
|
const location = useLocation();
|
||||||
const evPreload = getEventFromLocationState(location.state);
|
const evPreload = getEventFromLocationState(location.state);
|
||||||
const link = parseNostrLink(unwrap(params.id));
|
const [link, setLink] = useState<NostrLink>();
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (params.id) {
|
||||||
|
const parsedLink = tryParseNostrLink(params.id);
|
||||||
|
if (parsedLink) {
|
||||||
|
setLink(parsedLink);
|
||||||
|
} else {
|
||||||
|
const [handle, domain] = (params.id.includes("@") ? params.id : `${params.id}@zap.stream`).split("@");
|
||||||
|
fetchNip05Pubkey(handle, domain).then(d => {
|
||||||
|
if (d) {
|
||||||
|
setLink({
|
||||||
|
id: d,
|
||||||
|
type: NostrPrefix.PublicKey,
|
||||||
|
encode: () => hexToBech32(NostrPrefix.PublicKey, d)
|
||||||
|
} as NostrLink);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, [params.id]);
|
||||||
|
|
||||||
|
if (link) {
|
||||||
|
return <StreamPage link={link} evPreload={evPreload} />
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export function StreamPage({ link, evPreload }: { evPreload?: NostrEvent, link: NostrLink }) {
|
||||||
const ev = useCurrentStreamFeed(link, true, evPreload);
|
const ev = useCurrentStreamFeed(link, true, evPreload);
|
||||||
const host = getHost(ev);
|
const host = getHost(ev);
|
||||||
const goal = useZapGoal(host, link, true);
|
const goal = useZapGoal(host, createNostrLink(ev), true);
|
||||||
|
|
||||||
const title = findTag(ev, "title");
|
const title = findTag(ev, "title");
|
||||||
const summary = findTag(ev, "summary");
|
const summary = findTag(ev, "summary");
|
||||||
|
Loading…
Reference in New Issue
Block a user