c1ecdff729
The fixed-position music button covered content on mobile. Removed it from the global overlay; mute now lives in the TopBar icon group (Home), and the in-game HUD + Profile settings already have their own audio controls. Tightened the TopBar icon row (p-1.5, gap-1, profile max-w-44%) so the extra button still fits 360px phones. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
103 lines
4.2 KiB
TypeScript
103 lines
4.2 KiB
TypeScript
"use client";
|
|
|
|
import { Bell, Crown, Gift, Music, Store } from "lucide-react";
|
|
import { useSessionStore } from "@/lib/session-store";
|
|
import { useSoundStore } from "@/lib/sound-store";
|
|
import { useUIStore } from "@/lib/ui-store";
|
|
import { useNotifStore } from "@/lib/notification-store";
|
|
import { useI18n } from "@/lib/i18n";
|
|
import { MAX_LEVEL, xpNeededForLevel } from "@/lib/online/gamification";
|
|
import { Avatar } from "./Avatar";
|
|
import { CoinsPill } from "./CoinsPill";
|
|
|
|
export function TopBar() {
|
|
const profile = useSessionStore((s) => s.profile);
|
|
const go = useUIStore((s) => s.go);
|
|
const openDaily = useUIStore((s) => s.openDaily);
|
|
const unread = useNotifStore((s) => s.unread);
|
|
const music = useSoundStore((s) => s.music);
|
|
const toggleMusic = useSoundStore((s) => s.toggleMusic);
|
|
const { t } = useI18n();
|
|
if (!profile) return null;
|
|
|
|
const maxed = profile.level >= MAX_LEVEL;
|
|
const xpNeed = xpNeededForLevel(profile.level);
|
|
const xpPct = maxed ? 100 : Math.min(100, Math.max(0, Math.round((profile.xp / xpNeed) * 100)));
|
|
|
|
return (
|
|
<div className="flex items-center justify-between gap-2">
|
|
<button
|
|
onClick={() => go("profile")}
|
|
className="glass rounded-full ltr:pr-3 rtl:pl-3 ltr:pl-1 rtl:pr-1 py-1 flex items-center gap-2 min-w-0 max-w-[44%] hover:bg-navy-800/80 transition"
|
|
>
|
|
<span className="relative size-9 shrink-0 rounded-full bg-navy-900 gold-border flex items-center justify-center overflow-hidden">
|
|
<Avatar id={profile.avatar} image={profile.avatarImage} size={profile.avatarImage ? 36 : 26} />
|
|
</span>
|
|
<span className="text-start leading-tight min-w-0 flex-1">
|
|
<span className="flex items-center gap-1 text-sm font-bold text-cream truncate">
|
|
<span className="truncate">{profile.displayName}</span>
|
|
{profile.plan === "pro" && <Crown className="size-3 text-gold-400 fill-gold-500 shrink-0" />}
|
|
</span>
|
|
<span className="mt-1 flex items-center gap-1.5">
|
|
<span className="text-[10px] text-gold-400/80 shrink-0 whitespace-nowrap">
|
|
{t("common.level")} {profile.level}
|
|
</span>
|
|
<span className="h-1.5 flex-1 min-w-6 rounded-full bg-navy-900 overflow-hidden">
|
|
<span
|
|
className="block h-full rounded-full bg-gradient-to-r from-gold-500 to-gold-300"
|
|
style={{ width: `${xpPct}%` }}
|
|
/>
|
|
</span>
|
|
<span className="text-[9px] text-cream/40 tabular-nums shrink-0">{maxed ? "MAX" : `${xpPct}%`}</span>
|
|
</span>
|
|
</span>
|
|
</button>
|
|
|
|
<div className="flex items-center gap-1 shrink-0">
|
|
<button
|
|
onClick={toggleMusic}
|
|
className="glass rounded-full p-1.5 hover:bg-navy-800/80 transition"
|
|
title={t("settings.music")}
|
|
aria-label={t("settings.music")}
|
|
>
|
|
{music ? (
|
|
<Music className="size-4 text-gold-400" />
|
|
) : (
|
|
<span className="relative grid place-items-center">
|
|
<Music className="size-4 text-cream/40" />
|
|
<span className="absolute block h-0.5 w-5 rotate-45 rounded bg-rose-400" />
|
|
</span>
|
|
)}
|
|
</button>
|
|
<button
|
|
onClick={() => go("notifications")}
|
|
className="glass rounded-full p-2 hover:bg-navy-800/80 transition relative"
|
|
title={t("notif.title")}
|
|
>
|
|
<Bell className="size-4 text-gold-400" />
|
|
{unread > 0 && (
|
|
<span className="absolute -top-0.5 ltr:-right-0.5 rtl:-left-0.5 min-w-4 h-4 px-1 rounded-full bg-rose-500 text-[9px] font-bold text-white flex items-center justify-center">
|
|
{unread > 9 ? "9+" : unread}
|
|
</span>
|
|
)}
|
|
</button>
|
|
<button
|
|
onClick={openDaily}
|
|
className="glass rounded-full p-1.5 hover:bg-navy-800/80 transition"
|
|
title={t("daily.title")}
|
|
>
|
|
<Gift className="size-4 text-gold-400" />
|
|
</button>
|
|
<button
|
|
onClick={() => go("shop")}
|
|
className="glass rounded-full p-1.5 hover:bg-navy-800/80 transition"
|
|
title={t("menu.shop")}
|
|
>
|
|
<Store className="size-4 text-gold-400" />
|
|
</button>
|
|
<CoinsPill />
|
|
</div>
|
|
</div>
|
|
);
|
|
}
|