import React from 'react'; import { faviconUrlFor } from './helpers'; interface NewCompetitorEntry { domain?: string | null; name?: string | null; share_of_voice?: number | null; [key: string]: unknown; } interface NewCompetitorsBannerProps { newCompetitors: Record[] | undefined | null; } const CompetitorChip = ({ entry, }: { entry: NewCompetitorEntry; }): JSX.Element => { const domain = (entry.domain || '').trim(); const name = (entry.name || '').trim() || domain; const sov = typeof entry.share_of_voice === 'number' && Number.isFinite(entry.share_of_voice) ? entry.share_of_voice : null; return ( { (event.currentTarget as HTMLImageElement).style.visibility = 'hidden'; }} style={{ borderRadius: 3 }} /> {name} {sov !== null && ( {`${sov}%`} )} ); }; /** * Warning banner that surfaces competitors which entered the weekly * leaderboard for the first time. Renders nothing when there are no new * competitors for the selected week. */ const NewCompetitorsBanner = ({ newCompetitors, }: NewCompetitorsBannerProps): JSX.Element | null => { if (!Array.isArray(newCompetitors) || newCompetitors.length === 0) return null; const entries: NewCompetitorEntry[] = newCompetitors .filter( (raw): raw is Record => !!raw && typeof raw === 'object' ) .map(raw => raw as NewCompetitorEntry) .filter( entry => typeof entry.domain === 'string' && entry.domain.trim() !== '' ); if (entries.length === 0) return null; return (

{entries.length} new competitor{entries.length === 1 ? '' : 's'} entered your leaderboard this week

{entries.map((entry, idx) => ( ))}
); }; export default NewCompetitorsBanner;