import { Link } from 'react-router-dom' import { useAppState } from '#components/AppShell/hooks/useAppState' import { useItems } from '#components/Map/hooks/useItems' import { useAttestations } from '#components/Profile/hooks/useAttestations' import { timeAgo } from '#utils/TimeAgo' import type { Item } from '#types/Item' interface Props { item: Item heading?: string hideWhenEmpty?: boolean } export const AttestationsView = ({ item, heading = 'Trust', hideWhenEmpty = true }: Props) => { const attestations = useAttestations() const items = useItems() const appState = useAppState() const getUserProfile = (userId: string) => { return items.find((i) => i.user_created?.id === userId && i.layer?.userProfileLayer) } // Filter attestations for this user const userAttestations = attestations .filter((a) => a.to.some((t) => t.directus_users_id === item.user_created?.id)) .sort((a, b) => new Date(b.date_created).getTime() - new Date(a.date_created).getTime()) if (hideWhenEmpty && userAttestations.length === 0) { return null } return (

{heading}

{userAttestations.map((a, i) => ( ))}
{a.emoji}
{a.text}
{getUserProfile(a.user_created.id) ? (
{getUserProfile(a.user_created.id)?.image && ( Avatar )}
{getUserProfile(a.user_created.id)?.name ?? a.user_created.first_name}{' '}
{timeAgo(a.date_created)}
) : (
{a.user_created.first_name}
{timeAgo(a.date_created)}
)}
) }