Country selector in the header, auto-detected and remembered
Replaces the left sidebar with a header dropdown (flag + name), like 1xbet's region picker. The shown country resolves as: saved choice (cookie, then the member's profile so it follows them across devices), else Cloudflare's CF-IPCountry (Canada maps to Québec), else Québec. favoriteCountry becomes nullable so geo-detection isn't overridden by a default nobody chose. Emoji flags render as letters on Windows, so flags are now SVGs in /public/flags; country names are in French. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
2eafbfd3d7
commit
e97b2e54ad
+3
-13
@@ -10,7 +10,6 @@
|
||||
export interface CountryTheme {
|
||||
code: string // ISO 3166-1 alpha-2, or a region code like 'CA-QC'
|
||||
name: string
|
||||
flagEmoji: string
|
||||
flagPrimary: string
|
||||
flagSecondary: string
|
||||
accent: string // oklch(), CSS custom property value
|
||||
@@ -23,7 +22,6 @@ export const COUNTRIES: CountryTheme[] = [
|
||||
{
|
||||
code: 'CA-QC',
|
||||
name: 'Québec',
|
||||
flagEmoji: '⚜️',
|
||||
flagPrimary: '#1768C4',
|
||||
flagSecondary: '#183653',
|
||||
accent: 'oklch(0.62 0.16 255.5)',
|
||||
@@ -32,7 +30,6 @@ export const COUNTRIES: CountryTheme[] = [
|
||||
{
|
||||
code: 'FR',
|
||||
name: 'France',
|
||||
flagEmoji: '🇫🇷',
|
||||
flagPrimary: '#0055A4',
|
||||
flagSecondary: '#EF4135',
|
||||
accent: 'oklch(0.63 0.19 28.6)',
|
||||
@@ -40,8 +37,7 @@ export const COUNTRIES: CountryTheme[] = [
|
||||
},
|
||||
{
|
||||
code: 'US',
|
||||
name: 'United States',
|
||||
flagEmoji: '🇺🇸',
|
||||
name: 'États-Unis',
|
||||
flagPrimary: '#B22234',
|
||||
flagSecondary: '#3C3B6E',
|
||||
accent: 'oklch(0.6 0.17 20.7)',
|
||||
@@ -49,8 +45,7 @@ export const COUNTRIES: CountryTheme[] = [
|
||||
},
|
||||
{
|
||||
code: 'ES',
|
||||
name: 'España',
|
||||
flagEmoji: '🇪🇸',
|
||||
name: 'Espagne',
|
||||
flagPrimary: '#AA151B',
|
||||
flagSecondary: '#F1BF00',
|
||||
accent: 'oklch(0.76 0.16 89.6)',
|
||||
@@ -58,8 +53,7 @@ export const COUNTRIES: CountryTheme[] = [
|
||||
},
|
||||
{
|
||||
code: 'IT',
|
||||
name: 'Italia',
|
||||
flagEmoji: '🇮🇹',
|
||||
name: 'Italie',
|
||||
flagPrimary: '#009246',
|
||||
flagSecondary: '#CE2B37',
|
||||
accent: 'oklch(0.65 0.15 151.1)',
|
||||
@@ -68,7 +62,6 @@ export const COUNTRIES: CountryTheme[] = [
|
||||
{
|
||||
code: 'PT',
|
||||
name: 'Portugal',
|
||||
flagEmoji: '🇵🇹',
|
||||
flagPrimary: '#046A38',
|
||||
flagSecondary: '#DA020E',
|
||||
accent: 'oklch(0.63 0.14 153.6)',
|
||||
@@ -77,7 +70,6 @@ export const COUNTRIES: CountryTheme[] = [
|
||||
{
|
||||
code: 'DZ',
|
||||
name: 'Algérie',
|
||||
flagEmoji: '🇩🇿',
|
||||
flagPrimary: '#006233',
|
||||
flagSecondary: '#D21034',
|
||||
accent: 'oklch(0.6 0.13 153.7)',
|
||||
@@ -86,7 +78,6 @@ export const COUNTRIES: CountryTheme[] = [
|
||||
{
|
||||
code: 'MA',
|
||||
name: 'Maroc',
|
||||
flagEmoji: '🇲🇦',
|
||||
flagPrimary: '#C1272D',
|
||||
flagSecondary: '#006233',
|
||||
accent: 'oklch(0.58 0.19 25)',
|
||||
@@ -99,7 +90,6 @@ export function countryTheme(code: string): CountryTheme {
|
||||
COUNTRIES.find((c) => c.code === code) ?? {
|
||||
code,
|
||||
name: code,
|
||||
flagEmoji: '🏳️',
|
||||
flagPrimary: '#D7AE54',
|
||||
flagSecondary: '#242B36',
|
||||
accent: FALLBACK_ACCENT,
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
import 'server-only'
|
||||
import { cookies, headers } from 'next/headers'
|
||||
import { COUNTRIES } from './countries'
|
||||
import type { CurrentMember } from './member-auth'
|
||||
|
||||
export const COUNTRY_COOKIE = 'lokiloto_country'
|
||||
export const DEFAULT_COUNTRY = 'CA-QC'
|
||||
|
||||
function isKnown(code: string | null | undefined): code is string {
|
||||
return !!code && COUNTRIES.some((c) => c.code === code)
|
||||
}
|
||||
|
||||
/** Cloudflare's CF-IPCountry is ISO alpha-2; Canada maps to Québec, the only Canadian locale so far. */
|
||||
function fromGeo(iso: string | null): string | null {
|
||||
if (!iso) return null
|
||||
const code = iso.toUpperCase() === 'CA' ? 'CA-QC' : iso.toUpperCase()
|
||||
return isKnown(code) ? code : null
|
||||
}
|
||||
|
||||
/** Saved choice (cookie, then member profile) beats geo-detection, which beats the default. */
|
||||
export async function resolveCountry(member: CurrentMember | null): Promise<string> {
|
||||
const jar = await cookies()
|
||||
const saved = jar.get(COUNTRY_COOKIE)?.value
|
||||
if (isKnown(saved)) return saved
|
||||
if (isKnown(member?.favoriteCountry)) return member.favoriteCountry
|
||||
const h = await headers()
|
||||
return fromGeo(h.get('cf-ipcountry')) ?? DEFAULT_COUNTRY
|
||||
}
|
||||
|
||||
export function isKnownCountry(code: string): boolean {
|
||||
return isKnown(code)
|
||||
}
|
||||
+1
-1
@@ -26,7 +26,7 @@ export interface CurrentMember {
|
||||
name: string
|
||||
avatarUrl: string | null
|
||||
publicNickname: string | null
|
||||
favoriteCountry: string
|
||||
favoriteCountry: string | null
|
||||
}
|
||||
|
||||
export async function getCurrentMember(): Promise<CurrentMember | null> {
|
||||
|
||||
Reference in New Issue
Block a user