mirror of
https://github.com/hoornet/vega.git
synced 2026-04-24 06:40:01 -07:00
Show published note in feed immediately after posting
This commit is contained in:
@@ -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?.();
|
||||
|
||||
@@ -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[]> {
|
||||
|
||||
Reference in New Issue
Block a user