diff --git a/components/widgets/GlobeCard.tsx b/components/widgets/GlobeCard.tsx index c27fa1f..3eefcb4 100644 --- a/components/widgets/GlobeCard.tsx +++ b/components/widgets/GlobeCard.tsx @@ -18,37 +18,45 @@ function countryCodeToFlag(code: string): string { return [...code.toUpperCase()].map(c => String.fromCodePoint(0x1f1e6 + c.charCodeAt(0) - 65)).join(''); } -function CountryChip({ country }: { country: CountryData }) { - const [expanded, setExpanded] = useState(false); - +function CountryChip({ country, isSelected, onSelect }: { country: CountryData; isSelected: boolean; onSelect: (code: string | null) => void }) { return ( -
- - {expanded && ( -
- {country.regions.map((r) => ( -
-
- {r.region} - {r.count} -
- {r.cities.map((c) => ( -
- {c.city} - {c.count} -
- ))} + + ); +} + +function CountryDetail({ country }: { country: CountryData }) { + return ( +
+
+ {countryCodeToFlag(country.code)} + {country.code} + {country.count} hits +
+ {country.regions.map((r) => ( +
+
+ {r.region} + {r.count} +
+ {r.cities.map((c) => ( +
+ {c.city} + {c.count}
))}
- )} + ))}
); } @@ -72,6 +80,7 @@ export function GlobeCard() { countries: [], }); const [grabbing, setGrabbing] = useState(false); + const [selectedCountry, setSelectedCountry] = useState(null); useEffect(() => { async function fetchVisitors() { @@ -190,9 +199,18 @@ export function GlobeCard() { {visitorStats.countries.length > 0 && (
+ {selectedCountry && (() => { + const country = visitorStats.countries.find(c => c.code === selectedCountry); + return country ? : null; + })()}
{visitorStats.countries.map((country) => ( - + ))}