fix: use preload event in link handler
This commit is contained in:
@ -1,11 +1,12 @@
|
|||||||
|
import { NIP5_DOMAIN } from "@/const";
|
||||||
import { fetchNip05Pubkey } from "@snort/shared";
|
import { fetchNip05Pubkey } from "@snort/shared";
|
||||||
import { NostrLink, NostrPrefix, tryParseNostrLink } from "@snort/system";
|
import { NostrEvent, NostrLink, NostrPrefix, tryParseNostrLink } from "@snort/system";
|
||||||
import { useEffect, useState } from "react";
|
import { useEffect, useState } from "react";
|
||||||
import { useParams } from "react-router-dom";
|
import { useParams } from "react-router-dom";
|
||||||
|
|
||||||
export function useStreamLink() {
|
export function useStreamLink(evPreload?: NostrEvent) {
|
||||||
const params = useParams();
|
const params = useParams();
|
||||||
const [link, setLink] = useState<NostrLink>();
|
const [link, setLink] = useState<NostrLink | undefined>(evPreload ? NostrLink.fromEvent(evPreload) : undefined);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (params.id) {
|
if (params.id) {
|
||||||
@ -13,7 +14,7 @@ export function useStreamLink() {
|
|||||||
if (parsedLink) {
|
if (parsedLink) {
|
||||||
setLink(parsedLink);
|
setLink(parsedLink);
|
||||||
} else {
|
} else {
|
||||||
const [handle, domain] = (params.id.includes("@") ? params.id : `${params.id}@zap.stream`).split("@");
|
const [handle, domain] = (params.id.includes("@") ? params.id : `${params.id}@${NIP5_DOMAIN}`).split("@");
|
||||||
fetchNip05Pubkey(handle, domain).then(d => {
|
fetchNip05Pubkey(handle, domain).then(d => {
|
||||||
if (d) {
|
if (d) {
|
||||||
setLink(new NostrLink(NostrPrefix.PublicKey, d));
|
setLink(new NostrLink(NostrPrefix.PublicKey, d));
|
||||||
|
@ -14,7 +14,7 @@ import { ShortPage } from "./short";
|
|||||||
export function LinkHandler() {
|
export function LinkHandler() {
|
||||||
const location = useLocation();
|
const location = useLocation();
|
||||||
const evPreload = getEventFromLocationState(location.state);
|
const evPreload = getEventFromLocationState(location.state);
|
||||||
const link = useStreamLink();
|
const link = useStreamLink(evPreload);
|
||||||
const layoutContext = useLayout();
|
const layoutContext = useLayout();
|
||||||
|
|
||||||
if (!link) return;
|
if (!link) return;
|
||||||
|
Reference in New Issue
Block a user