return note or profile component directly from NostrLinkHandler
This commit is contained in:
@ -205,9 +205,10 @@ const TierThree = ({ active, isLastSubthread, notes, related, chains, onNavigate
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
export function ThreadRoute() {
|
export function ThreadRoute({ id }: { id?: string }) {
|
||||||
const params = useParams();
|
const params = useParams();
|
||||||
const link = parseNostrLink(params.id ?? "", NostrPrefix.Note);
|
const resolvedId = id ?? params.id;
|
||||||
|
const link = parseNostrLink(resolvedId ?? "", NostrPrefix.Note);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<ThreadContextWrapper link={link}>
|
<ThreadContextWrapper link={link}>
|
||||||
|
@ -1,32 +1,33 @@
|
|||||||
import { NostrPrefix, tryParseNostrLink } from "@snort/system";
|
import { NostrPrefix, tryParseNostrLink } from "@snort/system";
|
||||||
import { useEffect, useState } from "react";
|
import { useEffect, useState } from "react";
|
||||||
import FormattedMessage from "Element/FormattedMessage";
|
import FormattedMessage from "Element/FormattedMessage";
|
||||||
import { useNavigate, useParams } from "react-router-dom";
|
import { useParams } from "react-router-dom";
|
||||||
|
|
||||||
import Spinner from "Icons/Spinner";
|
import Spinner from "Icons/Spinner";
|
||||||
import { profileLink } from "SnortUtils";
|
|
||||||
import { getNip05PubKey } from "Pages/LoginPage";
|
import { getNip05PubKey } from "Pages/LoginPage";
|
||||||
|
import ProfilePage from "Pages/Profile/ProfilePage";
|
||||||
|
import { ThreadRoute } from "Element/Event/Thread";
|
||||||
|
|
||||||
export default function NostrLinkHandler() {
|
export default function NostrLinkHandler() {
|
||||||
const params = useParams();
|
const params = useParams();
|
||||||
const navigate = useNavigate();
|
|
||||||
|
|
||||||
const [loading, setLoading] = useState(true);
|
const [loading, setLoading] = useState(true);
|
||||||
|
const [renderComponent, setRenderComponent] = useState<React.ReactNode | null>(null);
|
||||||
|
|
||||||
const link = decodeURIComponent(params["*"] ?? "").toLowerCase();
|
const link = decodeURIComponent(params["*"] ?? "").toLowerCase();
|
||||||
|
|
||||||
async function handleLink(link: string) {
|
async function handleLink(link: string) {
|
||||||
const nav = tryParseNostrLink(link);
|
const nav = tryParseNostrLink(link);
|
||||||
if (nav) {
|
if (nav) {
|
||||||
if (nav.type === NostrPrefix.Event || nav.type === NostrPrefix.Note || nav.type === NostrPrefix.Address) {
|
if (nav.type === NostrPrefix.Event || nav.type === NostrPrefix.Note || nav.type === NostrPrefix.Address) {
|
||||||
navigate(`/e/${nav.encode()}`);
|
setRenderComponent(<ThreadRoute id={nav.encode()} />); // Directly render ThreadRoute
|
||||||
} else if (nav.type === NostrPrefix.PublicKey || nav.type === NostrPrefix.Profile) {
|
} else if (nav.type === NostrPrefix.PublicKey || nav.type === NostrPrefix.Profile) {
|
||||||
navigate(`/p/${nav.encode()}`);
|
setRenderComponent(<ProfilePage id={nav.encode()} />); // Directly render ProfilePage
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
const pubkey = await getNip05PubKey(`${link}@${process.env.NIP05_DOMAIN}`);
|
const pubkey = await getNip05PubKey(`${link}@${process.env.NIP05_DOMAIN}`);
|
||||||
if (pubkey) {
|
if (pubkey) {
|
||||||
navigate(profileLink(pubkey));
|
setRenderComponent(<ProfilePage id={pubkey} />); // Directly render ProfilePage
|
||||||
}
|
}
|
||||||
} catch {
|
} catch {
|
||||||
//ignored
|
//ignored
|
||||||
@ -41,6 +42,10 @@ export default function NostrLinkHandler() {
|
|||||||
}
|
}
|
||||||
}, [link]);
|
}, [link]);
|
||||||
|
|
||||||
|
if (renderComponent) {
|
||||||
|
return renderComponent;
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="flex f-center">
|
<div className="flex f-center">
|
||||||
{loading ? (
|
{loading ? (
|
||||||
|
@ -52,7 +52,11 @@ import ProfileTab, {
|
|||||||
} from "Pages/Profile/ProfileTab";
|
} from "Pages/Profile/ProfileTab";
|
||||||
import DisplayName from "../../Element/User/DisplayName";
|
import DisplayName from "../../Element/User/DisplayName";
|
||||||
|
|
||||||
export default function ProfilePage() {
|
interface ProfilePageProps {
|
||||||
|
id?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function ProfilePage({ id: propId }: ProfilePageProps) {
|
||||||
const params = useParams();
|
const params = useParams();
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const [id, setId] = useState<string>();
|
const [id, setId] = useState<string>();
|
||||||
@ -95,21 +99,22 @@ export default function ProfilePage() {
|
|||||||
const horizontalScroll = useHorizontalScroll();
|
const horizontalScroll = useHorizontalScroll();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (params.id?.match(EmailRegex)) {
|
const resolvedId = propId || params.id;
|
||||||
getNip05PubKey(params.id).then(a => {
|
if (resolvedId?.match(EmailRegex)) {
|
||||||
|
getNip05PubKey(resolvedId).then(a => {
|
||||||
setId(a);
|
setId(a);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
const nav = tryParseNostrLink(params.id ?? "");
|
const nav = tryParseNostrLink(resolvedId ?? "");
|
||||||
if (nav?.type === NostrPrefix.PublicKey || nav?.type === NostrPrefix.Profile) {
|
if (nav?.type === NostrPrefix.PublicKey || nav?.type === NostrPrefix.Profile) {
|
||||||
// todo: use relays if any for nprofile
|
// todo: use relays if any for nprofile
|
||||||
setId(nav.id);
|
setId(nav.id);
|
||||||
} else {
|
} else {
|
||||||
setId(parseId(params.id ?? ""));
|
setId(parseId(resolvedId ?? ""));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
setTab(ProfileTab.Notes);
|
setTab(ProfileTab.Notes);
|
||||||
}, [params]);
|
}, [propId, params]);
|
||||||
|
|
||||||
function musicStatus() {
|
function musicStatus() {
|
||||||
if (!status.music) return;
|
if (!status.music) return;
|
||||||
|
Reference in New Issue
Block a user