mirror of
https://gitlab.com/soapbox-pub/mkstack.git
synced 2025-08-27 13:09:22 +00:00
useNostrPublish returns the event
This commit is contained in:
parent
9221693edb
commit
79ed87e67c
@ -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");
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user