feat: mute

This commit is contained in:
codytseng 2025-01-19 14:40:05 +08:00
parent 34ff0cd314
commit cbae26e492
26 changed files with 564 additions and 45 deletions

View file

@ -1,17 +1,21 @@
import { getProfileFromProfileEvent } from '@/lib/event'
import { userIdToPubkey } from '@/lib/pubkey'
import { useNostr } from '@/providers/NostrProvider'
import client from '@/services/client.service'
import storage from '@/services/storage.service'
import { TProfile } from '@/types'
import { useEffect, useMemo, useState } from 'react'
import { useEffect, 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])
const [pubkey, setPubkey] = useState<string | null>(null)
useEffect(() => {
setProfile(null)
setPubkey(null)
const fetchProfile = async () => {
setIsFetching(true)
try {
@ -21,6 +25,16 @@ export function useFetchProfile(id?: string) {
return
}
const pubkey = userIdToPubkey(id)
setPubkey(pubkey)
const storedProfileEvent = storage.getAccountProfileEvent(pubkey)
if (storedProfileEvent) {
const profile = getProfileFromProfileEvent(storedProfileEvent)
setProfile(profile)
setIsFetching(false)
return
}
const profile = await client.fetchProfile(id)
if (profile) {
setProfile(profile)