Skip to content

A desktop coding agent with free access to frontier models.

TypeScript

feat(desktop): rewards UI in the app's own dialog, toast, badge and sidebar styles

ogsamratd1cf5320c583
diff --git a/apps/app/src/app/index.css b/apps/app/src/app/index.css
index 22f740ea..f6f9f9df 100644
--- a/apps/app/src/app/index.css
+++ b/apps/app/src/app/index.css
@@ -824,19 +824,3 @@ select:disabled {
[data-update-gate-shifted] .min-h-screen {
min-height: 100%;
}
-
-/* Quality rewards wheel (react-app/domains/quality/quality-wheel.tsx): the
- rim's bulbs chase while it spins. */
-@keyframes quality-wheel-bulb {
- 0%, 100% { opacity: 1; }
- 50% { opacity: 0.25; }
-}
-[data-spinning="true"] .quality-wheel-bulb {
- animation: quality-wheel-bulb 0.45s ease-in-out infinite;
-}
-[data-spinning="true"] .quality-wheel-bulb:nth-of-type(even) {
- animation-delay: 0.22s;
-}
-@media (prefers-reduced-motion: reduce) {
- [data-spinning="true"] .quality-wheel-bulb { animation: none; }
-}
diff --git a/apps/app/src/app/lib/quality.ts b/apps/app/src/app/lib/quality.ts
index 319d187c..4e5c7cfe 100644
--- a/apps/app/src/app/lib/quality.ts
+++ b/apps/app/src/app/lib/quality.ts
@@ -181,42 +181,13 @@ export function wheelTargetRotation(
}
/**
- * The spin's shape over time: a short acceleration, a long deceleration
- * that overshoots the stop by `overshoot` degrees, and a settle back onto
- * it. `progress` is 0..1; the result goes from `from` to `to`.
+ * The spin's shape over time: one ease-out (quartic) from `from` to `to`,
+ * no wind-up and no overshoot. `progress` is 0..1.
*/
-export function wheelAngleAt(progress: number, from: number, to: number, overshoot = 0): number {
+export function wheelEaseOut(progress: number, from: number, to: number): number {
const p = Math.min(1, Math.max(0, progress));
- const distance = to - from;
- const ACCEL = 0.12;
- const SETTLE = 0.88;
- // Velocity ramps up linearly over ACCEL and decays as a cubic after it, so
- // the curve is smooth where the phases meet. Normalised so it ends on `to + overshoot`.
- const accelArea = ACCEL / 2;
- const decelArea = (SETTLE - ACCEL) / 4;
- const total = accelArea + decelArea;
- const reach = distance + overshoot;
- if (p >= SETTLE) {
- const q = (p - SETTLE) / (1 - SETTLE);
- const ease = q * q * (3 - 2 * q);
- return to + overshoot * (1 - ease);
- }
- if (p <= ACCEL) {
- const area = (p * p) / (2 * ACCEL);
- return from + reach * (area / total);
- }
- const d = (p - ACCEL) / (SETTLE - ACCEL);
- const area = accelArea + ((SETTLE - ACCEL) * (1 - (1 - d) ** 4)) / 4;
- return from + reach * (area / total);
-}
-
-/** How far the wheel may overshoot its stop without leaving the slice. */
-export function wheelOvershoot(segments: WheelSegment[], index: number, offset = 0): number {
- const slice = wheelSlices(segments)[index];
- if (!slice) return 0;
- const half = (slice.end - slice.start) / 2;
- const room = half * (1 - Math.max(-0.7, Math.min(0.7, offset)));
- return Math.min(6, room * 0.6);
+ if (p >= 1) return to;
+ return from + (to - from) * (1 - (1 - p) ** 4);
}
/** "12%": a segment's share of the weights. */
@@ -273,7 +244,7 @@ export function nearMissText(spin: QualitySpin, jackpotTokens?: number | null):
/** The star, explained wherever it shows. */
export const CLIENT_GRADE_NOTE = "★ Replay-ready sessions earn +2 spins on a richer wheel.";
/** What users read for a client-grade session or spin (internal fields keep `client`). */
-export const REPLAY_READY_LABEL = "replay-ready ★";
+export const REPLAY_READY_LABEL = "Replay-ready ★";
/**
* The prize shown `progress` (0..1) into the count-up: an ease-out that never
diff --git a/apps/app/src/react-app/domains/quality/quality-notice.tsx b/apps/app/src/react-app/domains/quality/quality-notice.tsx
index cec56623..138ae116 100644
--- a/apps/app/src/react-app/domains/quality/quality-notice.tsx
+++ b/apps/app/src/react-app/domains/quality/quality-notice.tsx
@@ -1,7 +1,9 @@
/** @jsxImportSource react */
import { useCallback, useEffect, useState } from "react";
-import { ChevronDown, Gift, Lightbulb, Sparkles, X } from "lucide-react";
+import { ChevronDown, Gift, Lightbulb, X } from "lucide-react";
+import { Badge } from "@/components/ui/badge";
+import { Button } from "@/components/ui/button";
import { cn } from "@/lib/utils";
import { omnirushAccountStatus, omnirushQualityDetails } from "../../../app/lib/desktop";
@@ -56,35 +58,35 @@ function workSummary(work: OmniRushQualitySession["work"]): string | null {
/** "See why": each recent session, with what earned spins and what held it back. */
export function SessionReasons({ reasons }: { reasons: QualitySessionReasons | null }) {
- if (reasons === null) return <div className="text-xs text-white/50">Loading your sessions…</div>;
+ if (reasons === null) return <div className="text-xs text-muted-foreground">Loading your sessions…</div>;
const { sessions, failLabels } = reasons;
- if (sessions === null) return <div className="text-xs text-white/50">Loading your sessions…</div>;
- if (!sessions.length) return <div className="text-xs text-white/50">No sessions checked yet. They are checked about once an hour.</div>;
+ if (sessions === null) return <div className="text-xs text-muted-foreground">Loading your sessions…</div>;
+ if (!sessions.length) return <div className="text-xs text-muted-foreground">No sessions checked yet. They are checked about once an hour.</div>;
return (
<>
- <p className="mb-2 text-[11px] text-amber-200/80" data-testid="quality-client-grade-note">{CLIENT_GRADE_NOTE}</p>
- <ul className="space-y-2" data-testid="quality-session-reasons">
+ <p className="mb-2 text-xs text-muted-foreground" data-testid="quality-client-grade-note">{CLIENT_GRADE_NOTE}</p>
+ <ul className="flex flex-col gap-1.5" data-testid="quality-session-reasons">
{sessions.slice(0, 6).map((session) => (
- <li key={session.sessionId} className="rounded-xl border border-white/10 bg-black/20 px-3 py-2">
- <div className="flex items-center justify-between gap-2 text-[11px] text-white/50">
+ <li key={session.sessionId} className="rounded-lg border border-border px-3 py-2">
+ <div className="flex items-center justify-between gap-2 text-xs text-muted-foreground">
<span className="truncate">{session.workspace ?? "session"}</span>
{session.spins > 0 ? (
- <span className="shrink-0 font-semibold text-[#bef264]">+{session.spins} spin{session.spins === 1 ? "" : "s"}</span>
+ <span className="shrink-0 font-medium text-foreground">+{session.spins} spin{session.spins === 1 ? "" : "s"}</span>
) : null}
</div>
- {session.why ? <div className="mt-0.5 text-xs leading-5 text-white/80">{session.why}</div> : null}
- {workSummary(session.work) ? <div className="mt-0.5 text-[10.5px] text-white/45">{workSummary(session.work)}</div> : null}
+ {session.why ? <div className="mt-0.5 text-xs leading-5 text-foreground">{session.why}</div> : null}
+ {workSummary(session.work) ? <div className="mt-0.5 text-[11px] text-muted-foreground">{workSummary(session.work)}</div> : null}
{session.fails.length || session.reproducible === "pass" || session.clientGrade ? (
- <div className="mt-1 flex flex-wrap gap-1">
+ <div className="mt-1.5 flex flex-wrap gap-1">
{session.clientGrade ? (
- <span data-testid="quality-client-grade" className="rounded-full bg-amber-300/15 px-1.5 py-0.5 text-[10px] font-semibold text-amber-200">{REPLAY_READY_LABEL}</span>
+ <Badge variant="secondary" data-testid="quality-client-grade" className="h-4 px-1.5 text-[10px] font-normal text-muted-foreground">{REPLAY_READY_LABEL}</Badge>
) : session.reproducible === "pass" ? (
- <span data-testid="quality-reproducible" className="rounded-full bg-[#a3e635]/15 px-1.5 py-0.5 text-[10px] text-[#d9f99d]">reproducible ✓</span>
+ <Badge variant="secondary" data-testid="quality-reproducible" className="h-4 px-1.5 text-[10px] font-normal text-muted-foreground">Reproducible ✓</Badge>
) : null}
{session.fails.map((fail) => (
- <span key={fail} data-fail={fail} className="rounded-full bg-white/[0.06] px-1.5 py-0.5 text-[10px] text-white/60">
+ <Badge key={fail} variant="outline" data-fail={fail} className="h-4 px-1.5 text-[10px] font-normal text-muted-foreground">
{failLabel(fail, failLabels)}
- </span>
+ </Badge>
))}
</div>
) : null}
@@ -105,10 +107,14 @@ export type QualityNoticeCardProps = {
loadSessions?: () => Promise<QualitySessionReasons | null>;
};
+/** The app's toast surface: popover colours, a hairline border, small radius. */
+const TOAST_SURFACE =
+ "rounded-2xl border border-border bg-popover/95 text-popover-foreground shadow-md ring-1 ring-popover-border/20 backdrop-blur-sm";
+
/**
- * The quality popup, modelled on the update banner: fixed over the app,
- * with the notice, the tips and, when spins are ready, a Spin button.
- * Coaching reads as "here is how to get spins", never as a penalty.
+ * The quality popup, in the app's toast style: fixed over the app, with the
+ * notice, the tips and, when spins are ready, a Spin button. Coaching reads
+ * as "here is how to get spins", never as a penalty.
*/
export function QualityNoticeCard(props: QualityNoticeCardProps) {
const { quality, notice } = props;
@@ -118,6 +124,7 @@ export function QualityNoticeCard(props: QualityNoticeCardProps) {
const title = notice?.title ?? `Quality: ${qualityTierLabel(quality.tier)}`;
const body = notice?.body || (notice ? "" : quality.nextTierHint ?? "");
const spinnable = canSpinNow(quality);
+ const Icon = coaching ? Lightbulb : Gift;
const toggleWhy = () => {
setWhyOpen((open) => !open);
@@ -134,53 +141,53 @@ export function QualityNoticeCard(props: QualityNoticeCardProps) {
data-testid="quality-notice"
data-notice-id={notice?.id ?? undefined}
data-coaching={coaching ? "" : undefined}
- className="fixed bottom-4 right-4 z-[65] w-[380px] max-w-[calc(100vw-2rem)] overflow-hidden rounded-3xl border border-white/10 bg-[#0b1120]/95 text-white shadow-2xl shadow-black/50 backdrop-blur"
+ className={cn("fixed bottom-4 right-4 z-[65] flex w-[360px] max-w-[calc(100vw-2rem)] flex-col gap-3 p-4", TOAST_SURFACE)}
>
- <div className={cn("h-1 w-full", coaching ? "bg-violet-300/70" : "bg-[#a3e635]")} />
- <div className="p-5">
- <div className="flex items-start justify-between gap-3">
- <div className="flex items-center gap-2 text-[10px] font-semibold uppercase tracking-[0.2em] text-white/50">
- {coaching ? <Lightbulb className="size-3.5 text-violet-300" /> : <Sparkles className="size-3.5 text-[#a3e635]" />}
- {coaching ? "How to earn spins" : "Quality rewards"}
+ <div className="flex items-start gap-3">
+ <Icon className="mt-0.5 size-4 shrink-0 text-muted-foreground" aria-hidden="true" />
+ <div className="flex min-w-0 flex-1 flex-col gap-1">
+ <div className="flex min-w-0 items-center gap-2">
+ <p className="text-sm font-medium" data-testid="quality-notice-title">{title}</p>
<QualityTierBadge quality={quality} />
</div>
- <button
- type="button"
- onClick={props.onDismiss}
- aria-label="Dismiss"
- data-testid="quality-notice-dismiss"
- className="-me-1 -mt-1 flex size-7 items-center justify-center rounded-full text-white/50 transition hover:bg-white/10 hover:text-white"
- >
- <X className="size-4" />
- </button>
+ {body ? <p className="text-sm text-muted-foreground" data-testid="quality-notice-body">{body}</p> : null}
</div>
- <h3 className="mt-3 text-lg font-semibold leading-6 tracking-[-0.01em]" data-testid="quality-notice-title">{title}</h3>
- {body ? <p className="mt-1.5 text-sm leading-6 text-white/70" data-testid="quality-notice-body">{body}</p> : null}
+ <Button
+ type="button"
+ variant="ghost"
+ size="icon-xs"
+ onClick={props.onDismiss}
+ aria-label="Dismiss"
+ data-testid="quality-notice-dismiss"
+ className="-me-1 -mt-0.5 text-muted-foreground"
+ >
+ <X />
+ </Button>
+ </div>
- <div className="mt-3 space-y-2.5">
- <StreakLine quality={quality} />
- <NextSpinHint quality={quality} />
- </div>
+ <div className="flex flex-col gap-2 ps-7">
+ <StreakLine quality={quality} />
+ <NextSpinHint quality={quality} />
{quality.tips.length ? (
- <ul className="mt-3 space-y-1.5 rounded-2xl border border-white/10 bg-white/[0.03] p-3" data-testid="quality-notice-tips">
- {quality.tips.map((tip) => (
- <li key={tip} className="flex gap-2 text-xs leading-5 text-white/75">
- <span className="mt-[7px] size-1.5 shrink-0 rounded-full bg-[#a3e635]" aria-hidden="true" />
- <span>{tip}</span>
- </li>
- ))}
- </ul>
+ <div data-testid="quality-notice-tips">
+ <p className="text-xs font-medium text-foreground">{coaching ? "How to earn spins" : "Tips"}</p>
+ <ul className="mt-1 list-disc space-y-1 ps-4 text-xs leading-5 text-muted-foreground marker:text-muted-foreground/60">
+ {quality.tips.map((tip) => <li key={tip}>{tip}</li>)}
+ </ul>
+ </div>
+ ) : coaching ? (
+ <p className="text-xs font-medium text-foreground">How to earn spins</p>
) : null}
{coaching ? (
- <div className="mt-3">
+ <div>
<button
type="button"
onClick={toggleWhy}
aria-expanded={whyOpen}
data-testid="quality-see-why"
- className="inline-flex items-center gap-1 text-xs font-medium text-violet-200 hover:text-violet-100"
+ className="inline-flex items-center gap-1 text-xs text-muted-foreground transition hover:text-foreground"
>
See why
<ChevronDown className={cn("size-3.5 transition", whyOpen && "rotate-180")} />
@@ -189,30 +196,25 @@ export function QualityNoticeCard(props: QualityNoticeCardProps) {
</div>
) : null}
- <BiggestWinTicker quality={quality} className="mt-3 w-fit" />
+ <BiggestWinTicker quality={quality} />
- <div className="mt-4 flex items-center gap-2">
+ <div className="mt-1 flex flex-wrap items-center gap-2">
{quality.spinsAvailable > 0 ? (
- <button
+ <Button
type="button"
+ size="sm"
onClick={props.onSpin}
disabled={!spinnable}
data-testid="quality-notice-spin"
- className="inline-flex items-center gap-2 rounded-full bg-[#a3e635] px-4 py-2 text-sm font-bold text-[#1a2e05] shadow-[0_0_20px_rgba(163,230,53,0.4)] transition hover:bg-[#bef264] disabled:cursor-not-allowed disabled:opacity-60"
>
- <Gift className="size-4" aria-hidden="true" />
Spin{quality.spinsAvailable > 1 ? ` (${quality.spinsAvailable})` : ""}
- </button>
+ </Button>
) : null}
- <button
- type="button"
- onClick={props.onDismiss}
- className="rounded-full px-3 py-2 text-sm font-medium text-white/60 transition hover:bg-white/10 hover:text-white"
- >
+ <Button type="button" size="sm" variant="outline" onClick={props.onDismiss}>
Got it
- </button>
+ </Button>
{quality.spinsAvailable > 0 && !spinnable ? (
- <span className="text-xs text-amber-200">The wheel is resting, back tomorrow.</span>
+ <span className="text-xs text-muted-foreground">The wheel is resting, back tomorrow.</span>
) : null}
</div>
</div>
@@ -226,13 +228,13 @@ export function QualityNudge(props: { text: string; onDismiss: () => void }) {
<div
role="status"
data-testid="quality-nudge"
- className="fixed bottom-4 right-4 z-[64] flex max-w-[360px] items-start gap-2 rounded-2xl border border-[#a3e635]/30 bg-[#0b1120]/95 px-4 py-3 text-sm text-white shadow-xl shadow-black/40"
+ className={cn("fixed bottom-4 right-4 z-[64] flex max-w-[360px] items-start gap-3 p-4 text-sm", TOAST_SURFACE)}
>
- <Sparkles className="mt-0.5 size-4 shrink-0 text-[#a3e635]" aria-hidden="true" />
- <span className="leading-5 text-white/85">{props.text}</span>
- <button type="button" onClick={props.onDismiss} aria-label="Dismiss" className="-me-1 text-white/50 hover:text-white">
- <X className="size-4" />
- </button>
+ <Gift className="mt-0.5 size-4 shrink-0 text-muted-foreground" aria-hidden="true" />
+ <span className="flex-1 text-muted-foreground">{props.text}</span>
+ <Button type="button" variant="ghost" size="icon-xs" onClick={props.onDismiss} aria-label="Dismiss" className="-me-1 -mt-0.5 text-muted-foreground">
+ <X />
+ </Button>
</div>
);
}
diff --git a/apps/app/src/react-app/domains/quality/quality-parts.tsx b/apps/app/src/react-app/domains/quality/quality-parts.tsx
index 78aa98eb..68b4f95d 100644
--- a/apps/app/src/react-app/domains/quality/quality-parts.tsx
+++ b/apps/app/src/react-app/domains/quality/quality-parts.tsx
@@ -1,44 +1,34 @@
/** @jsxImportSource react */
-import { Flame, Gift, Trophy } from "lucide-react";
-
+import { Badge } from "@/components/ui/badge";
import { cn } from "@/lib/utils";
import { compactTokenCount } from "../../../app/lib/omnirush-usage";
-import { qualityBadgeText, qualityBadgeTitle, type AccountQuality, type QualityTier } from "../../../app/lib/quality";
-
-const TIER_STYLES: Record<QualityTier, string> = {
- new: "border-sky-400/40 bg-sky-400/10 text-sky-200",
- standard: "border-slate-300/30 bg-slate-300/10 text-slate-200",
- gold: "border-amber-300/60 bg-amber-300/15 text-amber-200",
- coaching: "border-violet-300/45 bg-violet-300/10 text-violet-200",
- limited: "border-rose-300/45 bg-rose-400/10 text-rose-200",
-};
+import { qualityBadgeText, qualityBadgeTitle, type AccountQuality } from "../../../app/lib/quality";
-/** The tier, as a small pill. Dashed and dimmed in preview (spins pay nothing). */
+/** The tier, as a small neutral badge. Dashed in preview (spins pay nothing). */
export function QualityTierBadge({ quality, className }: { quality: AccountQuality | null; className?: string }) {
// Null: quality rewards are switched off, and nothing shows.
if (!quality) return null;
return (
- <span
+ <Badge
+ variant="outline"
data-testid="quality-tier-badge"
data-tier={quality.tier}
data-preview={quality.preview ? "" : undefined}
title={qualityBadgeTitle(quality)}
className={cn(
- "inline-flex h-4 shrink-0 items-center gap-1 rounded-full border px-1.5 text-[9.5px] font-semibold uppercase leading-none tracking-[0.06em]",
- TIER_STYLES[quality.tier],
- quality.preview && "border-dashed opacity-80",
+ "h-4 px-1.5 text-[10px] font-normal text-muted-foreground",
+ quality.preview && "border-dashed",
className,
)}
>
- {quality.tier === "gold" ? <Trophy className="size-2.5" aria-hidden="true" /> : null}
{qualityBadgeText(quality)}
- </span>
+ </Badge>
);
}
-/** A ring that fills as the latest session gets closer to earning a spin. */
-export function ProgressRing({ progress, size = 18, stroke = 2.5, className }: { progress: number; size?: number; stroke?: number; className?: string }) {
+/** A thin ring that fills as the latest session gets closer to earning a spin. Takes the text colour. */
+export function ProgressRing({ progress, size = 14, stroke = 2, className }: { progress: number; size?: number; stroke?: number; className?: string }) {
const radius = (size - stroke) / 2;
const circumference = 2 * Math.PI * radius;
const value = Math.min(1, Math.max(0, progress));
@@ -52,13 +42,13 @@ export function ProgressRing({ progress, size = 18, stroke = 2.5, className }: {
data-progress={value.toFixed(2)}
aria-hidden="true"
>
- <circle cx={size / 2} cy={size / 2} r={radius} fill="none" stroke="currentColor" strokeOpacity={0.18} strokeWidth={stroke} />
+ <circle cx={size / 2} cy={size / 2} r={radius} fill="none" stroke="currentColor" strokeOpacity={0.2} strokeWidth={stroke} />
<circle
cx={size / 2}
cy={size / 2}
r={radius}
fill="none"
- stroke="#a3e635"
+ stroke="currentColor"
strokeWidth={stroke}
strokeLinecap="round"
strokeDasharray={circumference}
@@ -68,54 +58,40 @@ export function ProgressRing({ progress, size = 18, stroke = 2.5, className }: {
);
}
-/** "Spin" with a pulsing count of the spins that are ready. */
-export function SpinButton(props: {
- quality: AccountQuality;
- onClick: () => void;
- className?: string;
- label?: string;
- testId?: string;
-}) {
- const { quality } = props;
+function shortCount(value: number): string {
+ return value > 99 ? "99+" : String(value);
+}
+
+/** The sidebar row's tooltip: what is ready to spin. */
+export function spinRowTitle(quality: AccountQuality): string {
+ const ready = quality.spinsAvailable;
+ const stars = Math.min(ready, quality.clientSpinsAvailable ?? 0);
+ return ready > 0
+ ? `${ready} spin${ready === 1 ? "" : "s"} ready${stars > 0 ? `, ${stars} replay-ready ★ on the richer wheel` : ""}`
+ : "No spins yet: good sessions earn spins.";
+}
+
+/** "9 ready" and "★2" as small neutral badges, for the sidebar's Spin row. */
+export function SpinCounts({ quality }: { quality: AccountQuality }) {
const ready = quality.spinsAvailable;
const stars = Math.min(ready, quality.clientSpinsAvailable ?? 0);
+ if (ready <= 0) return null;
return (
- <button
- type="button"
- onClick={props.onClick}
- data-testid={props.testId ?? "quality-spin-button"}
- data-spins={ready}
- data-client-spins={stars}
- title={ready > 0
- ? `${ready} spin${ready === 1 ? "" : "s"} ready${stars > 0 ? `, ${stars} replay-ready ★ on the richer wheel` : ""}`
- : "No spins yet: good sessions earn spins."}
- className={cn(
- "relative inline-flex h-6 items-center gap-1.5 rounded-full px-2.5 text-[11px] font-semibold transition",
- ready > 0
- ? "bg-[#a3e635] text-[#1a2e05] shadow-[0_0_14px_rgba(163,230,53,0.45)] hover:bg-[#bef264]"
- : "border border-sidebar-border text-muted-foreground hover:text-foreground",
- props.className,
- )}
- >
- <Gift className="size-3.5" aria-hidden="true" />
- {props.label ?? "Spin"}
- {ready > 0 ? (
- <span className="relative ms-0.5 flex size-4 items-center justify-center">
- <span className="absolute inline-flex size-full animate-ping rounded-full bg-white/70 motion-reduce:hidden" />
- <span className="relative inline-flex size-4 items-center justify-center rounded-full bg-[#0b1120] text-[9.5px] font-bold text-[#a3e635]">
- {ready > 9 ? "9+" : ready}
- </span>
- </span>
- ) : null}
+ <span className="flex shrink-0 items-center gap-1" data-testid="quality-spin-counts">
+ <Badge variant="secondary" className="h-4 px-1.5 text-[10px] font-normal text-muted-foreground tabular-nums">
+ {shortCount(ready)} ready
+ </Badge>
{stars > 0 ? (
- <span
+ <Badge
+ variant="secondary"
data-testid="quality-client-spins"
- className="inline-flex h-4 items-center rounded-full bg-amber-300 px-1 text-[9.5px] font-bold text-amber-950"
+ title={`${stars} replay-ready ★`}
+ className="h-4 px-1.5 text-[10px] font-normal text-muted-foreground tabular-nums"
>
- ★{stars > 9 ? "9+" : stars}
- </span>
+ ★{shortCount(stars)}
+ </Badge>
) : null}
- </button>
+ </span>
);
}
@@ -133,25 +109,18 @@ export function StreakLine({ quality, className }: { quality: AccountQuality; cl
const text = streakText(quality);
if (!text) return null;
return (
- <div className={cn("flex items-center gap-1.5 text-xs text-orange-200", className)} data-testid="quality-streak">
- <Flame className="size-3.5 shrink-0 text-orange-400" aria-hidden="true" />
- <span>{text}</span>
- </div>
+ <p className={cn("text-xs text-muted-foreground", className)} data-testid="quality-streak">
+ {text}
+ </p>
);
}
export function BiggestWinTicker({ quality, className }: { quality: AccountQuality; className?: string }) {
if (!quality.biggestWinToday) return null;
return (
- <div
- className={cn("flex items-center gap-1.5 overflow-hidden rounded-full border border-amber-300/25 bg-amber-300/10 px-2.5 py-1 text-[11px] text-amber-100", className)}
- data-testid="quality-biggest-win"
- >
- <Trophy className="size-3 shrink-0 text-amber-300" aria-hidden="true" />
- <span className="truncate">
- Today&apos;s biggest win: <strong className="font-semibold text-amber-200">{compactTokenCount(quality.biggestWinToday.tokens)} tokens</strong>
- </span>
- </div>
+ <p className={cn("text-xs text-muted-foreground", className)} data-testid="quality-biggest-win">
+ Today&apos;s biggest win: {compactTokenCount(quality.biggestWinToday.tokens)} tokens
+ </p>
);
}
@@ -160,13 +129,11 @@ export function NextSpinHint({ quality, className }: { quality: AccountQuality;
const hint = quality.nextSpinHint;
if (!hint) return null;
return (
- <div className={cn("flex items-start gap-2 text-xs text-white/75", className)} data-testid="quality-next-spin">
- <ProgressRing progress={hint.progress} size={22} stroke={3} className="mt-0.5 text-white" />
+ <div className={cn("flex items-start gap-2 text-xs", className)} data-testid="quality-next-spin">
+ <ProgressRing progress={hint.progress} className="mt-px text-muted-foreground" />
<div className="min-w-0">
- <div className="text-[10px] font-semibold uppercase tracking-[0.14em] text-[#a3e635]">
- Next spin · {Math.round(hint.progress * 100)}%
- </div>
- <div className="leading-5">{hint.text}</div>
+ <div className="font-medium text-foreground">Next spin · {Math.round(hint.progress * 100)}%</div>
+ <div className="mt-0.5 leading-5 text-muted-foreground">{hint.text}</div>
</div>
</div>
);
diff --git a/apps/app/src/react-app/domains/quality/quality-spin-dialog.tsx b/apps/app/src/react-app/domains/quality/quality-spin-dialog.tsx
index 3e2d5b98..2d61efb0 100644
--- a/apps/app/src/react-app/domains/quality/quality-spin-dialog.tsx
+++ b/apps/app/src/react-app/domains/quality/quality-spin-dialog.tsx
@@ -1,7 +1,10 @@
/** @jsxImportSource react */
-import { useCallback, useEffect, useRef, useState } from "react";
-import { Loader2, Sparkles, Volume2, VolumeX, X } from "lucide-react";
+import { useCallback, useEffect, useState, type ComponentType, type ReactNode } from "react";
+import { Loader2, Volume2, VolumeX } from "lucide-react";
+import { Badge } from "@/components/ui/badge";
+import { Button } from "@/components/ui/button";
+import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogTitle } from "@/components/ui/dialog";
import { cn } from "@/lib/utils";
import type { OmniRushQualitySpinRecord, OmniRushQualitySpinTotals } from "@omnirush/types/desktop-ipc";
@@ -28,7 +31,7 @@ import {
type WheelSegment,
} from "../../../app/lib/quality";
import { BiggestWinTicker, QualityTierBadge, StreakLine } from "./quality-parts";
-import { QualityWheel } from "./quality-wheel";
+import { QualityWheel, WHEEL_LANDED_FILL, wheelSliceFill } from "./quality-wheel";
export function usePrefersReducedMotion(): boolean {
const [reduced, setReduced] = useState(() =>
@@ -76,28 +79,29 @@ function useCountUp(value: number, active: boolean, reducedMotion: boolean, dura
type Phase = "idle" | "requesting" | "spinning" | "result" | "error";
-/** The last spins (newest first), ★ on the replay-ready ones. */
+function recentSpinLabel(spin: OmniRushQualitySpinRecord): string {
+ if (spin.status === "spun") return spin.prizeTokens !== null ? compactTokenCount(spin.prizeTokens) : "spun";
+ return spin.status === "ready" ? "ready" : spin.status;
+}
+
+/** The last spins (newest first) as one muted line, ★ on the replay-ready ones. */
export function RecentSpins({ spins }: { spins: OmniRushQualitySpinRecord[] }) {
const shown = spins.slice(0, 10);
if (!shown.length) return null;
return (
- <div className="mt-1 w-full" data-testid="quality-recent-spins">
- <div className="mb-1 text-center text-[10px] font-semibold uppercase tracking-[0.18em] text-white/35">Recent spins</div>
- <ul className="flex flex-wrap justify-center gap-1">
- {shown.map((spin) => (
+ <div className="flex min-w-0 flex-wrap items-baseline gap-x-1.5 text-xs text-muted-foreground" data-testid="quality-recent-spins">
+ <span>Recent spins:</span>
+ <ul className="contents">
+ {shown.map((spin, index) => (
<li
key={spin.id}
data-replay-ready={spin.clientGrade ? "" : undefined}
title={spin.clientGrade ? REPLAY_READY_LABEL : spin.status}
- className={cn(
- "rounded-full border px-2 py-0.5 text-[10.5px] tabular-nums",
- spin.clientGrade ? "border-amber-300/40 bg-amber-300/10 text-amber-200" : "border-white/10 text-white/55",
- )}
+ className="tabular-nums"
>
{spin.clientGrade ? "★ " : ""}
- {spin.status === "spun"
- ? spin.prizeTokens !== null ? compactTokenCount(spin.prizeTokens) : "spun"
- : spin.status === "ready" ? "ready" : spin.status}
+ {recentSpinLabel(spin)}
+ {index < shown.length - 1 ? <span aria-hidden="true">,</span> : null}
</li>
))}
</ul>
@@ -105,6 +109,46 @@ export function RecentSpins({ spins }: { spins: OmniRushQualitySpinRecord[] }) {
);
}
+/** Each prize with its chance; the swatch is the slice's tint, the accent once landed. */
+function WheelLegend({ segments, landedIndex }: { segments: WheelSegment[]; landedIndex: number | null }) {
+ return (
+ <table className="w-full text-xs tabular-nums" data-testid="quality-wheel-legend">
+ <thead>
+ <tr className="text-muted-foreground">
+ <th className="pb-1 text-start font-normal">Prize</th>
+ <th className="pb-1 text-end font-normal">Chance</th>
+ </tr>
+ </thead>
+ <tbody>
+ {segments.map((segment, index) => {
+ const landed = index === landedIndex;
+ return (
+ <tr
+ key={index}
+ data-landed={landed ? "" : undefined}
+ className={cn("border-t border-border/60", landed ? "font-medium text-foreground" : "text-muted-foreground")}
+ >
+ <td className="py-1">
+ <span className="flex items-center gap-2">
+ <span
+ className="size-2.5 shrink-0 rounded-[3px] ring-1 ring-border ring-inset"
+ style={{ background: landed ? WHEEL_LANDED_FILL : wheelSliceFill(index, segments.length) }}
+ aria-hidden="true"
+ />
+ {compactTokenCount(segment.tokens)}
+ </span>
+ </td>
+ <td className="py-1 text-end">{segmentOdds(segments, index)}</td>
+ </tr>
+ );
+ })}
+ </tbody>
+ </table>
+ );
+}
+
+type SlotProps = { id?: string; className?: string; children?: ReactNode };
+
export type QualitySpinDialogProps = {
quality: AccountQuality;
onClose: () => void;
@@ -112,13 +156,24 @@ export type QualitySpinDialogProps = {
spin?: (input: { idempotencyKey: string }) => Promise<QualitySpinOutcome>;
};
+export type QualitySpinPanelProps = QualitySpinDialogProps & {
+ /** The dialog's title and description parts; plain elements outside a dialog (tests). */
+ Title?: ComponentType<SlotProps>;
+ Description?: ComponentType<SlotProps>;
+};
+
+const PlainTitle = (props: SlotProps) => <h2 id={props.id} className={cn("font-heading text-base leading-none font-medium", props.className)}>{props.children}</h2>;
+const PlainDescription = (props: SlotProps) => <p className={cn("text-sm text-muted-foreground", props.className)}>{props.children}</p>;
+
/**
- * The spin dialog: the wheel, the prizes with their odds, and the result.
- * The server picks the segment; the wheel animates to it, then the prize
- * counts up and the profile is read again.
+ * The spin dialog's content: the wheel, the prizes with their odds, and the
+ * result. The server picks the segment; the wheel animates to it, then the
+ * prize counts up and the profile is read again.
*/
-export function QualitySpinDialog(props: QualitySpinDialogProps) {
- const { quality, onClose } = props;
+export function QualitySpinPanel(props: QualitySpinPanelProps) {
+ const { quality } = props;
+ const Title = props.Title ?? PlainTitle;
+ const Description = props.Description ?? PlainDescription;
const reducedMotion = usePrefersReducedMotion();
const [segments, setSegments] = useState<WheelSegment[]>(DEFAULT_WHEEL_SEGMENTS);
const [expectedTokens, setExpectedTokens] = useState<number | null>(null);
@@ -133,9 +188,8 @@ export function QualitySpinDialog(props: QualitySpinDialogProps) {
const spinsLeft = result ? result.spinsAvailable : quality.spinsAvailable;
const count = useCountUp(result?.prizeTokens ?? 0, phase === "result", reducedMotion);
const prize = count.shown;
- // The final state (payout, chips, Spin again) waits for the count-up to land on the server's prize.
+ // The final state (payout, Spin again) waits for the count-up to land on the server's prize.
const settled = phase === "result" && count.done;
- const closeRef = useRef<HTMLButtonElement | null>(null);
useEffect(() => {
let active = true;
@@ -154,15 +208,6 @@ export function QualitySpinDialog(props: QualitySpinDialogProps) {
return () => { active = false; };
}, []);
- useEffect(() => {
- closeRef.current?.focus();
- const onKey = (event: KeyboardEvent) => {
- if (event.key === "Escape") onClose();
- };
- window.addEventListener("keydown", onKey);
- return () => window.removeEventListener("keydown", onKey);
- }, [onClose]);
-
const runSpin = useCallback(async () => {
if (phase === "requesting" || phase === "spinning") return;
setPhase("requesting");
@@ -210,180 +255,131 @@ export function QualitySpinDialog(props: QualitySpinDialogProps) {
// waiting). From the answer on: the wheel the server actually used.
const nextIsReplayReady = !result && quality.clientSpinsAvailable > 0 && clientSegments.length > 0;
const shownSegments = result ? segments : nextIsReplayReady ? clientSegments : segments;
- const goldHeader = result ? (result.clientGrade ? "★ replay-ready wheel" : null) : nextIsReplayReady ? "★ replay-ready wheel (next spin)" : null;
+ const replayWheel = result ? (result.clientGrade ? "Replay-ready ★ wheel" : null) : nextIsReplayReady ? "Replay-ready ★ wheel (next spin)" : null;
+ const resultLine = result
+ ? [
+ result.preview || result.capped ? spinPayoutText(result) : result.potBalance !== null ? `Pot: ${compactTokenCount(result.potBalance)} tokens` : "Added to your pot",
+ `${spinsLeft} spin${spinsLeft === 1 ? "" : "s"} left`,
+ result.alreadySpun ? "already counted" : null,
+ ].filter(Boolean).join(" · ")
+ : "";
return (
- <div className="fixed inset-0 z-[76] flex items-center justify-center bg-black/70 p-4 backdrop-blur-sm" data-testid="quality-spin-overlay">
- <section
- role="dialog"
- aria-modal="true"
- aria-labelledby="quality-spin-title"
- data-testid="quality-spin-dialog"
- data-phase={phase}
- className="relative w-full max-w-[520px] overflow-hidden rounded-[28px] border border-white/10 bg-[radial-gradient(ellipse_at_top,#1a2e05_0%,#0b1120_45%,#05070c_100%)] p-6 text-white shadow-2xl shadow-black/60"
- >
- {goldHeader ? (
- <div
- data-testid="quality-client-grade-header"
- className="-mx-6 -mt-6 mb-4 bg-gradient-to-r from-amber-500/30 via-amber-300/25 to-amber-500/30 px-6 py-2 text-center text-xs font-bold uppercase tracking-[0.24em] text-amber-200"
- >
- {goldHeader}
- </div>
- ) : null}
- <div className="flex items-start justify-between gap-3">
- <div className="min-w-0">
- <div className="flex items-center gap-2">
- <QualityTierBadge quality={quality} />
- <span className="text-[11px] text-white/50">
- {spinsLeft} spin{spinsLeft === 1 ? "" : "s"} ready
- {!result && quality.clientSpinsAvailable > 0 ? (
- <span className="ms-1 font-semibold text-amber-200" data-testid="quality-dialog-client-spins">· ★{quality.clientSpinsAvailable} replay-ready</span>
- ) : null}
- </span>
- </div>
- <h2 id="quality-spin-title" className="mt-2 text-2xl font-semibold tracking-[-0.02em]">
- Spin for tokens
- </h2>
- </div>
- <div className="flex items-center gap-1">
- <button
- type="button"
- onClick={toggleSound}
- aria-pressed={soundEnabled}
- aria-label={soundEnabled ? "Turn sound off" : "Turn sound on"}
- data-testid="quality-sound-toggle"
- className="flex size-8 items-center justify-center rounded-full text-white/60 transition hover:bg-white/10 hover:text-white"
- >
- {soundEnabled ? <Volume2 className="size-4" /> : <VolumeX className="size-4" />}
- </button>
- <button
- ref={closeRef}
- type="button"
- onClick={onClose}
- aria-label="Close"
- className="flex size-8 items-center justify-center rounded-full text-white/60 transition hover:bg-white/10 hover:text-white"
- >
- <X className="size-4" />
- </button>
- </div>
- </div>
-
- <div className="mt-3 flex flex-wrap items-center gap-2">
- <BiggestWinTicker quality={quality} />
- <StreakLine quality={quality} />
- </div>
-
- <div className="relative mt-4">
- <QualityWheel
- segments={shownSegments}
- targetIndex={result ? result.segmentIndex : null}
- spinId={spinId}
- onDone={landed}
- celebrate={celebrate}
- nearMiss={result?.nearMiss ?? false}
- soundEnabled={soundEnabled}
- reducedMotion={reducedMotion}
- jackpotTokens={result?.jackpotTokens ?? jackpotTokens}
- size={300}
- />
+ <>
+ <div className="flex flex-col gap-1.5 pe-20">
+ <div className="flex min-w-0 items-center gap-2">
+ <Title id="quality-spin-title">Spin for tokens</Title>
+ <QualityTierBadge quality={quality} />
</div>
+ <Description>
+ {spinsLeft} spin{spinsLeft === 1 ? "" : "s"} ready
+ {!result && quality.clientSpinsAvailable > 0 ? (
+ <span data-testid="quality-dialog-client-spins"> · ★{quality.clientSpinsAvailable} replay-ready</span>
+ ) : null}
+ </Description>
+ </div>
+ <Button
+ type="button"
+ variant="ghost"
+ size="icon-sm"
+ onClick={toggleSound}
+ aria-pressed={soundEnabled}
+ aria-label={soundEnabled ? "Turn sound off" : "Turn sound on"}
+ title={soundEnabled ? "Sound on" : "Sound off"}
+ data-testid="quality-sound-toggle"
+ className="absolute top-4 inset-e-14 bg-secondary text-muted-foreground"
+ >
+ {soundEnabled ? <Volume2 /> : <VolumeX />}
+ </Button>
- <div className="mt-3 flex flex-wrap justify-center gap-1.5" data-testid="quality-wheel-legend">
- {shownSegments.map((segment, index) => (
- <span
- key={index}
- className={cn(
- "rounded-full border px-2 py-0.5 text-[10.5px] tabular-nums",
- result && settled && index === result.segmentIndex
- ? "border-[#a3e635] bg-[#a3e635]/20 text-[#ecfccb]"
- : "border-white/10 text-white/55",
- )}
- >
- {compactTokenCount(segment.tokens)} · {segmentOdds(shownSegments, index)}
- </span>
- ))}
+ <div className="flex flex-col items-center gap-6 sm:flex-row sm:items-center" data-testid="quality-spin-dialog" data-phase={phase}>
+ <QualityWheel
+ segments={shownSegments}
+ targetIndex={result ? result.segmentIndex : null}
+ spinId={spinId}
+ onDone={landed}
+ celebrate={celebrate}
+ soundEnabled={soundEnabled}
+ reducedMotion={reducedMotion}
+ size={196}
+ />
+ <div className="flex w-full min-w-0 flex-1 flex-col gap-3">
+ {replayWheel ? (
+ <Badge variant="outline" className="h-5 font-normal text-muted-foreground" data-testid="quality-client-grade-header">
+ {replayWheel}
+ </Badge>
+ ) : null}
+ <WheelLegend segments={shownSegments} landedIndex={result && settled ? result.segmentIndex : null} />
+ <div className="flex flex-col gap-0.5">
+ <StreakLine quality={quality} />
+ <BiggestWinTicker quality={quality} />
+ </div>
</div>
+ </div>
- <div className="mt-4 min-h-[92px] text-center" aria-live="polite">
- {phase === "result" && result ? (
- <div data-testid="quality-spin-result" data-celebrate={celebrate}>
- <div
- className={cn(
- "font-semibold tabular-nums tracking-[-0.03em]",
- celebrate === "jackpot" ? "text-5xl text-amber-200" : celebrate === "big" ? "text-5xl text-[#d9f99d]" : "text-4xl text-white",
- )}
- data-testid="quality-spin-prize"
- >
- {prize.toLocaleString("en-US")}
- <span className="ms-2 text-base font-medium text-white/60">tokens</span>
- </div>
- {celebrate === "jackpot" ? (
- <div className="mt-1 text-sm font-semibold uppercase tracking-[0.3em] text-amber-300">Jackpot</div>
- ) : null}
- {settled ? (
- <>
- <div className={cn("mt-1 text-sm", result.preview || result.capped ? "text-amber-200" : "text-[#bef264]")} data-testid="quality-spin-payout">
- {spinPayoutText(result)}
- </div>
- <div className="mt-2 flex flex-wrap items-center justify-center gap-2 text-[11px]">
- {result.clientGrade ? (
- <span className="inline-flex items-center gap-1 rounded-full border border-amber-300/50 bg-amber-300/15 px-2 py-0.5 font-semibold text-amber-200">
- {REPLAY_READY_LABEL}
- </span>
- ) : result.reproducible ? (
- <span className="inline-flex items-center gap-1 rounded-full border border-[#a3e635]/40 bg-[#a3e635]/10 px-2 py-0.5 text-[#d9f99d]">
- <Sparkles className="size-3" aria-hidden="true" /> reproducible ✓
- </span>
- ) : null}
- {result.alreadySpun ? <span className="text-white/50">This spin was already counted.</span> : null}
- {result.potBalance !== null && !result.preview ? (
- <span className="text-white/50">Pot: {compactTokenCount(result.potBalance)} tokens</span>
- ) : null}
- </div>
- {tease ? (
- <div className="mt-2 text-sm font-semibold text-amber-300" data-testid="quality-near-miss">{tease}</div>
- ) : null}
- </>
+ <div className="flex min-h-14 flex-col justify-center gap-1" aria-live="polite">
+ {phase === "result" && result ? (
+ <div data-testid="quality-spin-result" data-celebrate={celebrate} className="flex flex-col gap-1">
+ <div className="flex flex-wrap items-center gap-2">
+ <span className="text-xl font-semibold tabular-nums" data-testid="quality-spin-prize" data-value={prize}>
+ +{compactTokenCount(prize)} tokens
+ </span>
+ {settled && celebrate === "jackpot" ? <Badge variant="secondary" className="font-normal">Jackpot</Badge> : null}
+ {settled && result.clientGrade ? (
+ <Badge variant="secondary" className="font-normal text-muted-foreground">{REPLAY_READY_LABEL}</Badge>
+ ) : settled && result.reproducible ? (
+ <Badge variant="secondary" className="font-normal text-muted-foreground">Reproducible</Badge>
) : null}
</div>
- ) : phase === "error" && error ? (
- <div className="pt-4 text-sm text-amber-200" data-testid="quality-spin-error">{error}</div>
- ) : phase === "spinning" ? (
- <div className="pt-6 text-sm text-white/60">Good luck…</div>
- ) : resting ? (
- <div className="pt-4 text-sm text-amber-200">The wheel is resting, back tomorrow.</div>
- ) : (
- <div className="pt-4 text-sm text-white/60">
+ {settled ? (
+ <p className="text-sm text-muted-foreground" data-testid="quality-spin-payout">{resultLine}</p>
+ ) : null}
+ {tease ? <p className="text-xs text-muted-foreground" data-testid="quality-near-miss">{tease}</p> : null}
+ </div>
+ ) : phase === "error" && error ? (
+ <p className="text-sm text-destructive" data-testid="quality-spin-error">{error}</p>
+ ) : phase === "spinning" || phase === "requesting" ? (
+ <p className="text-sm text-muted-foreground">Spinning…</p>
+ ) : resting ? (
+ <p className="text-sm text-muted-foreground">The wheel is resting, back tomorrow.</p>
+ ) : (
+ <>
+ <p className="text-sm text-muted-foreground">
{quality.preview ? "Preview: spins show what you would win, and pay 0 tokens." : "The wheel decides. Every prize goes into your pot."}
- {expectedTokens ? <span className="block text-white/40">Average spin: {compactTokenCount(expectedTokens)} tokens</span> : null}
- <span className="mt-1 block text-[11px] text-amber-200/70" data-testid="quality-client-grade-note">{CLIENT_GRADE_NOTE}</span>
- </div>
- )}
- </div>
+ {expectedTokens ? ` Average spin: ${compactTokenCount(expectedTokens)} tokens.` : null}
+ </p>
+ <p className="text-xs text-muted-foreground" data-testid="quality-client-grade-note">{CLIENT_GRADE_NOTE}</p>
+ </>
+ )}
+ {totals ? <RecentSpins spins={totals.recent ?? []} /> : null}
+ </div>
- <div className="mt-2 flex flex-col items-center gap-2">
- {spinsLeft > 0 || busy ? (
- <button
- type="button"
- onClick={() => void runSpin()}
- disabled={!canSpin}
- data-testid="quality-spin-go"
- className="inline-flex min-w-[200px] items-center justify-center gap-2 rounded-full bg-[#a3e635] px-6 py-3 text-sm font-bold uppercase tracking-[0.12em] text-[#1a2e05] shadow-[0_0_30px_rgba(163,230,53,0.45)] transition hover:bg-[#bef264] disabled:cursor-not-allowed disabled:opacity-60"
- >
- {busy ? <Loader2 className="size-4 animate-spin" aria-hidden="true" /> : null}
- {busy ? "Spinning" : settled ? `Spin again (${spinsLeft} left)` : spinsLeft > 1 ? `Spin (${spinsLeft} ready)` : "Spin"}
- </button>
- ) : (
- <div className="text-xs text-white/50">No spins left. Good sessions earn more.</div>
- )}
- {totals && totals.spun > 0 ? (
- <div className="text-[11px] text-white/40" data-testid="quality-spin-totals">
- {totals.spun} spin{totals.spun === 1 ? "" : "s"} so far · {compactTokenCount(totals.paidTokens)} tokens won
- </div>
- ) : null}
- {totals ? <RecentSpins spins={totals.recent ?? []} /> : null}
- </div>
- </section>
- </div>
+ <DialogFooter className="sm:items-center sm:justify-between">
+ <p className="text-xs text-muted-foreground" data-testid="quality-spin-totals">
+ {totals && totals.spun > 0
+ ? `${totals.spun} spin${totals.spun === 1 ? "" : "s"} so far · ${compactTokenCount(totals.paidTokens)} tokens won`
+ : null}
+ </p>
+ {spinsLeft > 0 || busy ? (
+ <Button type="button" onClick={() => void runSpin()} disabled={!canSpin} data-testid="quality-spin-go">
+ {busy ? <Loader2 className="animate-spin" aria-hidden="true" /> : null}
+ {busy ? "Spinning" : settled ? `Spin again (${spinsLeft} left)` : spinsLeft > 1 ? `Spin (${spinsLeft} ready)` : "Spin"}
+ </Button>
+ ) : (
+ <p className="text-sm text-muted-foreground">No spins left. Good sessions earn more.</p>
+ )}
+ </DialogFooter>
+ </>
+ );
+}
+
+/** The spin dialog: the app's standard dialog around the spin panel. */
+export function QualitySpinDialog(props: QualitySpinDialogProps) {
+ return (
+ <Dialog open onOpenChange={(open) => { if (!open) props.onClose(); }}>
+ <DialogContent className="w-full max-w-lg sm:max-w-lg lg:max-w-lg" data-testid="quality-spin-overlay">
+ <QualitySpinPanel {...props} Title={DialogTitle} Description={DialogDescription} />
+ </DialogContent>
+ </Dialog>
);
}
diff --git a/apps/app/src/react-app/domains/quality/quality-wheel.tsx b/apps/app/src/react-app/domains/quality/quality-wheel.tsx
index 9699a8cb..58de1933 100644
--- a/apps/app/src/react-app/domains/quality/quality-wheel.tsx
+++ b/apps/app/src/react-app/domains/quality/quality-wheel.tsx
@@ -1,18 +1,14 @@
/** @jsxImportSource react */
-import { useEffect, useMemo, useRef } from "react";
+import { useEffect, useMemo, useRef, useState } from "react";
import {
- jackpotIndex,
sliceAtPointer,
- wheelAngleAt,
- wheelOvershoot,
+ wheelEaseOut,
wheelSlices,
wheelTargetRotation,
type WheelSegment,
} from "../../../app/lib/quality";
-import { compactTokenCount } from "../../../app/lib/omnirush-usage";
import { createWheelSounds, type WheelSounds } from "./wheel-sounds";
-import { burstConfetti } from "./wheel-confetti";
export type QualityWheelProps = {
segments: WheelSegment[];
@@ -22,21 +18,29 @@ export type QualityWheelProps = {
spinId?: string | number;
onDone?: () => void;
celebrate?: "none" | "big" | "jackpot";
- nearMiss?: boolean;
soundEnabled?: boolean;
reducedMotion?: boolean;
/** Pixel size of the wheel (square). */
size?: number;
durationMs?: number;
- /** The top prize (GET /me/quality `jackpot_tokens`); the biggest segment otherwise. */
- jackpotTokens?: number | null;
};
-/** Low prizes in slate and teal, rising to the lime jackpot. */
-const SEGMENT_COLORS = ["#1e293b", "#334155", "#115e59", "#3f6212", "#65a30d", "#a3e635"];
-const SEGMENT_TEXT = ["#cbd5e1", "#e2e8f0", "#ccfbf1", "#ecfccb", "#f7fee7", "#1a2e05"];
const RADIUS = 100;
-const LABEL_INSIDE_MIN_DEGREES = 14;
+/** Full turns before the stop: with the ease-out this reads as one calm spin. */
+const TURNS = 4;
+
+/**
+ * Neutral tints from the theme (Radix slate, so light and dark both follow the
+ * app), rising with the prize. The legend uses the same tints as swatches.
+ */
+export function wheelSliceFill(index: number, count: number): string {
+ const steps = [4, 5, 6, 7, 8, 9];
+ const at = count <= 1 ? 0 : Math.round((index * (steps.length - 1)) / (count - 1));
+ return `var(--slate-${steps[at] ?? 4})`;
+}
+
+/** The landed slice and its legend swatch: the brand accent. */
+export const WHEEL_LANDED_FILL = "var(--lime-9)";
function point(angle: number, radius: number): [number, number] {
const radians = (angle * Math.PI) / 180;
@@ -50,17 +54,10 @@ function slicePath(start: number, end: number): string {
return `M0 0 L${x1.toFixed(3)} ${y1.toFixed(3)} A${RADIUS} ${RADIUS} 0 ${large} 1 ${x2.toFixed(3)} ${y2.toFixed(3)} Z`;
}
-function colorFor(index: number, count: number, palette: string[]): string {
- // Spread the palette over the segments so the top prize always gets the lime.
- const at = count <= 1 ? palette.length - 1 : Math.round((index * (palette.length - 1)) / (count - 1));
- return palette[at] ?? palette[0];
-}
-
/**
- * The quality-rewards wheel: slices sized by the real odds, a pointer that
- * ticks over every boundary, a spin that accelerates, decelerates for a long
- * time, overshoots a little and settles on `targetIndex`. The server chose
- * the index; this only animates to it.
+ * The quality-rewards wheel: flat slices sized by the real odds, a small
+ * pointer at the top, one ease-out spin that stops on `targetIndex`, and the
+ * landed slice in the accent. The server chose the index; this only animates to it.
*/
export function QualityWheel(props: QualityWheelProps) {
const {
@@ -71,20 +68,19 @@ export function QualityWheel(props: QualityWheelProps) {
celebrate = "none",
soundEnabled = false,
reducedMotion = false,
- size = 320,
- durationMs = 5600,
+ size = 200,
+ durationMs = 3_600,
} = props;
const slices = useMemo(() => wheelSlices(segments), [segments]);
const wheelRef = useRef<SVGGElement | null>(null);
- const pointerRef = useRef<SVGGElement | null>(null);
const rootRef = useRef<HTMLDivElement | null>(null);
- const confettiRef = useRef<HTMLCanvasElement | null>(null);
const rotation = useRef(0);
const sounds = useRef<WheelSounds | null>(null);
const soundOn = useRef(soundEnabled);
soundOn.current = soundEnabled;
const done = useRef(onDone);
done.current = onDone;
+ const [landed, setLanded] = useState<number | null>(null);
useEffect(() => () => sounds.current?.dispose(), []);
@@ -99,9 +95,7 @@ export function QualityWheel(props: QualityWheelProps) {
const finish = () => {
root?.setAttribute("data-spinning", "false");
root?.setAttribute("data-landed-index", String(targetIndex));
- if (celebrate !== "none" && !reducedMotion && confettiRef.current) {
- burstConfetti(confettiRef.current, celebrate);
- }
+ setLanded(targetIndex);
if (soundOn.current) {
sounds.current ??= createWheelSounds();
sounds.current?.win(celebrate);
@@ -111,7 +105,8 @@ export function QualityWheel(props: QualityWheelProps) {
// A small random offset inside the slice: the pointer never rests on a line.
const offset = (Math.random() - 0.5) * 0.9;
const from = rotation.current;
- const to = wheelTargetRotation(segments, targetIndex, from, 6, offset);
+ const to = wheelTargetRotation(segments, targetIndex, from, TURNS, offset);
+ setLanded(null);
root?.setAttribute("data-spinning", "true");
root?.removeAttribute("data-landed-index");
if (reducedMotion) {
@@ -119,32 +114,25 @@ export function QualityWheel(props: QualityWheelProps) {
const timer = window.setTimeout(finish, 0);
return () => window.clearTimeout(timer);
}
- const overshoot = wheelOvershoot(segments, targetIndex, offset);
let lastSlice = sliceAtPointer(slices, from);
let frame = 0;
- let kick = 0;
const started = performance.now();
const step = (now: number) => {
const progress = (now - started) / durationMs;
- const angle = wheelAngleAt(progress, from, to, overshoot);
+ const angle = wheelEaseOut(progress, from, to);
apply(angle);
const slice = sliceAtPointer(slices, angle);
if (slice !== lastSlice) {
lastSlice = slice;
- kick = 1;
if (soundOn.current) {
sounds.current ??= createWheelSounds();
sounds.current?.tick();
}
}
- // The pointer flicks back on every boundary and springs home.
- kick *= 0.82;
- pointerRef.current?.setAttribute("transform", `rotate(${(-22 * kick).toFixed(2)} 0 -112)`);
if (progress < 1) {
frame = requestAnimationFrame(step);
} else {
apply(to);
- pointerRef.current?.setAttribute("transform", "rotate(0 0 -112)");
finish();
}
};
@@ -154,80 +142,36 @@ export function QualityWheel(props: QualityWheelProps) {
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [targetIndex, spinId]);
- const jackpot = jackpotIndex(segments, props.jackpotTokens);
return (
<div
ref={rootRef}
- className="relative mx-auto"
+ className="relative shrink-0"
style={{ width: size, height: size }}
data-testid="quality-wheel"
data-spinning="false"
data-rotation="0"
>
- <svg viewBox="-130 -130 260 260" width={size} height={size} role="img" aria-label="Prize wheel">
- <defs>
- <radialGradient id="quality-wheel-hub" cx="50%" cy="40%" r="60%">
- <stop offset="0%" stopColor="#1f2937" />
- <stop offset="100%" stopColor="#030712" />
- </radialGradient>
- <filter id="quality-wheel-glow" x="-50%" y="-50%" width="200%" height="200%">
- <feGaussianBlur stdDeviation="4" result="blur" />
- <feMerge>
- <feMergeNode in="blur" />
- <feMergeNode in="SourceGraphic" />
- </feMerge>
- </filter>
- </defs>
- <circle r={RADIUS + 9} fill="#0b1120" stroke="#a3e635" strokeOpacity={0.55} strokeWidth={2} filter="url(#quality-wheel-glow)" />
- <g ref={wheelRef} transform="rotate(0)">
- {slices.map((slice) => {
- const fill = colorFor(slice.index, slices.length, SEGMENT_COLORS);
- const ink = colorFor(slice.index, slices.length, SEGMENT_TEXT);
- const wide = slice.end - slice.start >= LABEL_INSIDE_MIN_DEGREES;
- const label = compactTokenCount(slice.segment.tokens);
- const [lx, ly] = point(slice.mid, wide ? 68 : 90);
- return (
- <g key={slice.index} data-segment-index={slice.index}>
- <path d={slicePath(slice.start, slice.end)} fill={fill} stroke="#020617" strokeWidth={1.2} />
- {slice.index === jackpot ? (
- <path d={slicePath(slice.start, slice.end)} fill="#ecfccb" opacity={0.35} filter="url(#quality-wheel-glow)" />
- ) : null}
- <text
- x={lx}
- y={ly}
- fill={ink}
- fontSize={wide ? 13 : 7.5}
- fontWeight={700}
- textAnchor="middle"
- dominantBaseline="central"
- transform={`rotate(${wide ? slice.mid : slice.mid - 90} ${lx} ${ly})`}
- style={{ fontFamily: "ui-sans-serif, system-ui", letterSpacing: "0.02em" }}
- >
- {label}
- </text>
- </g>
- );
- })}
- {slices.map((slice) => {
- const [x, y] = point(slice.start, RADIUS + 4.5);
- return <circle key={`bulb-${slice.index}`} cx={x} cy={y} r={2.6} fill="#f7fee7" className="quality-wheel-bulb" />;
- })}
- </g>
- <circle r={24} fill="url(#quality-wheel-hub)" stroke="#a3e635" strokeWidth={2} />
- <text y={1} fill="#a3e635" fontSize={10} fontWeight={800} textAnchor="middle" dominantBaseline="central" style={{ letterSpacing: "0.12em" }}>
- SPIN
- </text>
- <g ref={pointerRef} transform="rotate(0 0 -112)">
- <path d="M0 -94 L-11 -122 L11 -122 Z" fill="#a3e635" stroke="#0b1120" strokeWidth={2} strokeLinejoin="round" />
- <circle cx={0} cy={-118} r={3} fill="#0b1120" />
+ <svg viewBox="-108 -108 216 216" width={size} height={size} role="img" aria-label="Prize wheel">
+ <g ref={wheelRef}>
+ {slices.map((slice) => (
+ <path
+ key={slice.index}
+ data-segment-index={slice.index}
+ d={slicePath(slice.start, slice.end)}
+ style={{
+ fill: slice.index === landed ? WHEEL_LANDED_FILL : wheelSliceFill(slice.index, slices.length),
+ transition: reducedMotion ? undefined : "fill 300ms ease-out",
+ }}
+ stroke="var(--popover)"
+ strokeWidth={1.5}
+ strokeLinejoin="round"
+ />
+ ))}
</g>
+ <circle r={RADIUS} fill="none" stroke="var(--border)" strokeWidth={1} />
+ <circle r={13} fill="var(--popover)" stroke="var(--border)" strokeWidth={1} />
+ <path d="M0 -92 L-6 -105 L6 -105 Z" fill="var(--foreground)" stroke="var(--popover)" strokeWidth={1.5} strokeLinejoin="round" />
</svg>
- <canvas
- ref={confettiRef}
- className="pointer-events-none absolute"
- style={{ inset: -size * 0.35, width: size * 1.7, height: size * 1.7 }}
- aria-hidden="true"
- />
</div>
);
}
diff --git a/apps/app/src/react-app/domains/quality/wheel-confetti.ts b/apps/app/src/react-app/domains/quality/wheel-confetti.ts
deleted file mode 100644
index 1608ca13..00000000
--- a/apps/app/src/react-app/domains/quality/wheel-confetti.ts
+++ /dev/null
@@ -1,75 +0,0 @@
-// A confetti burst on a canvas over the wheel: "big" wins get one burst,
-// the jackpot three bigger ones with gold. Never runs with reduced motion.
-
-const COLORS = ["#a3e635", "#d9f99d", "#f7fee7", "#facc15", "#22d3ee", "#ffffff"];
-const JACKPOT_COLORS = ["#facc15", "#fde047", "#a3e635", "#fef9c3", "#ffffff", "#f59e0b"];
-
-type Particle = { x: number; y: number; vx: number; vy: number; spin: number; angle: number; size: number; color: string; life: number };
-
-export function burstConfetti(canvas: HTMLCanvasElement, celebrate: "big" | "jackpot"): () => void {
- const scale = window.devicePixelRatio || 1;
- const width = canvas.clientWidth;
- const height = canvas.clientHeight;
- canvas.width = Math.round(width * scale);
- canvas.height = Math.round(height * scale);
- const context = canvas.getContext("2d");
- if (!context) return () => undefined;
- context.scale(scale, scale);
- const particles: Particle[] = [];
- const palette = celebrate === "jackpot" ? JACKPOT_COLORS : COLORS;
- const burst = (count: number, power: number) => {
- for (let index = 0; index < count; index += 1) {
- const direction = Math.random() * Math.PI * 2;
- const speed = power * (0.35 + Math.random() * 0.65);
- particles.push({
- x: width / 2,
- y: height / 2,
- vx: Math.cos(direction) * speed,
- vy: Math.sin(direction) * speed - power * 0.35,
- spin: (Math.random() - 0.5) * 0.4,
- angle: Math.random() * Math.PI,
- size: 4 + Math.random() * 5,
- color: palette[index % palette.length],
- life: 1,
- });
- }
- };
- const timers: number[] = [];
- if (celebrate === "jackpot") {
- burst(200, 11);
- timers.push(window.setTimeout(() => burst(160, 9), 350));
- timers.push(window.setTimeout(() => burst(160, 12), 800));
- } else {
- burst(130, 9);
- }
- let frame = 0;
- const started = performance.now();
- const lifetime = celebrate === "jackpot" ? 3_600 : 2_400;
- const step = (now: number) => {
- context.clearRect(0, 0, width, height);
- for (const particle of particles) {
- particle.vy += 0.22;
- particle.vx *= 0.985;
- particle.vy *= 0.985;
- particle.x += particle.vx;
- particle.y += particle.vy;
- particle.angle += particle.spin;
- particle.life = Math.max(0, particle.life - 0.008);
- context.save();
- context.globalAlpha = particle.life;
- context.translate(particle.x, particle.y);
- context.rotate(particle.angle);
- context.fillStyle = particle.color;
- context.fillRect(-particle.size / 2, -particle.size / 4, particle.size, particle.size / 2);
- context.restore();
- }
- if (now - started < lifetime) frame = requestAnimationFrame(step);
- else context.clearRect(0, 0, width, height);
- };
- frame = requestAnimationFrame(step);
- return () => {
- cancelAnimationFrame(frame);
- timers.forEach((timer) => window.clearTimeout(timer));
- context.clearRect(0, 0, width, height);
- };
-}
diff --git a/apps/app/src/react-app/domains/quality/wheel-sounds.ts b/apps/app/src/react-app/domains/quality/wheel-sounds.ts
index 22d7083b..3d1d7661 100644
--- a/apps/app/src/react-app/domains/quality/wheel-sounds.ts
+++ b/apps/app/src/react-app/domains/quality/wheel-sounds.ts
@@ -38,17 +38,14 @@ export function createWheelSounds(): WheelSounds | null {
return {
tick() {
if (context.state === "suspended") void context.resume();
- tone(1_700, context.currentTime, 0.03, 0.08, "square");
+ tone(1_200, context.currentTime, 0.025, 0.04, "sine");
},
win(celebrate) {
if (context.state === "suspended") void context.resume();
const now = context.currentTime;
- const notes = celebrate === "jackpot"
- ? [523, 659, 784, 1047, 784, 1047, 1319, 1568]
- : celebrate === "big"
- ? [523, 659, 784, 1047]
- : [659, 880];
- notes.forEach((note, index) => tone(note, now + index * 0.09, 0.22, 0.12, "triangle"));
+ // A soft two-note chime; a third note for the jackpot.
+ const notes = celebrate === "jackpot" ? [659, 880, 1047] : [659, 880];
+ notes.forEach((note, index) => tone(note, now + index * 0.12, 0.3, 0.07, "sine"));
},
dispose() {
void context.close().catch(() => undefined);
diff --git a/apps/app/src/react-app/domains/session/sidebar/app-sidebar.tsx b/apps/app/src/react-app/domains/session/sidebar/app-sidebar.tsx
index e88f7094..c90c51e4 100644
--- a/apps/app/src/react-app/domains/session/sidebar/app-sidebar.tsx
+++ b/apps/app/src/react-app/domains/session/sidebar/app-sidebar.tsx
@@ -13,6 +13,7 @@ import {
Columns2,
Copy,
FolderPlus,
+ Gift,
LayoutGrid,
MoreHorizontal,
Pencil,
@@ -41,7 +42,7 @@ import { omnirushAccountStatus, type WorkspaceInfo } from "../../../../app/lib/d
import { omnirushUsageSummary } from "../../../../app/lib/omnirush-usage";
import { isDesktopRuntime } from "../../../../app/lib/runtime-env";
import { refreshAccountStatus, setQualitySessionId, useAccountStatusStore, useQualityUiStore, type AccountQuality } from "../../../../app/lib/quality";
-import { ProgressRing, QualityTierBadge, SpinButton } from "../../quality/quality-parts";
+import { ProgressRing, QualityTierBadge, SpinCounts, spinRowTitle } from "../../quality/quality-parts";
import { OmniRushDenHelpLink } from "../../workspace/omnirush-den-help-link";
import { NotificationBell } from "../../../shell/notification-center";
import { useUiStateStore } from "../../../shell/ui-state-store";
@@ -979,34 +980,47 @@ function OmniRushWordmark({ className }: { className?: string }) {
}
/**
- * Quality rewards under the account: the spin button with the count of
- * ready spins, and the ring filling toward the next spin. Opens the quality
- * panel (tips, streak, coaching) or the spin dialog. Nothing while `quality`
- * is null.
+ * Quality rewards as a sidebar row: "Spin" with the ready count as a small
+ * badge, and a muted ring with the progress toward the next spin. Opens the
+ * spin dialog (or, without spins, the quality panel: tips, streak, coaching).
*/
-function QualityFooterStrip({ quality }: { quality: AccountQuality }) {
+function QualitySpinRow({ quality }: { quality: AccountQuality }) {
const openPanel = useQualityUiStore((store) => store.openPanel);
const openSpin = useQualityUiStore((store) => store.openSpin);
const hint = quality.nextSpinHint;
+ const ready = quality.spinsAvailable;
+ const stars = Math.min(ready, quality.clientSpinsAvailable ?? 0);
+ const progress = hint ? `${Math.round(hint.progress * 100)}%` : null;
return (
- <div
- className="flex items-center gap-1.5 px-2 pb-1 pt-0.5 group-data-[collapsible=icon]:hidden"
- data-testid="quality-footer-strip"
- >
- <SpinButton quality={quality} onClick={quality.spinsAvailable > 0 ? openSpin : openPanel} />
- <button
+ <SidebarMenuItem data-testid="quality-footer-strip">
+ <SidebarMenuButton
type="button"
- onClick={openPanel}
- className="flex min-w-0 flex-1 items-center gap-1.5 rounded-md px-1 py-0.5 text-left text-[10.5px] text-muted-foreground transition hover:bg-sidebar-accent hover:text-foreground"
- title={hint?.text ?? quality.nextTierHint ?? "Quality rewards"}
- data-testid="quality-footer-next"
+ onClick={ready > 0 ? openSpin : openPanel}
+ tooltip={spinRowTitle(quality)}
+ aria-label={ready > 0 ? `Spin, ${ready} ready` : "How to earn spins"}
+ data-testid="quality-spin-button"
+ data-spins={ready}
+ data-client-spins={stars}
+ className={cn(progress && "pe-14")}
>
- {hint ? <ProgressRing progress={hint.progress} size={16} stroke={2.25} /> : null}
- <span className="truncate">
- {hint ? `${Math.round(hint.progress * 100)}%` : quality.streakDays > 0 ? `${quality.streakDays}-day streak` : "How to earn spins"}
- </span>
- </button>
- </div>
+ <Gift className="size-4" />
+ <span className="truncate">{ready > 0 ? "Spin" : "Earn spins"}</span>
+ <SpinCounts quality={quality} />
+ </SidebarMenuButton>
+ {progress ? (
+ <button
+ type="button"
+ onClick={openPanel}
+ title={hint?.text ?? quality.nextTierHint ?? "Quality rewards"}
+ aria-label={`Next spin ${progress}`}
+ data-testid="quality-footer-next"
+ className="absolute inset-e-1 top-1.5 flex h-5 items-center gap-1 rounded-md px-1 text-[11px] text-muted-foreground tabular-nums transition hover:bg-sidebar-accent hover:text-foreground group-data-[collapsible=icon]:hidden"
+ >
+ <ProgressRing progress={hint!.progress} size={12} stroke={1.75} />
+ {progress}
+ </button>
+ ) : null}
+ </SidebarMenuItem>
);
}
@@ -1083,11 +1097,7 @@ function NativeAccountFooter({ onOpenAccountSettings }: { onOpenAccountSettings:
</span>
</SidebarMenuButton>
</SidebarMenuItem>
- {quality ? (
- <SidebarMenuItem>
- <QualityFooterStrip quality={quality} />
- </SidebarMenuItem>
- ) : null}
+ {quality ? <QualitySpinRow quality={quality} /> : null}
<SidebarMenuItem>
<SidebarMenuButton
type="button"
diff --git a/apps/app/tests/quality.test.tsx b/apps/app/tests/quality.test.tsx
index f49e377e..9a2a6012 100644
--- a/apps/app/tests/quality.test.tsx
+++ b/apps/app/tests/quality.test.tsx
@@ -18,8 +18,7 @@ import {
spinPayoutText,
spinRefusalMessage,
useAccountStatusStore,
- wheelAngleAt,
- wheelOvershoot,
+ wheelEaseOut,
wheelSlices,
wheelTargetRotation,
writePref,
@@ -27,9 +26,10 @@ import {
type QualitySpin,
type QualityTier,
} from "../src/app/lib/quality";
-import { QualityTierBadge, SpinButton, streakText } from "../src/react-app/domains/quality/quality-parts";
+import { QualityTierBadge, SpinCounts, streakText } from "../src/react-app/domains/quality/quality-parts";
import { QualityNoticeCard, QualityRewards, SessionReasons, failLabel } from "../src/react-app/domains/quality/quality-notice";
-import { QualitySpinDialog, RecentSpins } from "../src/react-app/domains/quality/quality-spin-dialog";
+import { QualitySpinPanel, RecentSpins } from "../src/react-app/domains/quality/quality-spin-dialog";
+import { WHEEL_LANDED_FILL, wheelSliceFill } from "../src/react-app/domains/quality/quality-wheel";
const quality: AccountQuality = {
tier: "gold",
@@ -141,6 +141,9 @@ describe("notice: once per id", () => {
expect(html).toContain("Spin (2)");
expect(html).toContain("4-day streak");
expect(html).toContain("Next spin · 60%");
+ // The app's toast style: theme surfaces, sentence case, no coloured bar or eyebrow.
+ expect(html).toContain("bg-popover");
+ expect(html).not.toMatch(/uppercase|tracking-\[|#a3e635|#0b1120|shadow-\[0_0/);
});
test("no Spin button without spins; a resting wheel says so", () => {
@@ -199,25 +202,23 @@ describe("wheel geometry", () => {
expect(((-target % 360) + 360) % 360).toBeCloseTo(270, 6);
});
- test("the spin starts and ends where it should, and the overshoot stays in the slice", () => {
- const to = wheelTargetRotation(DEFAULT_WHEEL_SEGMENTS, 5, 0, 6);
- const overshoot = wheelOvershoot(DEFAULT_WHEEL_SEGMENTS, 5);
- expect(wheelAngleAt(0, 0, to, overshoot)).toBe(0);
- expect(wheelAngleAt(1, 0, to, overshoot)).toBeCloseTo(to, 6);
+ test("one ease-out: starts and ends where it should, never goes back, never overshoots", () => {
+ const to = wheelTargetRotation(DEFAULT_WHEEL_SEGMENTS, 5, 0, 4);
+ expect(wheelEaseOut(0, 0, to)).toBe(0);
+ expect(wheelEaseOut(1, 0, to)).toBe(to);
+ expect(wheelEaseOut(1.5, 0, to)).toBe(to);
+ expect(sliceAtPointer(slices, wheelEaseOut(1, 0, to))).toBe(5);
let previous = 0;
- let peak = 0;
- let arrived = false;
+ let previousStep = Infinity;
for (let step = 1; step <= 1_000; step += 1) {
- const angle = wheelAngleAt(step / 1_000, 0, to, overshoot);
- if (step / 1_000 <= 0.88) expect(angle).toBeGreaterThanOrEqual(previous);
+ const angle = wheelEaseOut(step / 1_000, 0, to);
+ expect(angle).toBeGreaterThanOrEqual(previous);
+ expect(angle).toBeLessThanOrEqual(to);
+ // Decelerates the whole way: every frame moves less than the one before.
+ expect(angle - previous).toBeLessThanOrEqual(previousStep + 1e-9);
+ previousStep = angle - previous;
previous = angle;
- peak = Math.max(peak, angle);
- // Once the wheel reaches the stop it overshoots and settles without leaving the 10M slice.
- arrived ||= angle >= to;
- if (arrived) expect(sliceAtPointer(slices, angle)).toBe(5);
}
- expect(arrived).toBe(true);
- expect(peak).toBeCloseTo(to + overshoot, 3);
});
});
@@ -240,12 +241,26 @@ describe("spin results", () => {
});
test("the dialog shows the wheel, the odds and the Spin button", () => {
- const html = renderToStaticMarkup(<QualitySpinDialog quality={quality} onClose={() => undefined} />);
+ const html = renderToStaticMarkup(<QualitySpinPanel quality={quality} onClose={() => undefined} />);
expect(html).toContain("data-testid=\"quality-wheel\"");
- expect(html).toContain("10M · 1%");
- expect(html).toContain("250K · 35%");
+ // The legend: each prize with its chance, one row per segment, the slice's tint as the swatch.
+ expect(html).toContain("data-testid=\"quality-wheel-legend\"");
+ expect(html).toMatch(/10M<\/span><\/td><td[^>]*>1%<\/td>/);
+ expect(html).toMatch(/250K<\/span><\/td><td[^>]*>35%<\/td>/);
+ expect(html).toContain("Spin for tokens");
+ // The app's theme only: no hardcoded navy, lime glow, confetti or all-caps.
+ expect(html).not.toMatch(/#0b1120|#a3e635|shadow-\[0_0|uppercase|<canvas/);
expect(html).toContain("Spin (2 ready)");
- expect(html).toContain("Today&#x27;s biggest win");
+ expect(html).toContain("Today&#x27;s biggest win: 10M tokens");
+ });
+
+ test("the wheel uses theme tints, and the accent only for the landed slice", () => {
+ expect(wheelSliceFill(0, 6)).toBe("var(--slate-4)");
+ expect(wheelSliceFill(5, 6)).toBe("var(--slate-9)");
+ expect(WHEEL_LANDED_FILL).toBe("var(--lime-9)");
+ const html = renderToStaticMarkup(<QualitySpinPanel quality={quality} onClose={() => undefined} />);
+ expect(html).not.toContain(WHEEL_LANDED_FILL);
+ expect(html).not.toContain("data-landed=");
});
});
@@ -269,17 +284,19 @@ describe("revision: fail labels, jackpot, open session", () => {
);
expect(html).toContain("Started in your home folder");
expect(html).toContain("3 code files · 120 lines · no tests");
- expect(html).toContain("reproducible ✓");
- expect(html).not.toContain("replay-ready ★");
+ expect(html).toContain("Reproducible ✓");
+ expect(html).not.toContain("Replay-ready ★");
expect(html).toContain("+2 spins on a richer wheel");
});
- test("the spin button shows a ★ count only for replay-ready spins", () => {
- const plain = renderToStaticMarkup(<SpinButton quality={quality} onClick={() => undefined} />);
+ test("the sidebar row shows the ready count, and a ★ count only for replay-ready spins", () => {
+ const plain = renderToStaticMarkup(<SpinCounts quality={quality} />);
+ expect(plain).toContain("2 ready");
expect(plain).not.toContain("quality-client-spins");
- const starred = renderToStaticMarkup(<SpinButton quality={{ ...quality, clientSpinsAvailable: 1 }} onClick={() => undefined} />);
+ const starred = renderToStaticMarkup(<SpinCounts quality={{ ...quality, clientSpinsAvailable: 1 }} />);
expect(starred).toContain("data-testid=\"quality-client-spins\"");
expect(starred).toContain("★1");
+ expect(renderToStaticMarkup(<SpinCounts quality={{ ...quality, spinsAvailable: 0 }} />)).toBe("");
});
test("a replay-ready session shows the star instead of the check", () => {
@@ -294,8 +311,8 @@ describe("revision: fail labels, jackpot, open session", () => {
}}
/>,
);
- expect(html).toContain("replay-ready ★");
- expect(html).not.toContain("reproducible ✓");
+ expect(html).toContain("Replay-ready ★");
+ expect(html).not.toContain("Reproducible ✓");
});
test("the jackpot slice is the segment paying jackpot_tokens", () => {
@@ -325,9 +342,9 @@ describe("replay-ready wording, history and the count-up", () => {
const starred = { ...quality, clientSpinsAvailable: 2, tier: "coaching" as const };
const notice = { id: "c-1", kind: "tier-coaching", title: "Here is how to get spins", body: "" };
const html = [
- renderToStaticMarkup(<SpinButton quality={starred} onClick={() => undefined} />),
+ renderToStaticMarkup(<SpinCounts quality={starred} />),
renderToStaticMarkup(<QualityNoticeCard quality={starred} notice={notice} onSpin={() => undefined} onDismiss={() => undefined} />),
- renderToStaticMarkup(<QualitySpinDialog quality={starred} onClose={() => undefined} />),
+ renderToStaticMarkup(<QualitySpinPanel quality={starred} onClose={() => undefined} />),
renderToStaticMarkup(
<SessionReasons
reasons={{
@@ -345,7 +362,7 @@ describe("replay-ready wording, history and the count-up", () => {
const text = html.replace(/<[^>]*>/g, " ");
expect(text.toLowerCase()).not.toContain("client");
expect(text).toContain("old app version");
- expect(text).toContain("replay-ready ★");
+ expect(text).toContain("Replay-ready ★");
expect(text).toContain("Replay-ready sessions earn +2 spins on a richer wheel.");
});