import React from 'react'; import { Avatar, AvatarImage, Box, Text, toRem } from 'folds'; import { NavItem, NavItemContent, NavLink } from '../../components/nav'; import { getBotPath } from '../../pages/pathUtils'; import { useMatrixClient } from '../../hooks/useMatrixClient'; import { useMediaAuthentication } from '../../hooks/useMediaAuthentication'; import { useUserProfile } from '../../hooks/useUserProfile'; import { mxcUrlToHttp } from '../../utils/matrix'; import type { BotPreset } from './catalog'; const MONO_FONT = '"JetBrains Mono Variable", ui-monospace, monospace'; const ROW_MIN_HEIGHT = toRem(56); const AVATAR_BG = '#7ab6d9'; type BotCardProps = { preset: BotPreset; selected?: boolean; }; export function BotCard({ preset, selected }: BotCardProps) { const mx = useMatrixClient(); const useAuthentication = useMediaAuthentication(); const initial = preset.name.trim().charAt(0).toUpperCase() || '?'; // Standard Matrix avatar resolution. `useUserProfile` returns the cached // profile synchronously and subscribes to live `UserEvent.AvatarUrl` // updates — when the operator sets the bot's `avatar_url` server-side // (mautrix-telegram bridge config), every BotCard remount picks it up // without client deploys. The fleet-blue letter square remains as the // fallback when the bot has no profile avatar yet. const { avatarUrl: avatarMxc } = useUserProfile(preset.mxid); const avatarUrl = avatarMxc ? mxcUrlToHttp(mx, avatarMxc, useAuthentication, 56, 56, 'crop') ?? undefined : undefined; return ( {avatarUrl ? ( ) : ( {initial} )} {preset.name} {preset.mxid} ); }