🐸 Rybbit - open-source and privacy-friendly alternative to Google Analytics that is 10x more intuitive.
Enhance Countries component with language tab and improved data handling
Bill Yang9d5015332613
diff --git a/client/src/app/[site]/components/shared/StandardSection/StandardSection.tsx b/client/src/app/[site]/components/shared/StandardSection/StandardSection.tsxindex a408f9095..35c52a29e 100644--- a/client/src/app/[site]/components/shared/StandardSection/StandardSection.tsx+++ b/client/src/app/[site]/components/shared/StandardSection/StandardSection.tsx@@ -169,6 +169,7 @@ export function StandardSection({</div>{data?.data?.slice(0, 10).map((e) => (<Row+ key={getKey(e)}e={e}ratio={ratio}getKey={getKey}diff --git a/client/src/app/[site]/main/components/sections/Countries.tsx b/client/src/app/[site]/main/components/sections/Countries.tsxindex e5bfad2b3..d791cd705 100644--- a/client/src/app/[site]/main/components/sections/Countries.tsx+++ b/client/src/app/[site]/main/components/sections/Countries.tsx@@ -1,7 +1,5 @@"use client";-import { getCountryName } from "../../../../../lib/utils";-import { StandardSection } from "../../../components/shared/StandardSection/StandardSection";-import { CountryFlag } from "../../../components/shared/icons/CountryFlag";+import { Globe } from "lucide-react";import { useState } from "react";import {Tabs,@@ -9,22 +7,48 @@ import {TabsList,TabsTrigger,} from "../../../../../components/ui/basic-tabs";-import {- Card,- CardContent,- CardHeader,- CardTitle,-} from "../../../../../components/ui/card";+import { Card, CardContent } from "../../../../../components/ui/card";+import { getCountryName } from "../../../../../lib/utils";+import { StandardSection } from "../../../components/shared/StandardSection/StandardSection";+import { CountryFlag } from "../../../components/shared/icons/CountryFlag";++type Tab = "countries" | "regions" | "languages";++const regionNamesInEnglish = new Intl.DisplayNames(["en"], { type: "region" });+const languageNamesInEnglish = new Intl.DisplayNames(["en"], {+ type: "language",+});++const getLanguageName = (languageCode: string) => {+ try {+ // Handle codes like "en-US" that have both language and region+ if (languageCode.includes("-")) {+ const [language, region] = languageCode.split("-");+ const languageName = languageNamesInEnglish.of(language);+ const regionName = regionNamesInEnglish.of(region);+ return `${languageName} (${regionName})`;+ }+ // Just a language code+ return languageNamesInEnglish.of(languageCode);+ } catch (error) {+ console.error(error);+ return languageCode;+ }+};-type Tab = "countries" | "regions";+// Helper to extract country code from language code+const getCountryFromLanguage = (languageCode: string): string | null => {+ if (languageCode.includes("-")) {+ const [_, region] = languageCode.split("-");+ return region;+ }+ return null;+};export function Countries() {const [tab, setTab] = useState<Tab>("countries");return (<Card className="">- {/* <CardHeader>- <CardTitle>Countries</CardTitle>- </CardHeader> */}<CardContent className="mt-2"><TabsdefaultValue="countries"@@ -34,6 +58,7 @@ export function Countries() {<TabsList><TabsTrigger value="countries">Countries</TabsTrigger><TabsTrigger value="regions">Regions</TabsTrigger>+ <TabsTrigger value="languages">Languages</TabsTrigger></TabsList><TabsContent value="countries"><StandardSection@@ -50,6 +75,24 @@ export function Countries() {/></TabsContent><TabsContent value="regions"></TabsContent>+ <TabsContent value="languages">+ <StandardSection+ filterParameter="language"+ title="Languages"+ getValue={(e) => e.value}+ getKey={(e) => e.value}+ getLabel={(e) => (+ <div className="flex gap-2 items-center">+ {getCountryFromLanguage(e.value) ? (+ <CountryFlag country={getCountryFromLanguage(e.value)!} />+ ) : (+ <Globe className="w-5 h-5" />+ )}+ {getLanguageName(e.value)}+ </div>+ )}+ />+ </TabsContent></Tabs></CardContent></Card>