+
}>
+
+
}>
diff --git a/components/country-nav.tsx b/components/country-nav.tsx
deleted file mode 100644
index 36b7a7c..0000000
--- a/components/country-nav.tsx
+++ /dev/null
@@ -1,79 +0,0 @@
-"use client"
-
-import Link from "next/link"
-import { usePathname, useSearchParams } from "next/navigation"
-import { COUNTRIES } from "@/lib/countries"
-import { cn } from "@/lib/utils"
-
-export function CountryNav({ active }: { active: string }) {
- const pathname = usePathname()
- const searchParams = useSearchParams()
-
- function hrefFor(code: string) {
- const params = new URLSearchParams(searchParams.toString())
- params.set("country", code)
- return `${pathname}?${params.toString()}`
- }
-
- return (
-
- )
-}
-
-export function CountryNavMobile({ active }: { active: string }) {
- const pathname = usePathname()
- const searchParams = useSearchParams()
-
- function hrefFor(code: string) {
- const params = new URLSearchParams(searchParams.toString())
- params.set("country", code)
- return `${pathname}?${params.toString()}`
- }
-
- return (
-
- )
-}
diff --git a/components/country-switcher.tsx b/components/country-switcher.tsx
new file mode 100644
index 0000000..b022fed
--- /dev/null
+++ b/components/country-switcher.tsx
@@ -0,0 +1,58 @@
+"use client"
+
+import { useTransition } from "react"
+import { useRouter } from "next/navigation"
+import { Check, ChevronDown } from "lucide-react"
+import { COUNTRIES, countryTheme } from "@/lib/countries"
+import { setCountryAction } from "@/app/actions"
+import {
+ DropdownMenu,
+ DropdownMenuContent,
+ DropdownMenuItem,
+ DropdownMenuLabel,
+ DropdownMenuSeparator,
+ DropdownMenuTrigger,
+} from "@/components/ui/dropdown-menu"
+import { cn } from "@/lib/utils"
+import { Flag } from "@/components/flag"
+
+export function CountrySwitcher({ active }: { active: string }) {
+ const router = useRouter()
+ const [pending, startTransition] = useTransition()
+ const current = countryTheme(active)
+
+ function choose(code: string) {
+ if (code === active) return
+ startTransition(async () => {
+ await setCountryAction(code)
+ router.refresh()
+ })
+ }
+
+ return (
+
+
+
+ {current.name}
+
+
+
+ Choisir un pays
+
+ {COUNTRIES.map((c) => (
+ choose(c.code)} className="gap-2.5">
+
+ {c.name}
+ {c.code === active && }
+
+ ))}
+
+
+ )
+}
diff --git a/components/flag.tsx b/components/flag.tsx
new file mode 100644
index 0000000..aed7924
--- /dev/null
+++ b/components/flag.tsx
@@ -0,0 +1,14 @@
+import { cn } from "@/lib/utils"
+
+/** SVG flag from /public/flags — emoji flags don't render on Windows. */
+export function Flag({ code, className }: { code: string; className?: string }) {
+ return (
+ // eslint-disable-next-line @next/next/no-img-element
+
}.svg`})
+ )
+}
diff --git a/lib/countries.ts b/lib/countries.ts
index 14a449b..54d7abd 100644
--- a/lib/countries.ts
+++ b/lib/countries.ts
@@ -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,
diff --git a/lib/country-pref.ts b/lib/country-pref.ts
new file mode 100644
index 0000000..23b67ff
--- /dev/null
+++ b/lib/country-pref.ts
@@ -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
{
+ 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)
+}
diff --git a/lib/member-auth.ts b/lib/member-auth.ts
index 133a7e8..62d31ae 100644
--- a/lib/member-auth.ts
+++ b/lib/member-auth.ts
@@ -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 {
diff --git a/prisma/migrations/20261030120000_favorite_country_nullable/migration.sql b/prisma/migrations/20261030120000_favorite_country_nullable/migration.sql
new file mode 100644
index 0000000..908cf8e
--- /dev/null
+++ b/prisma/migrations/20261030120000_favorite_country_nullable/migration.sql
@@ -0,0 +1,5 @@
+-- A member's country preference is only set when they actually pick one,
+-- so geo-detection isn't overridden by a default nobody chose.
+ALTER TABLE "User" ALTER COLUMN "favoriteCountry" DROP NOT NULL;
+ALTER TABLE "User" ALTER COLUMN "favoriteCountry" DROP DEFAULT;
+UPDATE "User" SET "favoriteCountry" = NULL WHERE "favoriteCountry" = 'CA-QC';
diff --git a/prisma/schema.prisma b/prisma/schema.prisma
index 20fdb48..6c5569d 100644
--- a/prisma/schema.prisma
+++ b/prisma/schema.prisma
@@ -23,8 +23,9 @@ model User {
/// (leaderboard, follow counts). Must be set before a member appears
/// publicly.
publicNickname String?
- /// Last country tab the member viewed, restored on next visit.
- favoriteCountry String @default("CA-QC")
+ /// Country the member explicitly picked in the header selector — synced
+ /// across devices. Null until they pick one, so geo-detection applies.
+ favoriteCountry String?
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
diff --git a/public/flags/ca-qc.svg b/public/flags/ca-qc.svg
new file mode 100644
index 0000000..2a475fb
--- /dev/null
+++ b/public/flags/ca-qc.svg
@@ -0,0 +1 @@
+
diff --git a/public/flags/dz.svg b/public/flags/dz.svg
new file mode 100644
index 0000000..fe8bb71
--- /dev/null
+++ b/public/flags/dz.svg
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/public/flags/es.svg b/public/flags/es.svg
new file mode 100644
index 0000000..e143324
--- /dev/null
+++ b/public/flags/es.svg
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/public/flags/fr.svg b/public/flags/fr.svg
new file mode 100644
index 0000000..ec311d7
--- /dev/null
+++ b/public/flags/fr.svg
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/public/flags/it.svg b/public/flags/it.svg
new file mode 100644
index 0000000..2eb1289
--- /dev/null
+++ b/public/flags/it.svg
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/public/flags/ma.svg b/public/flags/ma.svg
new file mode 100644
index 0000000..c2f0600
--- /dev/null
+++ b/public/flags/ma.svg
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/public/flags/pt.svg b/public/flags/pt.svg
new file mode 100644
index 0000000..51d7c80
--- /dev/null
+++ b/public/flags/pt.svg
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/public/flags/us.svg b/public/flags/us.svg
new file mode 100644
index 0000000..dc427e7
--- /dev/null
+++ b/public/flags/us.svg
@@ -0,0 +1 @@
+
\ No newline at end of file