import { ImageWithFallback } from '@components/imageWithFallback'; import { createCacheProfile, getCacheProfile } from '@utils/storage'; import { truncate } from '@utils/truncate'; import { DotsHorizontalIcon } from '@radix-ui/react-icons'; import { fetch } from '@tauri-apps/api/http'; import Avatar from 'boring-avatars'; import dayjs from 'dayjs'; import relativeTime from 'dayjs/plugin/relativeTime'; import destr from 'destr'; import { useRouter } from 'next/router'; import { memo, useCallback, useEffect, useState } from 'react'; dayjs.extend(relativeTime); export const UserExtend = memo(function UserExtend({ pubkey, time }: { pubkey: string; time: any }) { const router = useRouter(); const [profile, setProfile] = useState(null); const openUserPage = (e) => { e.stopPropagation(); router.push(`/users/${pubkey}`); }; const fetchProfile = useCallback(async (id: string) => { const res = await fetch(`https://rbr.bio/${id}/metadata.json`, { method: 'GET', timeout: 30, }); return res.data; }, []); useEffect(() => { getCacheProfile(pubkey).then((res) => { if (res) { setProfile(destr(res.metadata)); } else { fetchProfile(pubkey) .then((res: any) => { setProfile(destr(res.content)); createCacheProfile(pubkey, res.content); }) .catch(console.error); } }); }, [fetchProfile, pubkey]); return (
openUserPage(e)} className="group flex items-start gap-2">
{profile?.picture ? ( ) : ( )}
{profile?.display_name || profile?.name || truncate(pubkey, 16, ' .... ')} ยท {dayjs().to(dayjs.unix(time))}
); });