import * as Dialog from '@radix-ui/react-dialog'; import { memo, useEffect, useState } from 'react'; import { Link } from 'react-router-dom'; import { useStorage } from '@libs/storage/provider'; import { Image } from '@shared/image'; import { NIP05 } from '@shared/nip05'; import { TextNote } from '@shared/notes'; import { User } from '@shared/user'; import { useNostr } from '@utils/hooks/useNostr'; import { useProfile } from '@utils/hooks/useProfile'; import { displayNpub } from '@utils/shortenKey'; import { UserLatestPosts } from './userLatestPosts'; export const UserWithDrawer = memo(function UserWithDrawer({ pubkey, }: { pubkey: string; }) { const { addContact, removeContact } = useNostr(); const { db } = useStorage(); const { status, user } = useProfile(pubkey); const [followed, setFollowed] = useState(false); const followUser = (pubkey: string) => { try { addContact(pubkey); // update state setFollowed(true); } catch (error) { console.log(error); } }; const unfollowUser = (pubkey: string) => { try { removeContact(pubkey); // update state setFollowed(false); } catch (error) { console.log(error); } }; useEffect(() => { if (db.account.follows.includes(pubkey)) { setFollowed(true); } }, []); return (
{status === 'loading' ? (

Loading...

) : ( <>
{pubkey}
{user?.displayName || user?.name || 'No name'}
{user?.nip05 ? ( ) : ( {displayNpub(pubkey, 16)} )} {user?.about ? : null}
{followed ? ( ) : ( )} Message
)}
); });