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>
39 lines
1.3 KiB
TypeScript
39 lines
1.3 KiB
TypeScript
"use server"
|
|
|
|
import { revalidatePath } from "next/cache"
|
|
import { cookies } from "next/headers"
|
|
import { prisma } from "@/lib/db"
|
|
import { getCurrentMember } from "@/lib/member-auth"
|
|
import { followPick, unfollowPick } from "@/lib/follows"
|
|
import { COUNTRY_COOKIE, isKnownCountry } from "@/lib/country-pref"
|
|
|
|
export async function setCountryAction(code: string) {
|
|
if (!isKnownCountry(code)) return { ok: false as const }
|
|
const jar = await cookies()
|
|
jar.set(COUNTRY_COOKIE, code, {
|
|
httpOnly: true,
|
|
sameSite: "lax",
|
|
secure: process.env.NODE_ENV === "production",
|
|
maxAge: 365 * 24 * 3600,
|
|
path: "/",
|
|
})
|
|
const member = await getCurrentMember()
|
|
if (member) await prisma.user.update({ where: { id: member.id }, data: { favoriteCountry: code } })
|
|
revalidatePath("/", "layout")
|
|
return { ok: true as const }
|
|
}
|
|
|
|
export async function toggleFollowAction(lotteryId: string, country: string, targetDrawDate: string, isFollowing: boolean) {
|
|
const member = await getCurrentMember()
|
|
if (!member) return { ok: false as const, needsAuth: true as const }
|
|
|
|
if (isFollowing) {
|
|
await unfollowPick(member.id, lotteryId, targetDrawDate)
|
|
} else {
|
|
await followPick(member.id, lotteryId, country, targetDrawDate)
|
|
}
|
|
revalidatePath("/")
|
|
revalidatePath("/profil")
|
|
return { ok: true as const, needsAuth: false as const }
|
|
}
|