🐸 Rybbit - open-source and privacy-friendly alternative to Google Analytics that is 10x more intuitive.
Refactor MapPage and Switch component for improved functionality and code clarity
Bill Yange35d7d3510bf
diff --git a/client/src/app/[site]/map/page.tsx b/client/src/app/[site]/map/page.tsxindex 2f5e66432..645c9ec53 100644--- a/client/src/app/[site]/map/page.tsx+++ b/client/src/app/[site]/map/page.tsx@@ -1,10 +1,9 @@"use client";+import { Switch } from "@/components/ui/switch";import { useState } from "react";-import { MobileSidebar } from "../../../components/MobileSidebar";import { MapComponent } from "../components/shared/Map";import { SubHeader } from "../components/SubHeader/SubHeader";-import { Switch } from "@/components/ui/switch";export default function MapPage() {const [mapMode, setMapMode] = useState<"total" | "perCapita">("total");@@ -17,11 +16,7 @@ export default function MapPage() {<div className="absolute bottom-4 left-4 z-10"><div className="flex items-center gap-3 bg-neutral-900 rounded-md px-3 py-2 text-sm"><span- className={- mapMode === "total"- ? "text-white font-medium"- : "text-neutral-400"- }+ className={mapMode === "total" ? "text-white" : "text-neutral-400"}>Total Visits</span>@@ -34,9 +29,7 @@ export default function MapPage() {/><spanclassName={- mapMode === "perCapita"- ? "text-white font-medium"- : "text-neutral-400"+ mapMode === "perCapita" ? "text-white" : "text-neutral-400"}>Per Capitadiff --git a/client/src/components/ui/switch.tsx b/client/src/components/ui/switch.tsxindex 9f9cc0ce3..e652c810d 100644--- a/client/src/components/ui/switch.tsx+++ b/client/src/components/ui/switch.tsx@@ -1,9 +1,9 @@-"use client"+"use client";-import * as React from "react"-import * as SwitchPrimitives from "@radix-ui/react-switch"+import * as React from "react";+import * as SwitchPrimitives from "@radix-ui/react-switch";-import { cn } from "@/lib/utils"+import { cn } from "@/lib/utils";const Switch = React.forwardRef<React.ElementRef<typeof SwitchPrimitives.Root>,@@ -11,7 +11,7 @@ const Switch = React.forwardRef<>(({ className, ...props }, ref) => (<SwitchPrimitives.RootclassName={cn(- "peer inline-flex h-5 w-9 shrink-0 cursor-pointer items-center rounded-full border-2 border-transparent shadow-sm transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-neutral-950 focus-visible:ring-offset-2 focus-visible:ring-offset-white disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-neutral-900 data-[state=unchecked]:bg-neutral-200 dark:focus-visible:ring-neutral-300 dark:focus-visible:ring-offset-neutral-950 dark:data-[state=checked]:bg-neutral-50 dark:data-[state=unchecked]:bg-neutral-800",+ "peer inline-flex h-5 w-9 shrink-0 cursor-pointer items-center rounded-full border-2 border-transparent shadow-sm transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-neutral-950 focus-visible:ring-offset-2 focus-visible:ring-offset-white disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-accent-400 data-[state=unchecked]:bg-neutral-200 dark:focus-visible:ring-neutral-300 dark:focus-visible:ring-offset-neutral-950 dark:data-[state=checked]:bg-accent-400 dark:data-[state=unchecked]:bg-neutral-800",className)}{...props}@@ -23,7 +23,7 @@ const Switch = React.forwardRef<)}/></SwitchPrimitives.Root>-))-Switch.displayName = SwitchPrimitives.Root.displayName+));+Switch.displayName = SwitchPrimitives.Root.displayName;-export { Switch }+export { Switch };diff --git a/client/src/lib/countryPopulation.ts b/client/src/lib/countryPopulation.tsindex 3c4d08cbe..efb2ed7ec 100644--- a/client/src/lib/countryPopulation.ts+++ b/client/src/lib/countryPopulation.ts@@ -16,100 +16,185 @@ export const countryPopulations: Record<string, number> = {ET: 123.4, // EthiopiaEG: 110.0, // EgyptVN: 98.2, // Vietnam-- // European countries+ CD: 99.0, // DR Congo+ TR: 84.3, // Turkey+ IR: 87.9, // IranDE: 83.8, // Germany+ TH: 71.7, // ThailandGB: 67.3, // United KingdomFR: 65.5, // France+ TZ: 63.6, // Tanzania+ ZA: 59.3, // South AfricaIT: 60.3, // Italy+ KE: 54.0, // Kenya+ MM: 54.8, // Myanmar+ CO: 51.5, // Colombia+ KR: 51.3, // South Korea+ UG: 47.1, // UgandaES: 47.4, // Spain+ AR: 45.8, // Argentina+ DZ: 44.6, // Algeria+ SD: 45.7, // Sudan+ UA: 43.8, // Ukraine (pre-war estimate)+ IQ: 43.5, // Iraq+ AF: 38.9, // AfghanistanPL: 37.8, // Poland- RO: 19.1, // Romania+ CA: 38.2, // Canada+ MR: 3.0, // Mauritania+ SA: 35.3, // Saudi Arabia+ UZ: 34.2, // Uzbekistan+ PE: 33.4, // Peru+ AO: 34.5, // Angola+ MY: 33.6, // Malaysia+ GH: 32.8, // Ghana+ MZ: 32.9, // Mozambique+ YE: 33.7, // Yemen+ NP: 30.0, // Nepal+ VE: 28.4, // Venezuela+ CM: 27.9, // Cameroon+ CI: 27.5, // Côte d'Ivoire+ AU: 25.7, // Australia+ NE: 25.4, // Niger+ TW: 23.8, // Taiwan+ SY: 21.3, // Syria+ ML: 21.9, // Mali+ BF: 21.5, // Burkina Faso+ MW: 19.6, // Malawi+ ZM: 19.4, // Zambia+ KZ: 18.9, // Kazakhstan+ CL: 19.2, // Chile+ EC: 17.9, // Ecuador+ GT: 17.1, // Guatemala+ SN: 17.2, // SenegalNL: 17.5, // Netherlands+ KH: 16.7, // Cambodia+ TD: 17.4, // Chad+ SO: 17.1, // Somalia+ ZW: 15.2, // Zimbabwe+ GN: 13.5, // Guinea+ RW: 13.4, // Rwanda+ BJ: 13.0, // Benin+ BI: 12.5, // Burundi+ TN: 12.0, // Tunisia+ BO: 11.7, // BoliviaBE: 11.6, // Belgium- GR: 10.6, // Greece+ HT: 11.5, // Haiti+ CU: 11.3, // Cuba+ SS: 11.3, // South Sudan+ DO: 10.9, // Dominican Republic+ JO: 10.2, // JordanCZ: 10.7, // Czech Republic- PT: 10.2, // PortugalSE: 10.4, // Sweden+ AZ: 10.2, // Azerbaijan+ GR: 10.6, // Greece+ PT: 10.2, // Portugal+ AE: 9.9, // United Arab EmiratesHU: 9.7, // Hungary+ TJ: 9.5, // Tajikistan+ BY: 9.4, // Belarus+ IL: 9.2, // IsraelAT: 9.1, // AustriaCH: 8.7, // Switzerland+ PG: 9.1, // Papua New Guinea+ HN: 10.0, // Honduras+ TG: 8.6, // Togo+ SL: 8.1, // Sierra Leone+ LA: 7.4, // Laos+ PY: 7.3, // Paraguay+ NI: 6.8, // Nicaragua+ LY: 7.0, // Libya+ SV: 6.5, // El Salvador+ KG: 6.5, // Kyrgyzstan+ TM: 6.0, // Turkmenistan+ SG: 5.9, // SingaporeDK: 5.8, // DenmarkFI: 5.5, // FinlandSK: 5.4, // SlovakiaNO: 5.4, // Norway+ CG: 5.8, // Congo (Brazzaville)+ ER: 3.6, // EritreaIE: 5.0, // Ireland+ PS: 5.1, // Palestine+ CR: 5.1, // Costa Rica+ NZ: 5.1, // New Zealand+ LB: 6.8, // Lebanon+ CF: 4.9, // Central African Republic+ OM: 5.1, // Oman+ PA: 4.3, // Panama+ KW: 4.3, // KuwaitHR: 4.0, // Croatia+ GE: 3.7, // Georgia+ UY: 3.5, // Uruguay+ BA: 3.3, // Bosnia and Herzegovina+ MN: 3.3, // Mongolia+ MD: 2.6, // Moldova+ JM: 2.9, // Jamaica+ AM: 2.9, // Armenia+ AL: 2.8, // Albania+ QA: 2.9, // QatarLT: 2.8, // Lithuania+ BW: 2.4, // Botswana+ NA: 2.5, // Namibia+ GM: 2.4, // Gambia+ GA: 2.3, // Gabon+ LS: 2.1, // LesothoSI: 2.1, // Slovenia+ MK: 2.1, // North MacedoniaLV: 1.9, // Latvia+ GW: 2.0, // Guinea-Bissau+ GQ: 1.4, // Equatorial Guinea+ TT: 1.4, // Trinidad and Tobago+ BH: 1.7, // Bahrain+ TL: 1.3, // Timor-LesteEE: 1.3, // Estonia+ MU: 1.3, // MauritiusCY: 0.9, // Cyprus+ SZ: 1.2, // Eswatini+ DJ: 1.0, // Djibouti+ FJ: 0.9, // Fiji+ RE: 0.9, // Réunion+ KM: 0.8, // Comoros+ GY: 0.8, // Guyana+ BT: 0.8, // Bhutan+ SB: 0.7, // Solomon Islands+ MQ: 0.4, // MartiniqueLU: 0.6, // Luxembourg+ SR: 0.6, // Suriname+ CV: 0.6, // Cabo Verde+ MV: 0.5, // MaldivesMT: 0.5, // Malta-- // North America- CA: 38.2, // Canada- CU: 11.3, // Cuba- HT: 11.5, // Haiti- DO: 10.9, // Dominican Republic-- // South/Central America- CO: 51.5, // Colombia- AR: 45.8, // Argentina- PE: 33.4, // Peru- VE: 28.4, // Venezuela- CL: 19.2, // Chile- EC: 17.9, // Ecuador- BO: 11.7, // Bolivia-- // Asia/Oceania- AU: 25.7, // Australia- MY: 33.6, // Malaysia- SA: 35.3, // Saudi Arabia- UZ: 34.2, // Uzbekistan- YE: 33.7, // Yemen- NP: 30.0, // Nepal- AF: 38.9, // Afghanistan- IQ: 43.5, // Iraq- TH: 71.7, // Thailand- TR: 84.3, // Turkey- IR: 87.9, // Iran- KR: 51.3, // South Korea- MM: 54.8, // Myanmar- TW: 23.8, // Taiwan- LK: 22.2, // Sri Lanka- KH: 16.7, // Cambodia- AE: 9.9, // United Arab Emirates- IL: 9.2, // Israel- TJ: 9.5, // Tajikistan- AZ: 10.2, // Azerbaijan- JO: 10.2, // Jordan- SG: 5.9, // Singapore- KG: 6.5, // Kyrgyzstan- TM: 6.0, // Turkmenistan- NZ: 5.1, // New Zealand-- // Africa- ZA: 59.3, // South Africa- TZ: 63.6, // Tanzania- KE: 54.0, // Kenya- DZ: 44.6, // Algeria- SD: 45.7, // Sudan- UG: 47.1, // Uganda- MA: 37.3, // Morocco- GH: 32.8, // Ghana- MZ: 32.9, // Mozambique- AO: 34.5, // Angola- CI: 27.5, // Côte d'Ivoire- CM: 27.9, // Cameroon- MG: 28.9, // Madagascar- LY: 7.0, // Libya- TN: 12.0, // Tunisia- SN: 17.2, // Senegal+ BN: 0.4, // Brunei+ BZ: 0.4, // Belize+ BS: 0.4, // Bahamas+ IS: 0.4, // Iceland+ GP: 0.4, // Guadeloupe+ VU: 0.3, // Vanuatu+ NC: 0.3, // New Caledonia+ PF: 0.3, // French Polynesia+ WS: 0.2, // Samoa+ ST: 0.2, // Sao Tome and Principe+ KI: 0.1, // Kiribati+ FM: 0.1, // Micronesia+ TO: 0.1, // Tonga+ SC: 0.1, // Seychelles+ VC: 0.1, // Saint Vincent and the Grenadines+ GD: 0.1, // Grenada+ LC: 0.1, // Saint Lucia+ AG: 0.1, // Antigua and Barbuda+ DM: 0.1, // Dominica+ KN: 0.05, // Saint Kitts and Nevis+ MH: 0.06, // Marshall Islands+ SM: 0.03, // San Marino+ MC: 0.04, // Monaco+ LI: 0.04, // Liechtenstein+ AD: 0.08, // Andorra+ PW: 0.02, // Palau+ TV: 0.01, // Tuvalu+ NR: 0.01, // Nauru+ VA: 0.001, // Vatican City// Default population for countries not in the list (use with caution)- XX: 5.0, // Default value+ XX: 1.0, // Default value (reduced from 5.0)};// Helper function to get population with fallback@@ -119,5 +204,8 @@ export function getCountryPopulation(countryCode: string): number {// Normalize to uppercase and get first 2 characters (ISO2 code)const normalizedCode = countryCode.slice(0, 2).toUpperCase();- return countryPopulations[normalizedCode] || countryPopulations.XX || 1;+ // Use 1 million as default if country not found or has 0 pop+ const population =+ countryPopulations[normalizedCode] || countryPopulations.XX || 1;+ return Math.max(population, 0.001); // Ensure a minimum population to avoid division by zero}