import { BeakerIcon, CheckBadgeIcon } from "@heroicons/react/24/solid"; import getAccount from "@hey/helpers/getAccount"; import getAvatar from "@hey/helpers/getAvatar"; import { type AccountStats, useFullAccountLazyQuery } from "@hey/indexer"; import * as HoverCard from "@radix-ui/react-hover-card"; import plur from "plur"; import type { ReactNode } from "react"; import Markup from "@/components/Shared/Markup"; import Slug from "@/components/Shared/Slug"; import { Card, Image } from "@/components/Shared/UI"; import getMentions from "@/helpers/getMentions"; import nFormatter from "@/helpers/nFormatter"; import truncateByWords from "@/helpers/truncateByWords"; import ENSBadge from "./ENSBadge"; import FollowUnfollowButton from "./FollowUnfollowButton"; interface AccountPreviewProps { children: ReactNode; username?: string; address?: string; showUserPreview?: boolean; } const AccountPreview = ({ children, username, address, showUserPreview = true }: AccountPreviewProps) => { const [loadAccount, { data, loading }] = useFullAccountLazyQuery(); const account = data?.account; const stats = data?.accountStats as AccountStats; const onPreviewStart = async () => { if (account || loading) { return; } await loadAccount({ variables: { accountRequest: { ...(address ? { address } : { username: { localName: username as string } }) }, accountStatsRequest: { account: address } } }); }; if (!address && !username) { return null; } if (!showUserPreview) { return {children}; } const Preview = () => { if (loading) { return (
{username || `#${address}`}
); } if (!account) { return (
No account found
); } const UserAvatar = () => ( {account.address} ); const UserName = () => (
{getAccount(account).name}
{account.hasSubscribed && ( )} {account.isBeta && }
{account.operations?.isFollowingMe && ( Follows you )}
); return (
{account.metadata?.bio && (
{truncateByWords(account.metadata.bio, 20)}
)}
{nFormatter(stats.graphFollowStats?.following)}
Following
{nFormatter(stats.graphFollowStats?.followers)}
{plur("Follower", stats.graphFollowStats?.followers)}
); }; return ( {children}
); }; export default AccountPreview;