Files
tidefront/apps/web/src/components/ProgressChip.tsx
T
db9979 6178ac979a Design „Seekarte 2.0“ mit hellem und dunklem Modus
- Zentrale Tokens (theme.css, hell/dunkel) und Abbildung aller Farbklassen per @theme inline;
  Zeichnungen, Diagramme und Kurstafel auf Tokens statt fester Hexwerte
- Modus: Systemeinstellung als Standard, Einstellungen → Spiel → Darstellung (Wie System/Hell/Dunkel),
  ohne Flackern (Inline-Skript in index.html), theme-color passend
- Dunkle Kopfleiste mit Füllstandsbalken (orange ab 85 %), Rang-Chip, Desktop mit Kopfleiste über volle Breite
- Lage (Rangzeile, Alarmkarte, Fraunces-Titel, Umrissknopf), Gebäudeblatt (Jetzt/Stufe n, Kostenbalken, feste Bauleiste)
- Schriften selbst ausgeliefert (+ Fraunces 700); Kartenfarben als lib/theme-map.ts (noch nicht verdrahtet)
- Tests: Kontrast-Test der Tokens, E2E Moduswechsel und Bildschirmfotos hell/dunkel bei 390/1440 px
2026-11-28 23:30:09 +01:00

55 lines
2.7 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// Fortschritts-Chip der Desktop-Kopfleiste (UX-0.43 E-1: am Desktop zusätzlich in der Kopfleiste):
// „Platz 3 von 8 · 420 bis Platz 2 · Tag 5/42“ aus der vorhandenen Ranglisten-Abfrage (social.ranking, gleicher Cache
// wie die Rangliste). Antippen öffnet die Saison (Meldungen → Saison bzw. Rangliste).
import { useQuery } from "@tanstack/react-query";
import { trpc } from "../lib/trpc.ts";
import { fmtNum } from "../lib/names.ts";
import { useNow } from "../lib/time.ts";
const DAY = 86400000;
export interface ProgressParts { rank: number; of: number; gap: number | null; day: number | null; days: number | null }
/** Platz, Abstand zum nächsten Platz und Saisontag aus der Rangliste; null ohne eigene Zeile. */
export function progressParts(
d: { rows: { rank: number; total: number; own: boolean }[]; season: { startsAtMs: number; endsAtMs: number } | null },
now: number,
): ProgressParts | null {
const own = d.rows.find((r) => r.own);
if (!own) return null;
const ahead = d.rows.filter((r) => r.rank < own.rank).sort((a, b) => b.rank - a.rank)[0];
const s = d.season;
return {
rank: own.rank,
of: d.rows.length,
gap: ahead ? Math.max(0, Math.ceil(ahead.total - own.total)) : null,
day: s ? Math.min(Math.max(1, Math.floor((now - s.startsAtMs) / DAY) + 1), Math.round((s.endsAtMs - s.startsAtMs) / DAY)) : null,
days: s ? Math.round((s.endsAtMs - s.startsAtMs) / DAY) : null,
};
}
export function progressText(p: ProgressParts): string {
const parts = [`Platz ${p.rank} von ${p.of}`];
if (p.gap !== null && p.rank > 1) parts.push(`${fmtNum(p.gap)} bis Platz ${p.rank - 1}`);
if (p.day !== null && p.days !== null) parts.push(`Tag ${p.day}/${p.days}`);
return parts.join(" · ");
}
export function ProgressChip({ onOpen }: { onOpen: () => void }) {
const q = useQuery({ ...trpc.social.ranking.queryOptions(), refetchInterval: 60000, staleTime: 30000 });
const now = useNow(60000);
const p = q.data ? progressParts(q.data, now) : null;
if (!p) return null;
const text = progressText(p);
return (
<button type="button" onClick={onOpen} data-testid="progress-chip" title="Saison öffnen"
aria-label={`${text} – Saison öffnen`}
className="tap shrink-0 self-center rounded-2xl border border-ink2 px-3 h-10 text-[13px] whitespace-nowrap flex items-center gap-1.5">
{/* Seekarte 2.0: Rang-Chip – Platz in Fraunces, Rest leise. */}
<span className="font-serif font-bold text-[14px]">Platz {p.rank} von {p.of}</span>
<span className="text-ink2 hidden xl:inline">{text.split(" · ").slice(1).map((t) => `· ${t}`).join(" ")}</span>
<span className="text-ink2 xl:hidden">{p.day !== null ? `· Tag ${p.day}/${p.days}` : ""}</span>
</button>
);
}