mirror of
https://github.com/purrgrammer/grimoire.git
synced 2026-04-12 00:17:02 +02:00
fix: resolve TypeScript errors in EventMentionNode
Fix TypeScript compilation errors: 1. Fix eventStore import - use default import instead of named import 2. Add identifier attribute to EventMentionNode for naddr support 3. Remove redundant nip19.decode call in node view 4. Extract and store identifier when creating naddr nodes in paste handler Changes: - eventStore: named import → default import - Add identifier attribute to node attrs (for naddr d tag) - Use stored identifier instead of re-decoding in node view - Extract identifier from AddressPointer in paste handler - Simplifies logic and fixes type narrowing issues This eliminates the type comparison error where TypeScript couldn't determine that decoded.type matched decodedType at runtime.
This commit is contained in:
@@ -34,7 +34,7 @@ import type { EmojiSearchResult } from "@/services/emoji-search";
|
||||
import type { ChatAction } from "@/types/chat-actions";
|
||||
import { nip19 } from "nostr-tools";
|
||||
import { getKindName } from "@/constants/kinds";
|
||||
import { eventStore } from "@/services/event-store";
|
||||
import eventStore from "@/services/event-store";
|
||||
import { MemoizedInlineEventPreview } from "../nostr/InlineEventPreview";
|
||||
import type { NostrEvent } from "@/types/nostr";
|
||||
import { FileText } from "lucide-react";
|
||||
@@ -297,6 +297,7 @@ const EventMentionNode = Node.create({
|
||||
eventId: { default: null },
|
||||
kind: { default: null },
|
||||
pubkey: { default: null },
|
||||
identifier: { default: null }, // For naddr (d tag)
|
||||
};
|
||||
},
|
||||
|
||||
@@ -317,7 +318,8 @@ const EventMentionNode = Node.create({
|
||||
|
||||
addNodeView() {
|
||||
return ({ node }) => {
|
||||
const { decodedType, kind, nostrUri, eventId, pubkey } = node.attrs;
|
||||
const { decodedType, kind, nostrUri, eventId, pubkey, identifier } =
|
||||
node.attrs;
|
||||
|
||||
// Create wrapper span
|
||||
const dom = document.createElement("span");
|
||||
@@ -333,19 +335,14 @@ const EventMentionNode = Node.create({
|
||||
if (eventId) {
|
||||
// For note/nevent - try to get by ID
|
||||
event = eventStore.event(eventId);
|
||||
} else if (decodedType === "naddr" && kind !== null && pubkey) {
|
||||
// For naddr - try to get replaceable event
|
||||
// Get the identifier from the original naddr
|
||||
try {
|
||||
const decoded = nip19.decode(nostrUri.replace("nostr:", ""));
|
||||
if (decoded.type === "naddr") {
|
||||
const identifier = (decoded.data as nip19.AddressPointer)
|
||||
.identifier;
|
||||
event = eventStore.replaceable(kind, pubkey, identifier);
|
||||
}
|
||||
} catch {
|
||||
// Failed to decode, fall through to fallback
|
||||
}
|
||||
} else if (
|
||||
decodedType === "naddr" &&
|
||||
kind !== null &&
|
||||
pubkey &&
|
||||
identifier !== null
|
||||
) {
|
||||
// For naddr - try to get replaceable event using stored identifier
|
||||
event = eventStore.replaceable(kind, pubkey, identifier);
|
||||
}
|
||||
|
||||
// Render the component
|
||||
@@ -452,6 +449,7 @@ const EventMentionNode = Node.create({
|
||||
let eventId: string | null = null;
|
||||
let kind: number | null = null;
|
||||
let pubkey: string | null = null;
|
||||
let identifier: string | null = null;
|
||||
|
||||
if (decoded.type === "note") {
|
||||
decodedType = "note";
|
||||
@@ -468,6 +466,7 @@ const EventMentionNode = Node.create({
|
||||
const data = decoded.data as nip19.AddressPointer;
|
||||
kind = data.kind;
|
||||
pubkey = data.pubkey;
|
||||
identifier = data.identifier;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
@@ -484,6 +483,7 @@ const EventMentionNode = Node.create({
|
||||
eventId,
|
||||
kind,
|
||||
pubkey,
|
||||
identifier,
|
||||
}),
|
||||
);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user