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
@@ -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 (
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger
|
||||
aria-label={`Pays : ${current.name}. Changer de pays`}
|
||||
className={cn(
|
||||
"flex h-9 items-center gap-2 rounded-md border border-gold/30 bg-card/70 px-3 text-sm font-medium outline-none transition-colors hover:border-gold/60 focus-visible:ring-2 focus-visible:ring-ring",
|
||||
pending && "opacity-60"
|
||||
)}
|
||||
>
|
||||
<Flag code={current.code} />
|
||||
<span className="hidden sm:inline">{current.name}</span>
|
||||
<ChevronDown className="h-3.5 w-3.5 text-muted-foreground" />
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent align="end" className="w-56">
|
||||
<DropdownMenuLabel className="text-xs text-muted-foreground">Choisir un pays</DropdownMenuLabel>
|
||||
<DropdownMenuSeparator />
|
||||
{COUNTRIES.map((c) => (
|
||||
<DropdownMenuItem key={c.code} onSelect={() => choose(c.code)} className="gap-2.5">
|
||||
<Flag code={c.code} />
|
||||
<span className="flex-1">{c.name}</span>
|
||||
{c.code === active && <Check className="h-4 w-4 text-gold" />}
|
||||
</DropdownMenuItem>
|
||||
))}
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user