import { RefreshButton } from '@/components/RefreshButton' import UserAvatar from '@/components/UserAvatar' import Username from '@/components/Username' import { Button } from '@/components/ui/button' import { Skeleton } from '@/components/ui/skeleton' import { useSecondaryPage } from '@/contexts/secondary-page-context' import { usePrimaryNoteView } from '@/contexts/primary-note-view-context' import { useFetchProfile } from '@/hooks/useFetchProfile' import { useProfileInteractionPartners } from '@/hooks/useProfileInteractionPartners' import SecondaryPageLayout from '@/layouts/SecondaryPageLayout' import { toProfile } from '@/lib/link' import { forwardRef, useCallback, useEffect, useImperativeHandle, useRef, useState } from 'react' import { useTranslation } from 'react-i18next' import type { TPageRef } from '@/types' import dayjs from 'dayjs' import relativeTime from 'dayjs/plugin/relativeTime' dayjs.extend(relativeTime) const ProfileInteractionDiagramPage = forwardRef< TPageRef, { id?: string; index?: number; hideTitlebar?: boolean } >(({ id, index, hideTitlebar = false }, ref) => { const { t } = useTranslation() const { registerPrimaryPanelRefresh } = usePrimaryNoteView() const { push } = useSecondaryPage() const { profile } = useFetchProfile(id) const [refreshNonce, setRefreshNonce] = useState(0) const bump = useCallback(() => setRefreshNonce((n) => n + 1), []) const { partners, loading, rescan, archiveAuthorEvents, sessionEventCount } = useProfileInteractionPartners( profile?.pubkey, refreshNonce ) const layoutRef = useRef(null) useImperativeHandle( ref, () => ({ scrollToTop: (behavior?: ScrollBehavior) => layoutRef.current?.scrollToTop(behavior), refresh: () => { void rescan() bump() } }), [rescan, bump] ) useEffect(() => { if (!hideTitlebar) { registerPrimaryPanelRefresh(null) return } registerPrimaryPanelRefresh(() => { void rescan() bump() }) return () => registerPrimaryPanelRefresh(null) }, [hideTitlebar, registerPrimaryPanelRefresh, rescan, bump]) const nowSec = dayjs().unix() const maxCount = partners[0]?.mentionCount ?? 1 const maxAgeSec = Math.max(1, 180 * 86400) return ( void rescan()} />} displayScrollToTopButton >

{t('interactionMapSubtitle')}

{t('interactionMapSessionNotes', { count: sessionEventCount })} {t('interactionMapArchiveNotes', { count: archiveAuthorEvents })}
{loading && partners.length === 0 ? (
{Array.from({ length: 15 }).map((_, i) => ( ))}
) : partners.length === 0 ? (
{t('interactionMapEmpty')}
) : (
{partners.slice(0, 72).map((p) => { const countNorm = Math.min(1, p.mentionCount / maxCount) const age = Math.max(0, nowSec - p.lastReferencedAt) const recencyNorm = 1 - Math.min(1, age / maxAgeSec) const heat = 0.55 * countNorm + 0.45 * recencyNorm const bgAlpha = 0.12 + heat * 0.55 const borderAlpha = 0.25 + heat * 0.65 return ( ) })}
)}
) }) ProfileInteractionDiagramPage.displayName = 'ProfileInteractionDiagramPage' export default ProfileInteractionDiagramPage