update viewers page
This commit is contained in:
+23
-6
@@ -2042,6 +2042,18 @@ const countryNames = {
|
|||||||
ZA: 'South Africa',
|
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) {
|
function filledLast30Days(rows) {
|
||||||
const byDate = new Map(rows.map((row) => [row.date, row]))
|
const byDate = new Map(rows.map((row) => [row.date, row]))
|
||||||
return Array.from({ length: 30 }, (_, index) => {
|
return Array.from({ length: 30 }, (_, index) => {
|
||||||
@@ -2515,14 +2527,19 @@ function ViewersPage({ viewers }) {
|
|||||||
|
|
||||||
function LocationSignalTable({ countries, locations }) {
|
function LocationSignalTable({ countries, locations }) {
|
||||||
const rows = locations.length
|
const rows = locations.length
|
||||||
? locations.map((location) => ({
|
? 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}`,
|
key: `${location.country}-${location.region}-${location.city}-${location.latitude}-${location.longitude}-${location.timezone}`,
|
||||||
place: location.city || location.region || location.timezone || 'Unknown city',
|
place: city || region || timezone || 'Unknown city',
|
||||||
region: location.region || 'Not shared',
|
region: region || 'Not shared',
|
||||||
country: countryNames[location.country] || location.country || 'Not shared',
|
country: countryNames[location.country] || location.country || 'Not shared',
|
||||||
visitors: location.visitors,
|
visitors: location.visitors,
|
||||||
events: location.events,
|
events: location.events,
|
||||||
}))
|
}
|
||||||
|
})
|
||||||
: countries.map((country) => ({
|
: countries.map((country) => ({
|
||||||
key: country.country,
|
key: country.country,
|
||||||
place: countryNames[country.country] || country.country || 'Unknown country',
|
place: countryNames[country.country] || country.country || 'Unknown country',
|
||||||
@@ -2588,14 +2605,14 @@ function LocationSignalMap({ countries, locations }) {
|
|||||||
const lat = Number(location.latitude)
|
const lat = Number(location.latitude)
|
||||||
const lon = Number(location.longitude)
|
const lon = Number(location.longitude)
|
||||||
if (!Number.isFinite(lat) || !Number.isFinite(lon)) return null
|
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)
|
.filter(Boolean)
|
||||||
.join(', ')
|
.join(', ')
|
||||||
return {
|
return {
|
||||||
...location,
|
...location,
|
||||||
lat,
|
lat,
|
||||||
lon,
|
lon,
|
||||||
label: place || location.country || location.timezone || 'Unknown location',
|
label: place || location.country || repairMojibake(location.timezone) || 'Unknown location',
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.filter(Boolean)
|
.filter(Boolean)
|
||||||
|
|||||||
Reference in New Issue
Block a user