Add member accounts, follow-based leaderboard, and dedicated Postgres
Members register via email+password (scrypt) or Google OAuth — same signed-cookie + scrypt pattern as LokiLab (lib/auth.ts, member-password.ts, member-auth.ts, google-oauth.ts), own AUTH_SECRET and own OAuth client, own dedicated Postgres database (lokiloto-db on Coolify), fully isolated from LokiLab's own DB and auth. Leaderboard tracks who follows Loki's picks most accurately — members star a pick from the results panel (FollowButton), resolution reuses LokiLab's own lastDraw.won, no money or pooled play involved anywhere. Leaderboard page renders a horizontal bar chart (recharts) plus a ranked list. Profile page: public nickname (required to appear on the leaderboard), list of followed picks. Header now carries nav + a user menu (avatar dropdown when signed in, "Connexion" button otherwise). Dockerfile runs prisma migrate deploy at container start via docker-entrypoint.sh, same pattern as LokiLab. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 5
parent
fc69d4a668
commit
c3a0a7b765
@@ -0,0 +1,33 @@
|
||||
import Link from "next/link"
|
||||
import { Suspense } from "react"
|
||||
import { LokiMark } from "@/components/loki-mark"
|
||||
import { UserMenu } from "@/components/user-menu"
|
||||
import { Skeleton } from "@/components/ui/skeleton"
|
||||
|
||||
export function AppHeader() {
|
||||
return (
|
||||
<div className="h-14 border-b border-border/60 bg-card">
|
||||
<div className="mx-auto flex h-full max-w-6xl items-center gap-5 px-4 sm:px-6">
|
||||
<Link href="/" className="flex shrink-0 items-center gap-2">
|
||||
<LokiMark className="h-8 w-8 text-accent" />
|
||||
<span className="text-base font-bold tracking-tight">LokiLoto</span>
|
||||
</Link>
|
||||
|
||||
<nav className="hidden items-center gap-4 text-sm text-muted-foreground sm:flex">
|
||||
<Link href="/" className="hover:text-foreground">
|
||||
Résultats
|
||||
</Link>
|
||||
<Link href="/classement" className="hover:text-foreground">
|
||||
Classement
|
||||
</Link>
|
||||
</nav>
|
||||
|
||||
<div className="ml-auto">
|
||||
<Suspense fallback={<Skeleton className="h-8 w-8 rounded-full" />}>
|
||||
<UserMenu />
|
||||
</Suspense>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
"use client"
|
||||
|
||||
import { useState, useTransition } from "react"
|
||||
import { useRouter } from "next/navigation"
|
||||
import { Star } from "lucide-react"
|
||||
import { toggleFollowAction } from "@/app/actions"
|
||||
import { cn } from "@/lib/utils"
|
||||
|
||||
export function FollowButton({
|
||||
lotteryId,
|
||||
country,
|
||||
targetDrawDate,
|
||||
initialFollowing,
|
||||
isAuthenticated,
|
||||
}: {
|
||||
lotteryId: string
|
||||
country: string
|
||||
targetDrawDate: string
|
||||
initialFollowing: boolean
|
||||
isAuthenticated: boolean
|
||||
}) {
|
||||
const [following, setFollowing] = useState(initialFollowing)
|
||||
const [pending, startTransition] = useTransition()
|
||||
const router = useRouter()
|
||||
|
||||
function handleClick() {
|
||||
if (!isAuthenticated) {
|
||||
router.push(`/connexion?next=${encodeURIComponent(window.location.pathname + window.location.search)}`)
|
||||
return
|
||||
}
|
||||
const next = !following
|
||||
setFollowing(next)
|
||||
startTransition(async () => {
|
||||
const res = await toggleFollowAction(lotteryId, country, targetDrawDate, following)
|
||||
if (!res.ok) setFollowing(!next)
|
||||
})
|
||||
}
|
||||
|
||||
return (
|
||||
<button
|
||||
type="button"
|
||||
onClick={handleClick}
|
||||
disabled={pending}
|
||||
title={following ? "Ne plus suivre" : "Suivre ce pronostic"}
|
||||
className={cn(
|
||||
"flex h-6 w-6 shrink-0 items-center justify-center rounded transition-colors",
|
||||
following ? "text-accent" : "text-muted-foreground hover:text-foreground"
|
||||
)}
|
||||
>
|
||||
<Star className="h-4 w-4" fill={following ? "currentColor" : "none"} />
|
||||
</button>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
"use client"
|
||||
|
||||
import { Bar, BarChart, CartesianGrid, ResponsiveContainer, Tooltip, XAxis, YAxis } from "recharts"
|
||||
import type { MemberStanding } from "@/lib/follows"
|
||||
|
||||
export function LeaderboardChart({ standings }: { standings: MemberStanding[] }) {
|
||||
const data = standings.slice(0, 10).map((s) => ({
|
||||
name: s.displayName,
|
||||
"Taux de réussite": Math.round(s.winRate * 100),
|
||||
}))
|
||||
|
||||
return (
|
||||
<ResponsiveContainer width="100%" height={Math.max(220, data.length * 36)}>
|
||||
<BarChart data={data} layout="vertical" margin={{ left: 8, right: 24, top: 8, bottom: 8 }}>
|
||||
<CartesianGrid strokeDasharray="3 3" stroke="var(--border)" horizontal={false} />
|
||||
<XAxis type="number" domain={[0, 100]} tick={{ fill: "var(--muted-foreground)", fontSize: 12 }} unit="%" />
|
||||
<YAxis
|
||||
type="category"
|
||||
dataKey="name"
|
||||
width={110}
|
||||
tick={{ fill: "var(--foreground)", fontSize: 12 }}
|
||||
/>
|
||||
<Tooltip
|
||||
contentStyle={{
|
||||
background: "var(--panel)",
|
||||
border: "1px solid var(--border)",
|
||||
borderRadius: 6,
|
||||
fontSize: 12,
|
||||
}}
|
||||
cursor={{ fill: "var(--panel-hover)" }}
|
||||
/>
|
||||
<Bar dataKey="Taux de réussite" fill="var(--accent)" radius={[0, 4, 4, 0]} />
|
||||
</BarChart>
|
||||
</ResponsiveContainer>
|
||||
)
|
||||
}
|
||||
@@ -1,14 +1,36 @@
|
||||
import { NumberSequence } from "@/components/number-sequence"
|
||||
import { FollowButton } from "@/components/follow-button"
|
||||
import type { LotteryFeedEntry } from "@/lib/lokilab-feed"
|
||||
|
||||
export function LotteryMobileCard({ entry }: { entry: LotteryFeedEntry }) {
|
||||
export function LotteryMobileCard({
|
||||
entry,
|
||||
country,
|
||||
isFollowing,
|
||||
isAuthenticated,
|
||||
}: {
|
||||
entry: LotteryFeedEntry
|
||||
country: string
|
||||
isFollowing: boolean
|
||||
isAuthenticated: boolean
|
||||
}) {
|
||||
const { lifetime, lastDraw } = entry
|
||||
const resultSet = new Set(lastDraw?.result ?? [])
|
||||
|
||||
return (
|
||||
<div className="space-y-2.5 border-b border-border/60 p-3 last:border-b-0">
|
||||
<div className="flex items-center justify-between">
|
||||
<p className="font-semibold">{entry.name}</p>
|
||||
<p className="flex items-center gap-1.5 font-semibold">
|
||||
{lastDraw && (
|
||||
<FollowButton
|
||||
lotteryId={entry.id}
|
||||
country={country}
|
||||
targetDrawDate={lastDraw.date}
|
||||
initialFollowing={isFollowing}
|
||||
isAuthenticated={isAuthenticated}
|
||||
/>
|
||||
)}
|
||||
{entry.name}
|
||||
</p>
|
||||
{lifetime.picksTracked > 0 ? (
|
||||
<p className="text-xs text-muted-foreground">
|
||||
<span className="font-semibold text-foreground tabular-nums">
|
||||
|
||||
@@ -2,10 +2,21 @@ import { LotteryRow } from "@/components/lottery-row"
|
||||
import { LotteryMobileCard } from "@/components/lottery-mobile-card"
|
||||
import type { LotteryFeedEntry } from "@/lib/lokilab-feed"
|
||||
|
||||
export function LotteryResultsPanel({ lotteries }: { lotteries: LotteryFeedEntry[] }) {
|
||||
export function LotteryResultsPanel({
|
||||
lotteries,
|
||||
country,
|
||||
followedKeys,
|
||||
isAuthenticated,
|
||||
}: {
|
||||
lotteries: LotteryFeedEntry[]
|
||||
country: string
|
||||
followedKeys: Set<string>
|
||||
isAuthenticated: boolean
|
||||
}) {
|
||||
return (
|
||||
<div className="overflow-hidden rounded-md border border-border/60 bg-panel">
|
||||
<div className="hidden sm:grid grid-cols-[160px_1fr_1fr_72px_120px] gap-3 border-b border-border/60 px-3 py-2 text-xs font-medium uppercase tracking-wide text-muted-foreground">
|
||||
<div className="hidden sm:grid grid-cols-[28px_160px_1fr_1fr_72px_120px] gap-3 border-b border-border/60 px-3 py-2 text-xs font-medium uppercase tracking-wide text-muted-foreground">
|
||||
<span />
|
||||
<span>Loterie</span>
|
||||
<span>Résultat officiel</span>
|
||||
<span>Choix de Loki</span>
|
||||
@@ -15,13 +26,25 @@ export function LotteryResultsPanel({ lotteries }: { lotteries: LotteryFeedEntry
|
||||
|
||||
<div className="hidden sm:block">
|
||||
{lotteries.map((entry) => (
|
||||
<LotteryRow key={entry.id} entry={entry} />
|
||||
<LotteryRow
|
||||
key={entry.id}
|
||||
entry={entry}
|
||||
country={country}
|
||||
isFollowing={entry.lastDraw ? followedKeys.has(`${entry.id}:${entry.lastDraw.date}`) : false}
|
||||
isAuthenticated={isAuthenticated}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
|
||||
<div className="sm:hidden">
|
||||
{lotteries.map((entry) => (
|
||||
<LotteryMobileCard key={entry.id} entry={entry} />
|
||||
<LotteryMobileCard
|
||||
key={entry.id}
|
||||
entry={entry}
|
||||
country={country}
|
||||
isFollowing={entry.lastDraw ? followedKeys.has(`${entry.id}:${entry.lastDraw.date}`) : false}
|
||||
isAuthenticated={isAuthenticated}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -1,12 +1,35 @@
|
||||
import { NumberSequence } from "@/components/number-sequence"
|
||||
import { FollowButton } from "@/components/follow-button"
|
||||
import type { LotteryFeedEntry } from "@/lib/lokilab-feed"
|
||||
|
||||
export function LotteryRow({ entry }: { entry: LotteryFeedEntry }) {
|
||||
export function LotteryRow({
|
||||
entry,
|
||||
country,
|
||||
isFollowing,
|
||||
isAuthenticated,
|
||||
}: {
|
||||
entry: LotteryFeedEntry
|
||||
country: string
|
||||
isFollowing: boolean
|
||||
isAuthenticated: boolean
|
||||
}) {
|
||||
const { lifetime, lastDraw } = entry
|
||||
const resultSet = new Set(lastDraw?.result ?? [])
|
||||
|
||||
return (
|
||||
<div className="grid grid-cols-[160px_1fr_1fr_72px_120px] items-center gap-3 border-b border-border/60 px-3 py-3 text-sm last:border-b-0 hover:bg-panel-hover/40">
|
||||
<div className="grid grid-cols-[28px_160px_1fr_1fr_72px_120px] items-center gap-3 border-b border-border/60 px-3 py-3 text-sm last:border-b-0 hover:bg-panel-hover/40">
|
||||
<div>
|
||||
{lastDraw && (
|
||||
<FollowButton
|
||||
lotteryId={entry.id}
|
||||
country={country}
|
||||
targetDrawDate={lastDraw.date}
|
||||
initialFollowing={isFollowing}
|
||||
isAuthenticated={isAuthenticated}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<div className="min-w-0">
|
||||
<p className="truncate font-semibold leading-tight" title={entry.name}>
|
||||
{entry.name}
|
||||
|
||||
@@ -0,0 +1,81 @@
|
||||
"use client"
|
||||
|
||||
import { useActionState, useState } from "react"
|
||||
import { loginWithPassword, signupWithPassword, type MemberAuthState } from "@/app/connexion/actions"
|
||||
import { Button } from "@/components/ui/button"
|
||||
import { Input } from "@/components/ui/input"
|
||||
import { Label } from "@/components/ui/label"
|
||||
import { cn } from "@/lib/utils"
|
||||
|
||||
const INITIAL: MemberAuthState = { ok: false, message: "" }
|
||||
|
||||
export function MemberAuthForm({ next }: { next: string }) {
|
||||
const [mode, setMode] = useState<"login" | "signup">("login")
|
||||
const [loginState, loginAction, loginPending] = useActionState(loginWithPassword, INITIAL)
|
||||
const [signupState, signupActionFn, signupPending] = useActionState(signupWithPassword, INITIAL)
|
||||
|
||||
const action = mode === "login" ? loginAction : signupActionFn
|
||||
const state = mode === "login" ? loginState : signupState
|
||||
const pending = mode === "login" ? loginPending : signupPending
|
||||
|
||||
return (
|
||||
<div>
|
||||
<div className="mb-4 flex rounded-md border border-border/60 bg-panel p-1 text-sm">
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setMode("login")}
|
||||
className={cn(
|
||||
"flex-1 rounded py-1.5 font-medium transition-colors",
|
||||
mode === "login" ? "bg-panel-hover text-foreground" : "text-muted-foreground"
|
||||
)}
|
||||
>
|
||||
Connexion
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setMode("signup")}
|
||||
className={cn(
|
||||
"flex-1 rounded py-1.5 font-medium transition-colors",
|
||||
mode === "signup" ? "bg-panel-hover text-foreground" : "text-muted-foreground"
|
||||
)}
|
||||
>
|
||||
Créer un compte
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<form action={action} className="space-y-3">
|
||||
<input type="hidden" name="next" value={next} />
|
||||
{mode === "signup" && (
|
||||
<div className="space-y-1.5">
|
||||
<Label htmlFor="name">Nom</Label>
|
||||
<Input id="name" name="name" type="text" required autoComplete="name" />
|
||||
</div>
|
||||
)}
|
||||
<div className="space-y-1.5">
|
||||
<Label htmlFor="email">Courriel</Label>
|
||||
<Input id="email" name="email" type="email" required autoComplete="email" />
|
||||
</div>
|
||||
<div className="space-y-1.5">
|
||||
<Label htmlFor="password">Mot de passe</Label>
|
||||
<Input
|
||||
id="password"
|
||||
name="password"
|
||||
type="password"
|
||||
required
|
||||
minLength={mode === "signup" ? 8 : undefined}
|
||||
autoComplete={mode === "login" ? "current-password" : "new-password"}
|
||||
/>
|
||||
{mode === "signup" && (
|
||||
<p className="text-[11px] text-muted-foreground">8 caractères minimum.</p>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{!state.ok && state.message && <p className="text-xs text-destructive">{state.message}</p>}
|
||||
|
||||
<Button type="submit" disabled={pending} className="w-full">
|
||||
{pending ? "…" : mode === "login" ? "Se connecter" : "Créer mon compte"}
|
||||
</Button>
|
||||
</form>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
"use client"
|
||||
|
||||
import { useActionState } from "react"
|
||||
import { setNicknameAction, type NicknameState } from "@/app/profil/actions"
|
||||
import { Input } from "@/components/ui/input"
|
||||
import { Button } from "@/components/ui/button"
|
||||
|
||||
const INITIAL: NicknameState = { ok: false, message: "" }
|
||||
|
||||
export function NicknameForm({ currentNickname }: { currentNickname: string | null }) {
|
||||
const [state, action, pending] = useActionState(setNicknameAction, INITIAL)
|
||||
|
||||
return (
|
||||
<form action={action} className="flex items-center gap-2">
|
||||
<Input name="nickname" defaultValue={currentNickname ?? ""} placeholder="Votre pseudo" maxLength={24} />
|
||||
<Button type="submit" disabled={pending} size="sm">
|
||||
{pending ? "…" : "Enregistrer"}
|
||||
</Button>
|
||||
{state.message && (
|
||||
<span className={state.ok ? "text-xs text-success" : "text-xs text-destructive"}>{state.message}</span>
|
||||
)}
|
||||
</form>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,111 @@
|
||||
"use client"
|
||||
|
||||
import * as React from "react"
|
||||
import { cn } from "cn"
|
||||
import { Avatar as AvatarPrimitive } from "radix-ui"
|
||||
|
||||
function Avatar({
|
||||
className,
|
||||
size = "default",
|
||||
...props
|
||||
}: React.ComponentProps<typeof AvatarPrimitive.Root> & {
|
||||
size?: "default" | "sm" | "lg"
|
||||
}) {
|
||||
return (
|
||||
<AvatarPrimitive.Root
|
||||
data-slot="avatar"
|
||||
data-size={size}
|
||||
className={cn(
|
||||
"group/avatar relative flex size-8 shrink-0 rounded-full select-none after:absolute after:inset-0 after:rounded-full after:border after:border-border after:mix-blend-darken data-[size=lg]:size-10 data-[size=sm]:size-6 dark:after:mix-blend-lighten",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function AvatarImage({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<typeof AvatarPrimitive.Image>) {
|
||||
return (
|
||||
<AvatarPrimitive.Image
|
||||
data-slot="avatar-image"
|
||||
className={cn(
|
||||
"aspect-square size-full rounded-full object-cover",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function AvatarFallback({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<typeof AvatarPrimitive.Fallback>) {
|
||||
return (
|
||||
<AvatarPrimitive.Fallback
|
||||
data-slot="avatar-fallback"
|
||||
className={cn(
|
||||
"flex size-full items-center justify-center rounded-full bg-muted text-sm text-muted-foreground group-data-[size=sm]/avatar:text-xs",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function AvatarBadge({ className, ...props }: React.ComponentProps<"span">) {
|
||||
return (
|
||||
<span
|
||||
data-slot="avatar-badge"
|
||||
className={cn(
|
||||
"absolute right-0 bottom-0 z-10 inline-flex items-center justify-center rounded-full bg-primary text-primary-foreground bg-blend-color ring-2 ring-background select-none",
|
||||
"group-data-[size=sm]/avatar:size-2 group-data-[size=sm]/avatar:[&>svg]:hidden",
|
||||
"group-data-[size=default]/avatar:size-2.5 group-data-[size=default]/avatar:[&>svg]:size-2",
|
||||
"group-data-[size=lg]/avatar:size-3 group-data-[size=lg]/avatar:[&>svg]:size-2",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function AvatarGroup({ className, ...props }: React.ComponentProps<"div">) {
|
||||
return (
|
||||
<div
|
||||
data-slot="avatar-group"
|
||||
className={cn(
|
||||
"group/avatar-group flex -space-x-2 *:data-[slot=avatar]:ring-2 *:data-[slot=avatar]:ring-background",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function AvatarGroupCount({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<"div">) {
|
||||
return (
|
||||
<div
|
||||
data-slot="avatar-group-count"
|
||||
className={cn(
|
||||
"relative flex size-8 shrink-0 items-center justify-center rounded-full bg-muted text-sm text-muted-foreground ring-2 ring-background group-has-data-[size=lg]/avatar-group:size-10 group-has-data-[size=sm]/avatar-group:size-6 [&>svg]:size-4 group-has-data-[size=lg]/avatar-group:[&>svg]:size-5 group-has-data-[size=sm]/avatar-group:[&>svg]:size-3",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
export {
|
||||
Avatar,
|
||||
AvatarImage,
|
||||
AvatarFallback,
|
||||
AvatarGroup,
|
||||
AvatarGroupCount,
|
||||
AvatarBadge,
|
||||
}
|
||||
@@ -0,0 +1,268 @@
|
||||
"use client"
|
||||
|
||||
import * as React from "react"
|
||||
import { cn } from "cn"
|
||||
import { DropdownMenu as DropdownMenuPrimitive } from "radix-ui"
|
||||
import { CheckIcon, ChevronRightIcon } from "lucide-react"
|
||||
|
||||
function DropdownMenu({
|
||||
...props
|
||||
}: React.ComponentProps<typeof DropdownMenuPrimitive.Root>) {
|
||||
return <DropdownMenuPrimitive.Root data-slot="dropdown-menu" {...props} />
|
||||
}
|
||||
|
||||
function DropdownMenuPortal({
|
||||
...props
|
||||
}: React.ComponentProps<typeof DropdownMenuPrimitive.Portal>) {
|
||||
return (
|
||||
<DropdownMenuPrimitive.Portal data-slot="dropdown-menu-portal" {...props} />
|
||||
)
|
||||
}
|
||||
|
||||
function DropdownMenuTrigger({
|
||||
...props
|
||||
}: React.ComponentProps<typeof DropdownMenuPrimitive.Trigger>) {
|
||||
return (
|
||||
<DropdownMenuPrimitive.Trigger
|
||||
data-slot="dropdown-menu-trigger"
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function DropdownMenuContent({
|
||||
className,
|
||||
align = "start",
|
||||
sideOffset = 4,
|
||||
...props
|
||||
}: React.ComponentProps<typeof DropdownMenuPrimitive.Content>) {
|
||||
return (
|
||||
<DropdownMenuPrimitive.Portal>
|
||||
<DropdownMenuPrimitive.Content
|
||||
data-slot="dropdown-menu-content"
|
||||
sideOffset={sideOffset}
|
||||
align={align}
|
||||
className={cn("z-50 max-h-(--radix-dropdown-menu-content-available-height) w-(--radix-dropdown-menu-trigger-width) min-w-32 origin-(--radix-dropdown-menu-content-transform-origin) overflow-x-hidden overflow-y-auto rounded-lg bg-popover p-1 text-popover-foreground shadow-md ring-1 ring-foreground/10 duration-100 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 data-[state=closed]:overflow-hidden data-open:animate-in data-open:fade-in-0 data-open:zoom-in-95 data-closed:animate-out data-closed:fade-out-0 data-closed:zoom-out-95", className )}
|
||||
{...props}
|
||||
/>
|
||||
</DropdownMenuPrimitive.Portal>
|
||||
)
|
||||
}
|
||||
|
||||
function DropdownMenuGroup({
|
||||
...props
|
||||
}: React.ComponentProps<typeof DropdownMenuPrimitive.Group>) {
|
||||
return (
|
||||
<DropdownMenuPrimitive.Group data-slot="dropdown-menu-group" {...props} />
|
||||
)
|
||||
}
|
||||
|
||||
function DropdownMenuItem({
|
||||
className,
|
||||
inset,
|
||||
variant = "default",
|
||||
...props
|
||||
}: React.ComponentProps<typeof DropdownMenuPrimitive.Item> & {
|
||||
inset?: boolean
|
||||
variant?: "default" | "destructive"
|
||||
}) {
|
||||
return (
|
||||
<DropdownMenuPrimitive.Item
|
||||
data-slot="dropdown-menu-item"
|
||||
data-inset={inset}
|
||||
data-variant={variant}
|
||||
className={cn(
|
||||
"group/dropdown-menu-item relative flex cursor-default items-center gap-1.5 rounded-md px-1.5 py-1 text-sm outline-hidden select-none focus:bg-accent focus:text-accent-foreground not-data-[variant=destructive]:focus:**:text-accent-foreground data-inset:pl-7 data-[variant=destructive]:text-destructive data-[variant=destructive]:focus:bg-destructive/10 data-[variant=destructive]:focus:text-destructive dark:data-[variant=destructive]:focus:bg-destructive/20 data-disabled:pointer-events-none data-disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4 data-[variant=destructive]:*:[svg]:text-destructive",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function DropdownMenuCheckboxItem({
|
||||
className,
|
||||
children,
|
||||
checked,
|
||||
inset,
|
||||
...props
|
||||
}: React.ComponentProps<typeof DropdownMenuPrimitive.CheckboxItem> & {
|
||||
inset?: boolean
|
||||
}) {
|
||||
return (
|
||||
<DropdownMenuPrimitive.CheckboxItem
|
||||
data-slot="dropdown-menu-checkbox-item"
|
||||
data-inset={inset}
|
||||
className={cn(
|
||||
"relative flex cursor-default items-center gap-1.5 rounded-md py-1 pr-8 pl-1.5 text-sm outline-hidden select-none focus:bg-accent focus:text-accent-foreground focus:**:text-accent-foreground data-inset:pl-7 data-disabled:pointer-events-none data-disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
|
||||
className
|
||||
)}
|
||||
checked={checked}
|
||||
{...props}
|
||||
>
|
||||
<span
|
||||
className="pointer-events-none absolute right-2 flex items-center justify-center"
|
||||
data-slot="dropdown-menu-checkbox-item-indicator"
|
||||
>
|
||||
<DropdownMenuPrimitive.ItemIndicator>
|
||||
<CheckIcon
|
||||
/>
|
||||
</DropdownMenuPrimitive.ItemIndicator>
|
||||
</span>
|
||||
{children}
|
||||
</DropdownMenuPrimitive.CheckboxItem>
|
||||
)
|
||||
}
|
||||
|
||||
function DropdownMenuRadioGroup({
|
||||
...props
|
||||
}: React.ComponentProps<typeof DropdownMenuPrimitive.RadioGroup>) {
|
||||
return (
|
||||
<DropdownMenuPrimitive.RadioGroup
|
||||
data-slot="dropdown-menu-radio-group"
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function DropdownMenuRadioItem({
|
||||
className,
|
||||
children,
|
||||
inset,
|
||||
...props
|
||||
}: React.ComponentProps<typeof DropdownMenuPrimitive.RadioItem> & {
|
||||
inset?: boolean
|
||||
}) {
|
||||
return (
|
||||
<DropdownMenuPrimitive.RadioItem
|
||||
data-slot="dropdown-menu-radio-item"
|
||||
data-inset={inset}
|
||||
className={cn(
|
||||
"relative flex cursor-default items-center gap-1.5 rounded-md py-1 pr-8 pl-1.5 text-sm outline-hidden select-none focus:bg-accent focus:text-accent-foreground focus:**:text-accent-foreground data-inset:pl-7 data-disabled:pointer-events-none data-disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
>
|
||||
<span
|
||||
className="pointer-events-none absolute right-2 flex items-center justify-center"
|
||||
data-slot="dropdown-menu-radio-item-indicator"
|
||||
>
|
||||
<DropdownMenuPrimitive.ItemIndicator>
|
||||
<CheckIcon
|
||||
/>
|
||||
</DropdownMenuPrimitive.ItemIndicator>
|
||||
</span>
|
||||
{children}
|
||||
</DropdownMenuPrimitive.RadioItem>
|
||||
)
|
||||
}
|
||||
|
||||
function DropdownMenuLabel({
|
||||
className,
|
||||
inset,
|
||||
...props
|
||||
}: React.ComponentProps<typeof DropdownMenuPrimitive.Label> & {
|
||||
inset?: boolean
|
||||
}) {
|
||||
return (
|
||||
<DropdownMenuPrimitive.Label
|
||||
data-slot="dropdown-menu-label"
|
||||
data-inset={inset}
|
||||
className={cn(
|
||||
"px-1.5 py-1 text-xs font-medium text-muted-foreground data-inset:pl-7",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function DropdownMenuSeparator({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<typeof DropdownMenuPrimitive.Separator>) {
|
||||
return (
|
||||
<DropdownMenuPrimitive.Separator
|
||||
data-slot="dropdown-menu-separator"
|
||||
className={cn("-mx-1 my-1 h-px bg-border", className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function DropdownMenuShortcut({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<"span">) {
|
||||
return (
|
||||
<span
|
||||
data-slot="dropdown-menu-shortcut"
|
||||
className={cn(
|
||||
"ml-auto text-xs tracking-widest text-muted-foreground group-focus/dropdown-menu-item:text-accent-foreground",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function DropdownMenuSub({
|
||||
...props
|
||||
}: React.ComponentProps<typeof DropdownMenuPrimitive.Sub>) {
|
||||
return <DropdownMenuPrimitive.Sub data-slot="dropdown-menu-sub" {...props} />
|
||||
}
|
||||
|
||||
function DropdownMenuSubTrigger({
|
||||
className,
|
||||
inset,
|
||||
children,
|
||||
...props
|
||||
}: React.ComponentProps<typeof DropdownMenuPrimitive.SubTrigger> & {
|
||||
inset?: boolean
|
||||
}) {
|
||||
return (
|
||||
<DropdownMenuPrimitive.SubTrigger
|
||||
data-slot="dropdown-menu-sub-trigger"
|
||||
data-inset={inset}
|
||||
className={cn(
|
||||
"flex cursor-default items-center gap-1.5 rounded-md px-1.5 py-1 text-sm outline-hidden select-none focus:bg-accent focus:text-accent-foreground not-data-[variant=destructive]:focus:**:text-accent-foreground data-inset:pl-7 data-open:bg-accent data-open:text-accent-foreground [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
>
|
||||
{children}
|
||||
<ChevronRightIcon className="ml-auto" />
|
||||
</DropdownMenuPrimitive.SubTrigger>
|
||||
)
|
||||
}
|
||||
|
||||
function DropdownMenuSubContent({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<typeof DropdownMenuPrimitive.SubContent>) {
|
||||
return (
|
||||
<DropdownMenuPrimitive.SubContent
|
||||
data-slot="dropdown-menu-sub-content"
|
||||
className={cn("z-50 min-w-[96px] origin-(--radix-dropdown-menu-content-transform-origin) overflow-hidden rounded-lg bg-popover p-1 text-popover-foreground shadow-lg ring-1 ring-foreground/10 duration-100 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 data-open:animate-in data-open:fade-in-0 data-open:zoom-in-95 data-closed:animate-out data-closed:fade-out-0 data-closed:zoom-out-95", className )}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
export {
|
||||
DropdownMenu,
|
||||
DropdownMenuPortal,
|
||||
DropdownMenuTrigger,
|
||||
DropdownMenuContent,
|
||||
DropdownMenuGroup,
|
||||
DropdownMenuLabel,
|
||||
DropdownMenuItem,
|
||||
DropdownMenuCheckboxItem,
|
||||
DropdownMenuRadioGroup,
|
||||
DropdownMenuRadioItem,
|
||||
DropdownMenuSeparator,
|
||||
DropdownMenuShortcut,
|
||||
DropdownMenuSub,
|
||||
DropdownMenuSubTrigger,
|
||||
DropdownMenuSubContent,
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
import * as React from "react"
|
||||
import { cn } from "cn"
|
||||
|
||||
function Input({ className, type, ...props }: React.ComponentProps<"input">) {
|
||||
return (
|
||||
<input
|
||||
type={type}
|
||||
data-slot="input"
|
||||
className={cn(
|
||||
"h-8 w-full min-w-0 rounded-lg border border-input bg-transparent px-2.5 py-1 text-base transition-colors outline-none file:inline-flex file:h-6 file:border-0 file:bg-transparent file:text-sm file:font-medium file:text-foreground placeholder:text-muted-foreground focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/50 disabled:pointer-events-none disabled:cursor-not-allowed disabled:bg-input/50 disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-3 aria-invalid:ring-destructive/20 md:text-sm dark:bg-input/30 dark:disabled:bg-input/80 dark:aria-invalid:border-destructive/50 dark:aria-invalid:ring-destructive/40",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
export { Input }
|
||||
@@ -0,0 +1,23 @@
|
||||
"use client"
|
||||
|
||||
import * as React from "react"
|
||||
import { cn } from "cn"
|
||||
import { Label as LabelPrimitive } from "radix-ui"
|
||||
|
||||
function Label({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<typeof LabelPrimitive.Root>) {
|
||||
return (
|
||||
<LabelPrimitive.Root
|
||||
data-slot="label"
|
||||
className={cn(
|
||||
"flex items-center gap-2 text-sm leading-none font-medium select-none group-data-[disabled=true]:pointer-events-none group-data-[disabled=true]:opacity-50 peer-disabled:cursor-not-allowed peer-disabled:opacity-50",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
export { Label }
|
||||
@@ -0,0 +1,55 @@
|
||||
import Link from "next/link"
|
||||
import { getCurrentMember } from "@/lib/member-auth"
|
||||
import { Button } from "@/components/ui/button"
|
||||
import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar"
|
||||
import {
|
||||
DropdownMenu,
|
||||
DropdownMenuContent,
|
||||
DropdownMenuItem,
|
||||
DropdownMenuSeparator,
|
||||
DropdownMenuTrigger,
|
||||
} from "@/components/ui/dropdown-menu"
|
||||
|
||||
export async function UserMenu() {
|
||||
const member = await getCurrentMember()
|
||||
|
||||
if (!member) {
|
||||
return (
|
||||
<Button asChild size="sm">
|
||||
<Link href="/connexion">Connexion</Link>
|
||||
</Button>
|
||||
)
|
||||
}
|
||||
|
||||
const displayName = member.publicNickname || member.name
|
||||
const initial = displayName.charAt(0).toUpperCase()
|
||||
|
||||
return (
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger className="flex items-center gap-2 rounded-full outline-none focus-visible:ring-2 focus-visible:ring-ring">
|
||||
<Avatar className="h-8 w-8">
|
||||
<AvatarImage src={member.avatarUrl ?? undefined} alt="" />
|
||||
<AvatarFallback>{initial}</AvatarFallback>
|
||||
</Avatar>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent align="end" className="w-52">
|
||||
<div className="px-2 py-1.5 text-sm font-medium">{displayName}</div>
|
||||
<DropdownMenuSeparator />
|
||||
<DropdownMenuItem asChild>
|
||||
<Link href="/profil">Mon profil</Link>
|
||||
</DropdownMenuItem>
|
||||
<DropdownMenuItem asChild>
|
||||
<Link href="/classement">Classement</Link>
|
||||
</DropdownMenuItem>
|
||||
<DropdownMenuSeparator />
|
||||
<DropdownMenuItem asChild>
|
||||
<form action="/api/auth/logout" method="post" className="w-full">
|
||||
<button type="submit" className="w-full text-left">
|
||||
Déconnexion
|
||||
</button>
|
||||
</form>
|
||||
</DropdownMenuItem>
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user