From 80beff02fa234230d52c9fcf3809fe8ed8afbc66 Mon Sep 17 00:00:00 2001 From: Heidi Date: Sat, 16 May 2026 08:16:35 +0100 Subject: [PATCH] update viewers page --- src/App.jsx | 37 +++++++++++++++++++++++++++---------- 1 file changed, 27 insertions(+), 10 deletions(-) diff --git a/src/App.jsx b/src/App.jsx index 3fe28ff..2514212 100644 --- a/src/App.jsx +++ b/src/App.jsx @@ -2042,6 +2042,18 @@ const countryNames = { ZA: 'South Africa', } +function repairMojibake(value) { + const text = String(value || '') + if (!/[ÃÂâ]/.test(text) || typeof TextDecoder === 'undefined') return text + + try { + const bytes = Uint8Array.from(text, (character) => character.charCodeAt(0)) + return new TextDecoder('utf-8', { fatal: true }).decode(bytes) + } catch { + return text + } +} + function filledLast30Days(rows) { const byDate = new Map(rows.map((row) => [row.date, row])) return Array.from({ length: 30 }, (_, index) => { @@ -2515,14 +2527,19 @@ function ViewersPage({ viewers }) { function LocationSignalTable({ countries, locations }) { const rows = locations.length - ? locations.map((location) => ({ - key: `${location.country}-${location.region}-${location.city}-${location.latitude}-${location.longitude}-${location.timezone}`, - place: location.city || location.region || location.timezone || 'Unknown city', - region: location.region || 'Not shared', - country: countryNames[location.country] || location.country || 'Not shared', - visitors: location.visitors, - events: location.events, - })) + ? locations.map((location) => { + const city = repairMojibake(location.city) + const region = repairMojibake(location.region) + const timezone = repairMojibake(location.timezone) + return { + key: `${location.country}-${location.region}-${location.city}-${location.latitude}-${location.longitude}-${location.timezone}`, + place: city || region || timezone || 'Unknown city', + region: region || 'Not shared', + country: countryNames[location.country] || location.country || 'Not shared', + visitors: location.visitors, + events: location.events, + } + }) : countries.map((country) => ({ key: country.country, place: countryNames[country.country] || country.country || 'Unknown country', @@ -2588,14 +2605,14 @@ function LocationSignalMap({ countries, locations }) { const lat = Number(location.latitude) const lon = Number(location.longitude) if (!Number.isFinite(lat) || !Number.isFinite(lon)) return null - const place = [location.city, location.region, countryNames[location.country] || location.country] + const place = [repairMojibake(location.city), repairMojibake(location.region), countryNames[location.country] || location.country] .filter(Boolean) .join(', ') return { ...location, lat, lon, - label: place || location.country || location.timezone || 'Unknown location', + label: place || location.country || repairMojibake(location.timezone) || 'Unknown location', } }) .filter(Boolean)