Show published note in feed immediately after posting

This commit is contained in:
Jure
2026-03-13 18:08:40 +01:00
parent 176cbe8ae3
commit 7c10423b4a
2 changed files with 9 additions and 2 deletions

View File

@@ -2,6 +2,7 @@ import { useState, useRef } from "react";
import { publishNote } from "../../lib/nostr";
import { uploadImage } from "../../lib/upload";
import { useUserStore } from "../../stores/user";
import { useFeedStore } from "../../stores/feed";
import { shortenPubkey } from "../../lib/utils";
export function ComposeBox({ onPublished }: { onPublished?: () => void }) {
@@ -59,7 +60,12 @@ export function ComposeBox({ onPublished }: { onPublished?: () => void }) {
setPublishing(true);
setError(null);
try {
await publishNote(text.trim());
const event = await publishNote(text.trim());
// Inject into feed immediately so the user sees their post
const { notes } = useFeedStore.getState();
useFeedStore.setState({
notes: [event, ...notes],
});
setText("");
textareaRef.current?.focus();
onPublished?.();

View File

@@ -205,7 +205,7 @@ export async function publishReply(content: string, replyTo: { id: string; pubke
await event.publish();
}
export async function publishNote(content: string): Promise<void> {
export async function publishNote(content: string): Promise<NDKEvent> {
const instance = getNDK();
if (!instance.signer) throw new Error("Not logged in");
@@ -213,6 +213,7 @@ export async function publishNote(content: string): Promise<void> {
event.kind = NDKKind.Text;
event.content = content;
await event.publish();
return event;
}
export async function fetchReplies(eventId: string): Promise<NDKEvent[]> {