snort/packages/app/src/Pages/NostrLinkHandler.tsx

24 lines
742 B
TypeScript
Raw Normal View History

2023-02-14 13:35:12 +00:00
import { NostrPrefix } from "@snort/nostr";
2023-01-29 19:44:53 +00:00
import { useEffect } from "react";
2023-02-14 10:34:43 +00:00
import { useNavigate, useParams } from "react-router-dom";
2023-01-29 19:44:53 +00:00
export default function NostrLinkHandler() {
2023-02-14 10:34:43 +00:00
const params = useParams();
const navigate = useNavigate();
const link = decodeURIComponent(params["*"] ?? "");
2023-01-29 19:44:53 +00:00
2023-02-14 10:34:43 +00:00
useEffect(() => {
if (link.length > 0) {
const ls = link.split(":");
const entity = ls[1];
if (entity.startsWith(NostrPrefix.PublicKey) || entity.startsWith(NostrPrefix.Profile)) {
navigate(`/p/${entity}`);
} else if (entity.startsWith(NostrPrefix.Event) || entity.startsWith(NostrPrefix.Note)) {
navigate(`/e/${entity}`);
}
}
}, [link]);
2023-01-29 19:44:53 +00:00
2023-02-14 10:34:43 +00:00
return <>Could not handle {link}</>;
}