|
|
|
@ -2,7 +2,7 @@ import client from '@/services/client.service' |
|
|
|
import { Event } from 'nostr-tools' |
|
|
|
import { Event } from 'nostr-tools' |
|
|
|
import { useEffect, useState } from 'react' |
|
|
|
import { useEffect, useState } from 'react' |
|
|
|
|
|
|
|
|
|
|
|
export function useFetchEvent(id?: string) { |
|
|
|
export function useFetchEvent(eventId?: string) { |
|
|
|
const [isFetching, setIsFetching] = useState(true) |
|
|
|
const [isFetching, setIsFetching] = useState(true) |
|
|
|
const [error, setError] = useState<Error | null>(null) |
|
|
|
const [error, setError] = useState<Error | null>(null) |
|
|
|
const [event, setEvent] = useState<Event | undefined>(undefined) |
|
|
|
const [event, setEvent] = useState<Event | undefined>(undefined) |
|
|
|
@ -10,14 +10,14 @@ export function useFetchEvent(id?: string) { |
|
|
|
useEffect(() => { |
|
|
|
useEffect(() => { |
|
|
|
const fetchEvent = async () => { |
|
|
|
const fetchEvent = async () => { |
|
|
|
setIsFetching(true) |
|
|
|
setIsFetching(true) |
|
|
|
if (!id) { |
|
|
|
if (!eventId) { |
|
|
|
setIsFetching(false) |
|
|
|
setIsFetching(false) |
|
|
|
setError(new Error('No id provided')) |
|
|
|
setError(new Error('No id provided')) |
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
try { |
|
|
|
try { |
|
|
|
const event = await client.fetchEvent(id) |
|
|
|
const event = await client.fetchEvent(eventId) |
|
|
|
if (event) { |
|
|
|
if (event) { |
|
|
|
setEvent(event) |
|
|
|
setEvent(event) |
|
|
|
} |
|
|
|
} |
|
|
|
@ -32,7 +32,7 @@ export function useFetchEvent(id?: string) { |
|
|
|
setError(err as Error) |
|
|
|
setError(err as Error) |
|
|
|
setIsFetching(false) |
|
|
|
setIsFetching(false) |
|
|
|
}) |
|
|
|
}) |
|
|
|
}, [id]) |
|
|
|
}, [eventId]) |
|
|
|
|
|
|
|
|
|
|
|
return { isFetching, error, event } |
|
|
|
return { isFetching, error, event } |
|
|
|
} |
|
|
|
} |
|
|
|
|