feat: generate new account & profile editor
This commit is contained in:
@@ -1,11 +1,15 @@
|
||||
import { userIdToPubkey } from '@/lib/pubkey'
|
||||
import { useNostr } from '@/providers/NostrProvider'
|
||||
import client from '@/services/client.service'
|
||||
import { TProfile } from '@/types'
|
||||
import { useEffect, useState } from 'react'
|
||||
import { useEffect, useMemo, useState } from 'react'
|
||||
|
||||
export function useFetchProfile(id?: string) {
|
||||
const { profile: currentAccountProfile } = useNostr()
|
||||
const [isFetching, setIsFetching] = useState(true)
|
||||
const [error, setError] = useState<Error | null>(null)
|
||||
const [profile, setProfile] = useState<TProfile | null>(null)
|
||||
const pubkey = useMemo(() => (id ? userIdToPubkey(id) : undefined), [id])
|
||||
|
||||
useEffect(() => {
|
||||
const fetchProfile = async () => {
|
||||
@@ -31,5 +35,11 @@ export function useFetchProfile(id?: string) {
|
||||
fetchProfile()
|
||||
}, [id])
|
||||
|
||||
useEffect(() => {
|
||||
if (currentAccountProfile && pubkey === currentAccountProfile.pubkey) {
|
||||
setProfile(currentAccountProfile)
|
||||
}
|
||||
}, [currentAccountProfile])
|
||||
|
||||
return { isFetching, error, profile }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user