import { useEffect, useState } from 'react' import type { Article } from '@/types/nostr' export function useExistingPresentation(params: { pubkey: string | null checkPresentationExists: () => Promise
}): { existingPresentation: Article | null; loadingPresentation: boolean } { const [existingPresentation, setExistingPresentation] = useState
(null) const [loadingPresentation, setLoadingPresentation] = useState(true) useEffect(() => { void loadExistingPresentation({ pubkey: params.pubkey, checkPresentationExists: params.checkPresentationExists, setExistingPresentation, setLoadingPresentation, }) }, [params.pubkey, params.checkPresentationExists]) return { existingPresentation, loadingPresentation } } async function loadExistingPresentation(params: { pubkey: string | null checkPresentationExists: () => Promise
setExistingPresentation: (value: Article | null) => void setLoadingPresentation: (value: boolean) => void }): Promise { if (!params.pubkey) { params.setLoadingPresentation(false) return } try { params.setExistingPresentation(await params.checkPresentationExists()) } catch (e) { console.error('[AuthorPresentationEditor] Error loading presentation:', e) } finally { params.setLoadingPresentation(false) } }