feat(frontend): add shared client libraries and UI primitives

Introduce API helpers, types, hooks, design-system components, and the authenticated app shell.
This commit is contained in:
ahp
2026-10-07 19:40:26 +03:30
parent 0751ee5588
commit 680db7dce0
39 changed files with 2806 additions and 0 deletions
+32
View File
@@ -0,0 +1,32 @@
"use client";
import type { Role, User } from "./types";
/** Hard cap for students — no timed refill. */
export const MAX_HEARTS = 3;
/** Infinity glyph for staff heart display. */
export const INFINITE_HEARTS_LABEL = "∞";
export function hasInfiniteHearts(role: Role | string | null | undefined): boolean {
return role === "admin" || role === "mentor";
}
export function clampHearts(hearts: number | null | undefined): number {
if (hearts == null || Number.isNaN(hearts)) {
return MAX_HEARTS;
}
return Math.max(0, Math.min(MAX_HEARTS, hearts));
}
/** Effective hearts from the server user — never invents a timed refill. */
export function heartsOf(user: User | null | undefined): number {
return clampHearts(user?.hearts);
}
export function formatHeartsDisplay(user: User | null | undefined): string {
if (hasInfiniteHearts(user?.role)) {
return INFINITE_HEARTS_LABEL;
}
return String(clampHearts(user?.hearts));
}