useNostrPublish returns the event

This commit is contained in:
Alex Gleason 2025-05-30 23:40:57 +02:00
parent 9221693edb
commit 79ed87e67c
No known key found for this signature in database
GPG Key ID: 7211D1F99744FBB7

View File

@ -1,21 +1,16 @@
import { useNostr } from "@nostrify/react"; import { useNostr } from "@nostrify/react";
import { useMutation } from "@tanstack/react-query"; import { useMutation, type UseMutationResult } from "@tanstack/react-query";
import { useCurrentUser } from "./useCurrentUser"; import { useCurrentUser } from "./useCurrentUser";
interface EventTemplate { import type { NostrEvent } from "@nostrify/nostrify";
kind: number;
content?: string;
tags?: string[][];
created_at?: number;
}
export function useNostrPublish() { export function useNostrPublish(): UseMutationResult<NostrEvent> {
const { nostr } = useNostr(); const { nostr } = useNostr();
const { user } = useCurrentUser(); const { user } = useCurrentUser();
return useMutation({ return useMutation({
mutationFn: async (t: EventTemplate) => { mutationFn: async (t: Omit<NostrEvent, 'id' | 'pubkey' | 'sig'>) => {
if (user) { if (user) {
const tags = t.tags ?? []; const tags = t.tags ?? [];
@ -33,6 +28,7 @@ export function useNostrPublish() {
}); });
await nostr.event(event, { signal: AbortSignal.timeout(5000) }); await nostr.event(event, { signal: AbortSignal.timeout(5000) });
return event;
} else { } else {
throw new Error("User is not logged in"); throw new Error("User is not logged in");
} }