workspace with decoupled nostr package
This commit is contained in:
23
packages/app/src/Pages/NostrLinkHandler.tsx
Normal file
23
packages/app/src/Pages/NostrLinkHandler.tsx
Normal file
@ -0,0 +1,23 @@
|
||||
import { NostrPrefix } from "Nostr/Links";
|
||||
import { useEffect } from "react";
|
||||
import { useNavigate, useParams } from "react-router-dom";
|
||||
|
||||
export default function NostrLinkHandler() {
|
||||
const params = useParams();
|
||||
const navigate = useNavigate();
|
||||
const link = decodeURIComponent(params["*"] ?? "");
|
||||
|
||||
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]);
|
||||
|
||||
return <>Could not handle {link}</>;
|
||||
}
|
Reference in New Issue
Block a user