import { useQuery } from '@tanstack/react-query'; import { useEffect, useState } from 'react'; import { FollowIcon, LoaderIcon, UnfollowIcon } from '@shared/icons'; import { Image } from '@shared/image'; import { DEFAULT_AVATAR } from '@stores/constants'; import { useSocial } from '@utils/hooks/useSocial'; import { compactNumber } from '@utils/number'; import { shortenKey } from '@utils/shortenKey'; export function Profile({ data }: { data: any }) { const { status: socialStatus, userFollows, follow, unfollow } = useSocial(); const { status, data: userStats } = useQuery( ['user-stats', data.pubkey], async () => { const res = await fetch(`https://api.nostr.band/v0/stats/profile/${data.pubkey}`); return res.json(); }, { refetchOnMount: false, refetchOnReconnect: false, refetchOnWindowFocus: false, staleTime: Infinity, } ); const embedProfile = data.profile ? JSON.parse(data.profile.content) : null; const profile = embedProfile; const [followed, setFollowed] = useState(false); const followUser = (pubkey: string) => { try { follow(pubkey); // update state setFollowed(true); } catch (error) { console.log(error); } }; const unfollowUser = (pubkey: string) => { try { unfollow(pubkey); // update state setFollowed(false); } catch (error) { console.log(error); } }; useEffect(() => { if (status === 'success' && userFollows) { if (userFollows.includes(data.pubkey)) { setFollowed(true); } } }, [status]); if (!profile) { return (
Can't fetch profile
{profile.nip05 || shortenKey(data.pubkey)}
{profile.about || profile.bio}
Loading...
) : (