import { replyAt } from "@/commons";
import { Note, Spinner, User } from "@/components";
import { LumeWindow, useEvent } from "@/system";
import { nip19 } from "nostr-tools";
import { type ReactNode, memo, useMemo } from "react";
import reactStringReplace from "react-string-replace";
import { Hashtag } from "./hashtag";
import { MentionUser } from "./user";
export const MentionNote = memo(function MentionNote({
eventId,
}: {
eventId: string;
}) {
const { isLoading, isError, error, data: event } = useEvent(eventId);
return (
{isLoading ? (
Loadng note
) : isError || !event ? (
{error?.message ??
"Cannot found this note within your current relay set"}
{eventId}
) : (
{event.content.length > 300 ? (
`${event.content.substring(0, 300)}...`
) : (
)}
{replyAt(event.created_at)}
)}
);
});
function Content({ text, className }: { text: string; className?: string }) {
const content = useMemo(() => {
let replacedText: ReactNode[] | string = text.trim();
const nostr = replacedText
.split(/\s+/)
.filter((w) => w.startsWith("nostr:"));
replacedText = reactStringReplace(text, /(https?:\/\/\S+)/g, (match, i) => (
{match}
));
replacedText = reactStringReplace(replacedText, /#(\w+)/g, (match, i) => (
));
for (const word of nostr) {
const bech32 = word.replace("nostr:", "").replace(/[^\w\s]/gi, "");
try {
const data = nip19.decode(bech32);
switch (data.type) {
case "npub":
replacedText = reactStringReplace(
replacedText,
word,
(match, i) => ,
);
break;
case "nprofile":
replacedText = reactStringReplace(
replacedText,
word,
(match, i) => (
),
);
break;
default:
replacedText = reactStringReplace(
replacedText,
word,
(match, i) => (
{match}
),
);
break;
}
} catch {
console.log(word);
}
}
return replacedText;
}, [text]);
return {content}
;
}