Self-hosted fitness tracker. Log workouts, track nutrition, and monitor progress. Docker deployment, mobile-friendly.
The error state itself: one mark, one component, both apps (#157)
Carter3c48a92c6bbe
diff --git a/.gitignore b/.gitignoreindex 7ed2226..be9055b 100644--- a/.gitignore+++ b/.gitignore@@ -91,3 +91,6 @@ web/playwright-report/# The rule exists because the convention alone did not hold: without it the same mistake# landed twice, and the second time it reached main.mobile/.maestro/++# tsc --incremental caches. Regenerated on every build; never useful in a diff.+*.tsbuildinfodiff --git a/mobile/src/components/Logo.tsx b/mobile/src/components/Logo.tsxindex 1bf458f..313c8a9 100644--- a/mobile/src/components/Logo.tsx+++ b/mobile/src/components/Logo.tsx@@ -1,34 +1,65 @@import Svg, { Path, Rect } from 'react-native-svg'+import { BARBELL, type BarbellInk, type BarbellMarkData } from '@lyftr/shared'-// The web app's "bent barbell" mark (bar bowing under load, plates each end).-// Ported from web/public/favicon + BarbellSVG. Colors are parameterized so it reads-// on gradient (all white), on a glass chip (cyan plates), or as a watermark.+// Renders a barbell mark from shared geometry. The coordinates used to live here AND in+// web/src/components/BarbellSVG.tsx — the same path string and the same eight rects,+// typed out twice — so they now come from packages/shared/src/brand/barbell.ts and this+// file is only the react-native-svg half of the drawing.+//+// The colour props are kept as they were: AuthScaffold renders this all-white on the+// gradient and cyan-on-glass in the same screen, so the palette has to stay per-call.export function BarbellMark({size = 34,+ mark = BARBELL,bar = '#ffffff',plate = '#00b8d9',plateEdge = '#0891b2',highlight = true,}: {size?: number+ mark?: BarbellMarkDatabar?: stringplate?: stringplateEdge?: stringhighlight?: boolean}) {+ const ink: Record<BarbellInk, string> = { bar, plate, plateEdge, highlight: '#7eeeff', collar: '#475569' }+ const spin = (r?: readonly [number, number, number]) =>+ r ? { transform: `rotate(${r[0]} ${r[1]} ${r[2]})` } : {}+return (- <Svg width={size} height={size} viewBox="0 0 40 40">- <Path d="M4 16 Q20 25 36 16" fill="none" stroke={bar} strokeWidth={2.6} strokeLinecap="round" />- <Rect x={3} y={10} width={3} height={18} rx={0.8} fill={plateEdge} />- <Rect x={6} y={8} width={4} height={22} rx={1} fill={plate} />- <Rect x={34} y={10} width={3} height={18} rx={0.8} fill={plateEdge} />- <Rect x={30} y={8} width={4} height={22} rx={1} fill={plate} />- {highlight ? (- <>- <Rect x={7.2} y={10.5} width={1.2} height={17} rx={0.5} fill="#7eeeff" opacity={0.55} />- <Rect x={31.6} y={10.5} width={1.2} height={17} rx={0.5} fill="#7eeeff" opacity={0.55} />- </>- ) : null}+ <Svg width={size} height={size} viewBox={mark.viewBox}>+ {mark.shapes.map((s, i) => {+ if (s.kind === 'stroke') {+ return (+ <Path+ key={i}+ d={s.d}+ fill="none"+ stroke={ink[s.ink]}+ strokeWidth={s.width}+ strokeLinecap={s.cap ?? 'round'}+ {...spin(s.rotate)}+ />+ )+ }+ // `highlight={false}` drops the specular strips — wanted for the flat all-white+ // watermark, where they would read as a seam rather than as a shine.+ if (s.ink === 'highlight' && !highlight) return null+ return (+ <Rect+ key={i}+ x={s.x}+ y={s.y}+ width={s.w}+ height={s.h}+ rx={s.rx}+ fill={ink[s.ink]}+ opacity={s.opacity}+ {...spin(s.rotate)}+ />+ )+ })}</Svg>)}diff --git a/mobile/src/components/ui/BarbellBroken.tsx b/mobile/src/components/ui/BarbellBroken.tsxnew file mode 100644index 0000000..e222feb--- /dev/null+++ b/mobile/src/components/ui/BarbellBroken.tsx@@ -0,0 +1,20 @@+import { BARBELL_DROPPED } from '@lyftr/shared'+import { BarbellMark } from '../Logo'++// The mark for "we could not load this": the barbell after the lift is over — bar tilted+// and straight (nothing is loading it), one end down to its last plate, and the plate that+// slid off lying below. Geometry is shared with the logo in packages/shared, and the+// renderer is the same BarbellMark the logo uses; only the palette differs, muted so this+// reads as a state rather than as branding on a failed screen.+export function BarbellBroken({ size = 44, color = '#94a3b8' }: { size?: number; color?: string }) {+ return (+ <BarbellMark+ size={size}+ mark={BARBELL_DROPPED}+ bar={color}+ plate={color}+ plateEdge={color}+ highlight={false}+ />+ )+}diff --git a/mobile/src/components/ui/ErrorState.test.tsx b/mobile/src/components/ui/ErrorState.test.tsxnew file mode 100644index 0000000..c8ba128--- /dev/null+++ b/mobile/src/components/ui/ErrorState.test.tsx@@ -0,0 +1,63 @@+import { fireEvent, render, screen } from '@testing-library/react-native'+import mockAsyncStorage from '@react-native-async-storage/async-storage/jest/async-storage-mock'+import { Button } from './Button'+import { ErrorState } from './ErrorState'++// Same preamble as the other component tests: expo-router can't load under bare jest, and+// the ui barrel reaches it via useTheme → lib/lyftr.+jest.mock('expo-router', () => ({+ router: { push: jest.fn(), navigate: jest.fn(), replace: jest.fn() },+}))+jest.mock('@react-native-async-storage/async-storage', () => mockAsyncStorage)+jest.mock('react-native-safe-area-context', () => ({+ useSafeAreaInsets: () => ({ top: 0, bottom: 0, left: 0, right: 0 }),+}))++// Mobile gets no e2e — it is not in the Playwright suite and never will be — so these+// component tests are the only gate standing under the mobile half of this feature.+//+// They mirror web's ErrorState.test.tsx case for case on purpose: the two platforms are+// supposed to read as one screen, and a test that only exists on one side is how they+// quietly stop matching.+describe('ErrorState', () => {+ it('names what failed and why', () => {+ render(<ErrorState title="Couldn't load your dashboard" message="The server didn't respond in time." />)+ expect(screen.getByText("Couldn't load your dashboard")).toBeTruthy()+ expect(screen.getByText("The server didn't respond in time.")).toBeTruthy()+ })++ // Asserted on the root props rather than via getByRole: the role is not queryable+ // because the container is deliberately NOT `accessible` — making it so would collapse+ // the title, message and retry into a single unreachable announcement. On Android the+ // live region is what actually announces this, and it is the part that would regress+ // silently if someone deleted it.+ it('announces itself without swallowing the controls inside it', () => {+ const tree: any = render(<ErrorState title="Couldn't load" message="No answer." onRetry={() => {}} />).toJSON()+ expect(tree.props.accessibilityRole).toBe('alert')+ expect(tree.props.accessibilityLiveRegion).toBe('polite')+ expect(tree.props.accessible).toBeUndefined()+ // and the retry is still reachable as its own node+ expect(screen.getByText('Try again')).toBeTruthy()+ })++ it('offers a retry that actually calls back', () => {+ const onRetry = jest.fn()+ render(<ErrorState title="Couldn't load" message="No answer." onRetry={onRetry} />)+ fireEvent.press(screen.getByText('Try again'))+ expect(onRetry).toHaveBeenCalledTimes(1)+ })++ it('shows no retry when there is nothing to retry', () => {+ render(<ErrorState title="Couldn't load" message="No answer." />)+ expect(screen.queryByText('Try again')).toBeNull()+ })++ it('takes one escape hatch alongside the retry', () => {+ render(+ <ErrorState title="Couldn't load" message="No answer." onRetry={() => {}}+ secondary={<Button title="Back to workouts" variant="secondary" onPress={() => {}} />} />,+ )+ expect(screen.getByText('Try again')).toBeTruthy()+ expect(screen.getByText('Back to workouts')).toBeTruthy()+ })+})diff --git a/mobile/src/components/ui/ErrorState.tsx b/mobile/src/components/ui/ErrorState.tsxnew file mode 100644index 0000000..8ea3799--- /dev/null+++ b/mobile/src/components/ui/ErrorState.tsx@@ -0,0 +1,74 @@+import type { ReactNode } from 'react'+import { View } from 'react-native'+import { semanticInk } from '../../theme/theme'+import { useTheme } from '../../theme/useTheme'+import { AppText } from './Typography'+import { Button } from './Button'+import { BarbellBroken } from './BarbellBroken'++// A load that failed, said as a state rather than as an alert over the wreckage.+// Mirrors web ui/ErrorState beat for beat — same mark, same anatomy, same sizes — so the+// two platforms do not merely behave alike, they read as one screen.+//+// Empty and error are different outcomes: empty means we heard back and there is nothing,+// error means we did not hear back at all. Drawing the screen's components anyway — a KPI+// tile reading 0, a ring at 0 kcal — states the first while the second is true.+//+// `size` follows the rule the design systems converge on: page when the whole screen is+// unusable, section when one region inside a working screen failed. A failed list keeps+// its search field and its create button, so that is a section.+interface Props {+ /** What we were trying to load, in the app's words: "Couldn't load your dashboard". */+ title: string+ /** The cause, from apiErrorMessage — already specific, so the mark stays constant. */+ message: string+ size?: 'page' | 'section'+ onRetry?: () => void+ retryLabel?: string+ /** One escape hatch at most, for when retrying is not the answer. */+ secondary?: ReactNode+}++export function ErrorState({+ title,+ message,+ size = 'section',+ onRetry,+ retryLabel = 'Try again',+ secondary,+}: Props) {+ const { isDark } = useTheme()+ // Status colour, not the muted grey of an empty state — and via semanticInk because+ // the raw 400s fail AA on this app's light surface (see alertContrast.test.ts).+ const ink = semanticInk[isDark ? 'dark' : 'light'].error+ const page = size === 'page'++ return (+ <View+ accessibilityRole="alert"+ // The role alone is inert on React Native: a View is only exposed as an+ // accessibility node when it is `accessible`, and setting that here would collapse+ // the title, the message and the retry into one unreachable announcement. Android's+ // actual mechanism for "something just went wrong" is a live region, which+ // announces the new content without stealing focus and leaves the button tappable.+ accessibilityLiveRegion="polite"+ className={`items-center justify-center px-6 ${page ? 'flex-1 py-16 gap-3' : 'py-10 gap-2.5'}`}+ >+ <BarbellBroken size={page ? 64 : 44} color={ink} />+ <View className="gap-1">+ <AppText variant={page ? 'title' : 'bodySemibold'} className="text-center">+ {title}+ </AppText>+ <AppText variant="body" color="muted" className="text-center">+ {message}+ </AppText>+ </View>+ {onRetry || secondary ? (+ <View className="mt-1 flex-row flex-wrap items-center justify-center gap-2">+ {onRetry ? <Button title={retryLabel} onPress={onRetry} /> : null}+ {secondary}+ </View>+ ) : null}+ </View>+ )+}diff --git a/mobile/src/theme/theme.ts b/mobile/src/theme/theme.tsindex f377228..fbbc421 100644--- a/mobile/src/theme/theme.ts+++ b/mobile/src/theme/theme.ts@@ -1,4 +1,4 @@-import { accents, palette, surfaces, type SurfaceTokens } from '@lyftr/shared'+import { accents, semanticInk, palette, surfaces, type SurfaceTokens } from '@lyftr/shared'// Light + dark palettes and brand tokens, imported from @lyftr/shared so the two apps// cannot drift. Web consumes the same values as CSS custom properties (emitted by the@@ -27,3 +27,6 @@ export const brand = {// screen's other warningColor usages routing through brand/useTheme().warningText: accents.warningText,}++// Re-exported so components import their theme from one place.+export { semanticInk }diff --git a/packages/shared/src/brand/barbell.ts b/packages/shared/src/brand/barbell.tsnew file mode 100644index 0000000..2309784--- /dev/null+++ b/packages/shared/src/brand/barbell.ts@@ -0,0 +1,105 @@+// The barbell marks, as geometry rather than as markup.+//+// The bent barbell existed twice before this — web/src/components/BarbellSVG.tsx and the+// BarbellMark inside mobile/src/components/Logo.tsx — with the same path string and the+// same eight rects typed out independently. Adding a second mark would have made four+// copies of numbers that must agree, which is the shape of every drift bug this repo has+// already paid for once (three copies of the numeric strip, two of dateUtils).+//+// React DOM and react-native-svg cannot share a component, but they can share this: the+// coordinates and which palette slot each shape uses. Each platform keeps a ~20-line+// renderer that maps a slot to a colour; nothing else about the drawing lives there.++/** Palette slots. A renderer decides what each one actually is, so the same mark can be+ * all-white on a gradient, cyan on a chip, or muted as an error state. */+export type BarbellInk = 'bar' | 'plate' | 'plateEdge' | 'highlight' | 'collar'++export interface BarbellStroke {+ kind: 'stroke'+ d: string+ ink: BarbellInk+ width: number+ /** 'round' for a loaded bar's ends; 'butt' where the drawing wants a cut edge. */+ cap?: 'round' | 'butt'+ /** [degrees, cx, cy] — applied to this shape alone, so no renderer needs groups. */+ rotate?: readonly [number, number, number]+}++export interface BarbellFill {+ kind: 'fill'+ x: number+ y: number+ w: number+ h: number+ rx: number+ ink: BarbellInk+ opacity?: number+ /** [degrees, cx, cy] — applied to this shape alone, so no renderer needs groups. */+ rotate?: readonly [number, number, number]+}++export type BarbellShape = BarbellStroke | BarbellFill++export interface BarbellMarkData {+ viewBox: string+ shapes: readonly BarbellShape[]+}++/** One end's plate stack. `dy` shifts it onto whichever bar line the mark uses. */+const plates = (+ x: number,+ edgeX: number,+ dy = 0,+ rotate?: readonly [number, number, number],+): BarbellFill[] => [+ { kind: 'fill', x: edgeX, y: 10 + dy, w: 3, h: 18, rx: 0.8, ink: 'plateEdge', rotate },+ { kind: 'fill', x, y: 8 + dy, w: 4, h: 22, rx: 1, ink: 'plate', rotate },+ { kind: 'fill', x: x + 1.2, y: 10.5 + dy, w: 1.2, h: 17, rx: 0.5, ink: 'highlight', opacity: 0.55, rotate },+]++/** The brand mark: a bar bowing under load, plates both ends. */+export const BARBELL: BarbellMarkData = {+ viewBox: '0 0 40 40',+ shapes: [+ { kind: 'stroke', d: 'M4 16 Q20 25 36 16', ink: 'bar', width: 2.6, cap: 'round' },+ // The collar dots, drawn as circles in the original web markup. A rect whose rx is+ // half its side IS a circle in both SVG and react-native-svg, so they ride the fill+ // primitive both renderers already have rather than earning a third shape kind.+ // They were dropped when this geometry was lifted from mobile's copy, which never+ // had them — a silent change to the web logo, restored here.+ { kind: 'fill', x: 9.2, y: 17.8, w: 2, h: 2, rx: 1, ink: 'collar' },+ { kind: 'fill', x: 28.8, y: 17.8, w: 2, h: 2, rx: 1, ink: 'collar' },+ ...plates(6, 3),+ ...plates(30, 34),+ ],+}++// The failure mark: the same barbell after the lift is over.+//+// Deliberately NOT the logo with a crack in it. A logo-with-a-break reads as a damaged+// logo — the eye recognises the brand first and the fault second, and at 44px the break+// is a few pixels of nothing. This is a different composition that happens to be made of+// the same parts: the bar is TILTED rather than level, it is STRAIGHT rather than bowed+// (nothing is loading it any more — the one detail that says the lift failed rather than+// succeeded), one sleeve is BARE, and the plate that came off lies below it.+//+// So it shares the brand's vocabulary — same bar weight, same plate proportions, same+// palette — without being the brand's silhouette.+const TILT = [-16, 20, 20] as const+const FALLEN = [-6, 30, 32] as const++export const BARBELL_DROPPED: BarbellMarkData = {+ viewBox: '0 0 40 40',+ shapes: [+ // Straight, not bowed: nothing is loading it any more. That one difference is what+ // separates "the lift failed" from the logo, which bows *because* it succeeded.+ { kind: 'stroke', d: 'M7 21 L33 21', ink: 'bar', width: 2.6, cap: 'round', rotate: TILT },+ // Plates stay on both ends so the silhouette still reads "barbell" at 44px — an+ // earlier version left one sleeve bare and the whole mark read as a hammer.+ ...plates(8, 5, 2, TILT),+ // The high end is down to its last plate; the one that slid off lies below.+ { kind: 'fill', x: 30, y: 12, w: 3, h: 18, rx: 0.8, ink: 'plateEdge', rotate: TILT },+ { kind: 'fill', x: 26.5, y: 31, w: 10, h: 3.4, rx: 1.7, ink: 'plate', rotate: FALLEN },+ { kind: 'fill', x: 28, y: 31.8, w: 7, h: 1.2, rx: 0.6, ink: 'highlight', opacity: 0.5, rotate: FALLEN },+ ],+}diff --git a/packages/shared/src/index.ts b/packages/shared/src/index.tsindex 71f6b6f..afa7a56 100644--- a/packages/shared/src/index.ts+++ b/packages/shared/src/index.ts@@ -30,6 +30,7 @@ export * from './hooks/useRestTimer'export * from './hooks/useServerList'export * from './hooks/useServerInfo'export * from './utils/dateUtils'+export * from './brand/barbell'export * from './utils/programUtils'export * from './stores/auth'export * from './stores/server'diff --git a/packages/shared/src/theme/alertContrast.test.ts b/packages/shared/src/theme/alertContrast.test.tsnew file mode 100644index 0000000..4913c95--- /dev/null+++ b/packages/shared/src/theme/alertContrast.test.ts@@ -0,0 +1,105 @@+import { semanticInk, palette, surfaces, type SemanticTone } from './tokens'++// THE STANDARD, enforced rather than written down: text on a tinted feedback surface must+// clear WCAG AA (4.5:1) against that tint, in both themes, on both apps.+//+// This exists because the rule was broken everywhere and nobody could see it. The 400+// shades came over from web's .alert-* classes, where they sit on a dark surface and read+// fine; mobile is light-first and web has a light theme, and on a white card the same+// pairing measures 2.4:1 for error and 1.4:1 for warning. Every alert in both apps, in a+// theme a user can actually be in, and it survived review because contrast is not+// something you notice by looking — you notice it by measuring.+//+// So this measures. Add a variant, change a shade, restyle an alert: if the pairing stops+// being legible, this fails before anyone ships it.++const AA_NORMAL_TEXT = 4.5+// The two tint strengths the alert idiom uses: the surface fill, and the slightly+// stronger fill used for a button sitting inside one (the duplicate-log confirm).+const TINTS = [0.1, 0.2]++const channel = (c: number): number => {+ const v = c / 255+ return v <= 0.03928 ? v / 12.92 : ((v + 0.055) / 1.055) ** 2.4+}++const rgb = (hex: string): [number, number, number] => {+ const h = hex.replace('#', '')+ return [0, 2, 4].map((i) => parseInt(h.slice(i, i + 2), 16)) as [number, number, number]+}++const luminance = (hex: string): number => {+ const [r, g, b] = rgb(hex)+ return 0.2126 * channel(r) + 0.7152 * channel(g) + 0.0722 * channel(b)+}++const contrast = (a: string, b: string): number => {+ const [hi, lo] = [luminance(a), luminance(b)].sort((x, y) => y - x)+ return (hi + 0.05) / (lo + 0.05)+}++// What a translucent tint actually looks like once the card behind it is composited in.+// Contrast is a property of rendered pixels, not of the colour you typed.+const flatten = (tint: string, alpha: number, behind: string): string => {+ const [tr, tg, tb] = rgb(tint)+ const [br, bg, bb] = rgb(behind)+ const mix = (t: number, b: number) => Math.round(t * alpha + b * (1 - alpha))+ return `#${[mix(tr, br), mix(tg, bg), mix(tb, bb)]+ .map((c) => c.toString(16).padStart(2, '0'))+ .join('')}`+}++// The hue each variant tints its surface with.+const TINT_HUE: Record<SemanticTone, string> = {+ error: palette.error[500],+ warning: palette.warning[500],+ success: palette.success[500],+ info: palette.brand[500],+}++const VARIANTS = Object.keys(TINT_HUE) as SemanticTone[]+const MODES = ['light', 'dark'] as const++describe('feedback surfaces are legible in both themes', () => {+ for (const mode of MODES) {+ for (const variant of VARIANTS) {+ for (const alpha of TINTS) {+ it(`${mode}: ${variant} text on a ${alpha * 100}% tint`, () => {+ // Alerts sit on a card, which is the raised surface, not the page background.+ const behind = surfaces[mode].raised+ const background = flatten(TINT_HUE[variant], alpha, behind)+ const ratio = contrast(semanticInk[mode][variant], background)++ expect({ mode, variant, alpha, ratio: Number(ratio.toFixed(2)) }).toMatchObject({+ ratio: expect.any(Number),+ })+ expect(ratio).toBeGreaterThanOrEqual(AA_NORMAL_TEXT)+ })+ }+ }+ }++ // Not only on tints. A field's validation error and a destructive row label sit on the+ // plain card, and the 400s failed there too — 2.8:1 for error, 1.5:1 for warning on+ // white. That is the most common error a user ever reads, so it is the one that must+ // hold up.+ for (const mode of MODES) {+ for (const surface of ['base', 'raised'] as const) {+ for (const variant of VARIANTS) {+ it(`${mode}: ${variant} text on the plain ${surface} surface`, () => {+ const ratio = contrast(semanticInk[mode][variant], surfaces[mode][surface])+ expect(ratio).toBeGreaterThanOrEqual(AA_NORMAL_TEXT)+ })+ }+ }+ }++ // The pairing has to be a pair. If someone "simplifies" this to one shade for both+ // themes, one of them drops below AA — that is the whole reason the map is shaped this+ // way, and it is worth failing loudly rather than rediscovering it.+ it('cannot be collapsed to a single shade per variant', () => {+ for (const variant of VARIANTS) {+ expect(semanticInk.light[variant]).not.toBe(semanticInk.dark[variant])+ }+ })+})diff --git a/packages/shared/src/theme/tokens.ts b/packages/shared/src/theme/tokens.tsindex cbce8fa..7010f27 100644--- a/packages/shared/src/theme/tokens.ts+++ b/packages/shared/src/theme/tokens.ts@@ -55,21 +55,52 @@ export const palette = {DEFAULT: '#00b8d9',},violet: { 400: '#a78bfa', 500: '#8b5cf6', 600: '#7c3aed', DEFAULT: '#8b5cf6' },- success: { 400: '#4ade80', 500: '#22c55e', DEFAULT: '#22c55e' },- warning: { 400: '#facc15', 500: '#eab308', DEFAULT: '#eab308' },- error: { 400: '#f87171', 500: '#ef4444', 600: '#dc2626', 700: '#b91c1c', DEFAULT: '#ef4444' },+ success: { 400: '#4ade80', 500: '#22c55e', 800: '#166534', DEFAULT: '#22c55e' },+ warning: { 400: '#facc15', 500: '#eab308', 800: '#854d0e', DEFAULT: '#eab308' },+ error: { 400: '#f87171', 500: '#ef4444', 600: '#dc2626', 700: '#b91c1c', 800: '#991b1b', DEFAULT: '#ef4444' },} as constexport const accents = {// Darker cyan for accents sitting on light surfaces (the web login link colour).// Tailwind's cyan-600 — outside the brand ramp, which is tuned for dark surfaces.cyanEdge: '#0891b2',+ // For text on a brand-tinted alert in light mode: cyanEdge measures 3.4:1 there,+ // below AA. This rung clears it on both the /10 and /20 tints.+ cyanEdgeDeep: '#155e75',// Near-black text on a solid warning-500 fill (e.g. "Apply all"), where both white// and the normal text colour fail contrast.warningText: '#1a1400',gradient: [palette.brand[500], palette.violet[500]] as const,} as const+// THE RULE: text on a tinted feedback surface must clear WCAG AA (4.5:1) against that+// tint, in BOTH themes. alertContrast.test.ts fails the build if any pair below does not.+//+// The 400s were used for this originally, copied from web's .alert-* classes where they+// sit on a dark surface and read fine. Mobile is light-first and web has a light theme,+// and on a white card the same pairing measures 2.4:1 for error and 1.4:1 for warning.+// Every alert in both apps was below AA in a theme a user can actually be in.+//+// No single rung clears both themes - that is why this is a pair rather than a constant.+// The light values are the lightest rungs that pass on both the /10 and /20 tints.+// Same shape as `accent`: darker on light, lighter on dark.+export const semanticInk = {+ light: {+ error: palette.error[700],+ warning: palette.warning[800],+ success: palette.success[800],+ info: accents.cyanEdgeDeep,+ },+ dark: {+ error: palette.error[400],+ warning: palette.warning[400],+ success: palette.success[400],+ info: palette.brand[300],+ },+} as const++export type SemanticTone = keyof typeof semanticInk['light']+export const GRADIENT_CSS = `linear-gradient(135deg, ${palette.brand[500]} 0%, ${palette.violet[500]} 100%)`// Surface tokens as the CSS custom properties web consumes. The var names are part of@@ -87,6 +118,10 @@ export function cssVars(mode: 'light' | 'dark'): Record<string, string> {'--tx-secondary': s.txSecondary,'--tx-muted': s.txMuted,'--tx-inverse': s.txInverse,+ '--alert-error': semanticInk[mode].error,+ '--alert-warning': semanticInk[mode].warning,+ '--alert-success': semanticInk[mode].success,+ '--alert-info': semanticInk[mode].info,'color-scheme': mode,}}diff --git a/web/src/components/BarbellBrokenSVG.tsx b/web/src/components/BarbellBrokenSVG.tsxnew file mode 100644index 0000000..daeed34--- /dev/null+++ b/web/src/components/BarbellBrokenSVG.tsx@@ -0,0 +1,20 @@+import { BARBELL_DROPPED } from '@lyftr/shared'+import { BarbellMark } from './BarbellSVG'++// The mark for "we could not load this": the barbell after the lift is over — bar tilted+// and straight (nothing is loading it), one sleeve bare, the plate that came off lying+// beneath it. Geometry is shared with the logo in packages/shared; only the palette+// differs here, muted so this reads as a state rather than as branding on a failed screen.+export default function BarbellBrokenSVG({ className = '' }: { className?: string }) {+ return (+ <BarbellMark+ mark={BARBELL_DROPPED}+ className={className}+ // Same opt-out mobile's BarbellBroken takes: on a mark painted in one flat colour+ // the specular strips are lighter streaks over the same hue, which reads as damage+ // to the drawing rather than as shine. Dropping them keeps the two platforms one mark.+ highlight={false}+ ink={{ plate: 'currentColor', plateEdge: 'currentColor', collar: 'currentColor' }}+ />+ )+}diff --git a/web/src/components/BarbellSVG.tsx b/web/src/components/BarbellSVG.tsxindex 0e9ade5..b402bd1 100644--- a/web/src/components/BarbellSVG.tsx+++ b/web/src/components/BarbellSVG.tsx@@ -1,25 +1,81 @@-// Bent barbell from brand-logo.html design system-export default function BarbellSVG() {- return (- <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 40 40" width="40" height="40">- {/* Bent bar (under load) — currentColor so it adapts to light/dark */}- <path d="M4 16 Q20 25 36 16" fill="none" stroke="currentColor" strokeWidth="2.6" strokeLinecap="round" />+import type { BarbellInk, BarbellMarkData } from '@lyftr/shared'+import { BARBELL } from '@lyftr/shared'- {/* Collar dots */}- <circle cx="10.2" cy="18.8" r="1" fill="#475569" />- <circle cx="29.8" cy="18.8" r="1" fill="#475569" />-- {/* Left plates */}- <rect x="3" y="10" width="3" height="18" rx="0.8" fill="#0891b2" />- <rect x="6" y="8" width="4" height="22" rx="1" fill="#00b8d9" />+// Renders a barbell mark from shared geometry. The coordinates live in+// packages/shared/src/brand/barbell.ts because this file and mobile's BarbellMark used to+// carry the same path string and the same eight rects, typed out twice.+//+// `ink` maps a palette slot to a colour, so one drawing serves the logo (brand cyan, bar+// in currentColor) and the error state (muted, so it reads as a state and not as branding).+const DEFAULT_INK: Record<BarbellInk, string> = {+ bar: 'currentColor',+ plate: '#00b8d9',+ plateEdge: '#0891b2',+ highlight: '#7eeeff',+ collar: '#475569',+}- {/* Right plates */}- <rect x="34" y="10" width="3" height="18" rx="0.8" fill="#0891b2" />- <rect x="30" y="8" width="4" height="22" rx="1" fill="#00b8d9" />+const spin = (r?: readonly [number, number, number]) =>+ r ? { transform: `rotate(${r[0]} ${r[1]} ${r[2]})` } : {}- {/* Highlights */}- <rect x="7.2" y="10.5" width="1.2" height="17" rx="0.5" fill="#7eeeff" opacity="0.55" />- <rect x="31.6" y="10.5" width="1.2" height="17" rx="0.5" fill="#7eeeff" opacity="0.55" />+export function BarbellMark({+ mark = BARBELL,+ ink,+ className = '',+ width,+ height,+ highlight = true,+}: {+ mark?: BarbellMarkData+ ink?: Partial<Record<BarbellInk, string>>+ className?: string+ width?: number+ height?: number+ /** Specular strips. Off for a flat monochrome mark, where they read as a seam+ * rather than a shine — mobile's BarbellMark takes the same opt-out. */+ highlight?: boolean+}) {+ const paint = { ...DEFAULT_INK, ...ink }+ return (+ <svg+ xmlns="http://www.w3.org/2000/svg"+ viewBox={mark.viewBox}+ width={width}+ height={height}+ className={className}+ role="presentation"+ aria-hidden="true"+ >+ {mark.shapes.filter(s => highlight || s.ink !== 'highlight').map((s, i) =>+ s.kind === 'stroke' ? (+ <path+ key={i}+ d={s.d}+ fill="none"+ stroke={paint[s.ink]}+ strokeWidth={s.width}+ strokeLinecap={s.cap ?? 'round'}+ {...spin(s.rotate)}+ />+ ) : (+ <rect+ key={i}+ x={s.x}+ y={s.y}+ width={s.w}+ height={s.h}+ rx={s.rx}+ fill={paint[s.ink]}+ opacity={s.opacity}+ {...spin(s.rotate)}+ />+ ),+ )}</svg>)}++/** The brand mark at its original fixed size, for the logo lockup. */+export default function BarbellSVG() {+ return <BarbellMark width={40} height={40} />+}diff --git a/web/src/components/ui/ErrorState.test.tsx b/web/src/components/ui/ErrorState.test.tsxnew file mode 100644index 0000000..0d40dfb--- /dev/null+++ b/web/src/components/ui/ErrorState.test.tsx@@ -0,0 +1,52 @@+import { describe, it, expect, vi } from 'vitest'+import { render, screen, fireEvent } from '@testing-library/react'+import ErrorState from './ErrorState'+import ListError from './ListError'++// The component this whole slice exists to provide, and until now nothing rendered it in+// a test. Empty and error are different outcomes — empty means we heard back and there is+// nothing, error means we did not hear back at all — so the thing worth pinning is that+// this says which one it is, and offers a way out.+describe('ErrorState', () => {+ it('names what failed and why', () => {+ render(<ErrorState title="Couldn't load your dashboard" message="The server didn't respond in time." />)+ expect(screen.getByText("Couldn't load your dashboard")).toBeTruthy()+ expect(screen.getByText("The server didn't respond in time.")).toBeTruthy()+ })++ it('is announced as an alert, not read as ordinary prose', () => {+ render(<ErrorState title="Couldn't load" message="No answer." />)+ expect(screen.getByRole('alert')).toBeTruthy()+ })++ it('offers a retry that actually calls back', () => {+ const onRetry = vi.fn()+ render(<ErrorState title="Couldn't load" message="No answer." onRetry={onRetry} />)+ fireEvent.click(screen.getByRole('button', { name: /try again/i }))+ expect(onRetry).toHaveBeenCalledTimes(1)+ })++ it('shows no retry when there is nothing to retry', () => {+ render(<ErrorState title="Couldn't load" message="No answer." />)+ expect(screen.queryByRole('button')).toBeNull()+ })++ it('takes one escape hatch alongside the retry', () => {+ render(+ <ErrorState title="Couldn't load" message="No answer."+ onRetry={() => {}} secondary={<button>Back to workouts</button>} />,+ )+ expect(screen.getByRole('button', { name: /try again/i })).toBeTruthy()+ expect(screen.getByRole('button', { name: /back to workouts/i })).toBeTruthy()+ })+})++describe('ListError', () => {+ // A failed list is section-scoped: the search box and the create button above it still+ // work, so the state replaces the rows and says which rows they were.+ it('names the subject that failed to load', () => {+ render(<ListError subject="workouts" message="The server didn't respond." onRetry={() => {}} />)+ expect(screen.getByText("Couldn't load workouts")).toBeTruthy()+ expect(screen.getByRole('button', { name: /try again/i })).toBeTruthy()+ })+})diff --git a/web/src/components/ui/ErrorState.tsx b/web/src/components/ui/ErrorState.tsxnew file mode 100644index 0000000..4458569--- /dev/null+++ b/web/src/components/ui/ErrorState.tsx@@ -0,0 +1,77 @@+import type React from 'react'+import { RotateCw } from 'lucide-react'+import BarbellBrokenSVG from '../BarbellBrokenSVG'++// A load that failed, said as a state rather than as a banner over the wreckage.+//+// Empty and error are different outcomes and the design systems that bother to separate+// them all say so (Carbon, PatternFly, the Agriculture DS). Empty means we heard back and+// there is nothing; error means we did not hear back at all. Rendering the page's+// components anyway — a KPI tile reading 0, a chart with no line — states the first while+// the second is true, and a red bar above them does not undo that. The zeros are not a+// styling problem, they are wrong.+//+// `size` follows Geist's rule: full-page when the route itself is unusable, section when+// one region inside an otherwise-working page failed. A failed workouts LIST keeps its+// search box and its "Log Workout" button, so that is a section. A failed dashboard has+// nothing truthful left to draw, so that is a page.+//+// Anatomy is the shared one: mark, Title Case title, sentence-case body, at most one+// primary action and one secondary. `message` is whatever apiErrorMessage produced, so+// the specific cause — unreachable, timed out, cleartext blocked, 5xx — is already in the+// words and does not need a second icon to encode it.+interface Props {+ /** What we were trying to load, in the app's words: "Couldn't load your dashboard". */+ title: string+ /** The cause, from apiErrorMessage. */+ message: string+ size?: 'page' | 'section'+ onRetry?: () => void+ retryLabel?: string+ /** One escape hatch at most — a link out when retrying is not the answer. */+ secondary?: React.ReactNode+}++export default function ErrorState({+ title,+ message,+ size = 'section',+ onRetry,+ retryLabel = 'Try again',+ secondary,+}: Props) {+ const page = size === 'page'+ return (+ <div+ role="alert"+ className={`flex flex-col items-center justify-center text-center px-6 ${+ page ? 'min-h-[60vh] justify-center gap-3' : 'py-10 gap-2.5'+ }`}+ >+ {/* The mark carries the status colour, not the muted grey an empty state uses.+ PatternFly draws the line exactly here: icons are grey by default "except when+ used as a status icon", and it names our case — "inability to get data,+ backend failure" — as the red one. Only the mark is tinted; painting the whole+ page red would be alarming rather than legible, and the copy carries the detail. */}+ <BarbellBrokenSVG+ className={`${page ? 'w-16 h-16' : 'w-11 h-11'} text-[color:var(--alert-error)]`}+ />+ <div className="space-y-1 max-w-sm">+ <p className={`font-display font-bold text-tx-primary ${page ? 'text-xl' : 'text-base'}`}>+ {title}+ </p>+ <p className="text-sm text-tx-muted leading-relaxed">{message}</p>+ </div>+ {(onRetry || secondary) && (+ <div className="flex flex-wrap items-center justify-center gap-2 mt-1">+ {onRetry && (+ <button onClick={onRetry} className="btn-primary btn-sm flex items-center gap-1.5">+ <RotateCw className="w-3.5 h-3.5" /> {retryLabel}+ </button>+ )}+ {secondary}+ </div>+ )}+ </div>+ )+}diff --git a/web/src/components/ui/ListError.tsx b/web/src/components/ui/ListError.tsxnew file mode 100644index 0000000..ca47a8e--- /dev/null+++ b/web/src/components/ui/ListError.tsx@@ -0,0 +1,28 @@+import ErrorState from './ErrorState'++// A page of a list that never arrived.+//+// useServerList still answers a failed fetch by setting hasMore=false, which renders+// identically to reaching the end of the data — the one outcome a reader cannot tell+// from success. The list simply stops, and on a flaky connection "you have 12 workouts"+// and "you have 12 workouts so far" look the same.+//+// This component is the replacement for that silence; the hook starts reporting the+// failure, and the lists start rendering this, in the lists slice. Nothing calls it yet.+//+// A list failure is section-scoped, not page-scoped: the search box and the create+// button above it still work, so the state replaces the rows and nothing else. Retry+// resumes from where it stopped rather than reloading, so nothing already on screen is+// thrown away to recover the page that failed.+export default function ListError(+ { subject, message, onRetry }: { subject: string; message: string; onRetry: () => void },+) {+ return (+ <ErrorState+ size="section"+ title={`Couldn't load ${subject}`}+ message={message}+ onRetry={onRetry}+ />+ )+}diff --git a/web/src/components/ui/index.ts b/web/src/components/ui/index.tsindex fb941c6..c694f96 100644--- a/web/src/components/ui/index.ts+++ b/web/src/components/ui/index.ts@@ -8,3 +8,5 @@ export { default as NumberField } from './NumberField'export { default as StepperTile } from './StepperTile'export { default as Toast } from './Toast'export type { ToastVariant } from './Toast'+export { default as ErrorState } from './ErrorState'+export { default as ListError } from './ListError'diff --git a/web/src/index.css b/web/src/index.cssindex c417c7e..12ad198 100644--- a/web/src/index.css+++ b/web/src/index.css@@ -80,10 +80,15 @@/* Alerts */.alert { @apply flex gap-3 items-start rounded-lg p-3.5 text-sm border; }- .alert-error { @apply alert bg-error-500/10 border-error-500/20 text-error-400; }- .alert-success { @apply alert bg-success-500/10 border-success-500/20 text-success-400; }- .alert-info { @apply alert bg-brand-500/10 border-brand-500/20 text-brand-400; }- .alert-warning { @apply alert bg-warning-500/10 border-warning-500/20 text-warning-400; }+ /* Text colour comes from --alert-* (emitted per theme by the addBase plugin from+ the shared tokens), not from a fixed 400. The 400s are legible on the dark+ surface these classes were written against and measure 2.4:1 (error) and 1.4:1+ (warning) on the light one, below WCAG AA. packages/shared's alertContrast test+ fails the build if any pairing regresses. */+ .alert-error { @apply alert bg-error-500/10 border-error-500/20 text-[color:var(--alert-error)]; }+ .alert-success { @apply alert bg-success-500/10 border-success-500/20 text-[color:var(--alert-success)]; }+ .alert-info { @apply alert bg-brand-500/10 border-brand-500/20 text-[color:var(--alert-info)]; }+ .alert-warning { @apply alert bg-warning-500/10 border-warning-500/20 text-[color:var(--alert-warning)]; }/* Nav */.nav-item {