feat: generate new account & profile editor

This commit is contained in:
codytseng
2025-01-14 18:09:31 +08:00
parent 3f031da748
commit 78629dd64f
33 changed files with 535 additions and 142 deletions

View File

@@ -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 }
}