- Stats: three big numbers, no icon tiles - Payment methods move out of the step card into a strip that names every method and wraps - Course page: title on the course photo, preview button in the header; on phones a price + Buy (or progress + Continue) bar replaces the app tabs - Help: big heading, three contact cards (Telegram, call, email with copy), FAQ beside the form - Header: Get started only (Sign in removed) - Placeholder courses tagged in the seed; cleanup issue drafted in design/issues/ Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
180 lines
11 KiB
TypeScript
180 lines
11 KiB
TypeScript
'use client';
|
|
import { useEffect, useRef, useState, type ReactNode } from 'react';
|
|
import type { Course, Locale } from '@lms/data';
|
|
import { useApp } from './store';
|
|
import { tr } from './domain';
|
|
import { LOGO_MARK, LOGO_WORDMARK } from './brandLogo';
|
|
|
|
const PATHS: Record<string, string> = {
|
|
home: 'M3 11l9-7 9 7v9a1 1 0 0 1-1 1h-5v-6H9v6H4a1 1 0 0 1-1-1z',
|
|
grid: 'M4 4h7v7H4zM13 4h7v7h-7zM4 13h7v7H4zM13 13h7v7h-7z',
|
|
book: 'M4 5a2 2 0 0 1 2-2h13v16H6a2 2 0 0 0-2 2zM4 21V5M8 7h7',
|
|
help: 'M12 21a9 9 0 1 0 0-18 9 9 0 0 0 0 18zM9.5 9a2.5 2.5 0 1 1 3.5 2.3c-.6.3-1 .9-1 1.6V14M12 17.5v.01',
|
|
user: 'M12 12a4 4 0 1 0 0-8 4 4 0 0 0 0 8zM4 21a8 8 0 0 1 16 0',
|
|
bell: 'M6 8a6 6 0 1 1 12 0c0 7 3 8 3 8H3s3-1 3-8M10 20a2 2 0 0 0 4 0',
|
|
search: 'M11 18a7 7 0 1 0 0-14 7 7 0 0 0 0 14zM20 20l-4-4',
|
|
play: 'M7 4v16l13-8z',
|
|
pause: 'M7 4h4v16H7zM13 4h4v16h-4z',
|
|
lock: 'M6 11h12v10H6zM8 11V7a4 4 0 0 1 8 0v4',
|
|
check: 'M5 12l5 5 9-10',
|
|
quiz: 'M9 3h6v3H9zM7 4.5H5V21h14V4.5h-2M9 14l2 2 4-4',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h.01M3 18h.01',
|
|
tag: 'M3 12V3h9l9 9-9 9zM7.5 7.5h.01',
|
|
menu: 'M4 6h16M4 12h16M4 18h16',
|
|
upload: 'M12 16V4M7 9l5-5 5 5M4 20h16',
|
|
plus: 'M12 5v14M5 12h14',
|
|
mail: 'M3 6h18v12H3zM3 7l9 6 9-6',
|
|
up: 'M6 15l6-6 6 6',
|
|
down: 'M6 9l6 6 6-6',
|
|
download: 'M12 4v12M7 11l5 5 5-5M4 20h16',
|
|
phone: 'M5 4h4l2 5-2.5 1.5a11 11 0 0 0 5 5L15 13l5 2v4a2 2 0 0 1-2 2A16 16 0 0 1 3 6a2 2 0 0 1 2-2',
|
|
chat: 'M21 12a8 8 0 0 1-11.6 7.1L4 20l1-4.6A8 8 0 1 1 21 12z',
|
|
rewind: 'M11 19l-9-7 9-7zM22 19l-9-7 9-7z',
|
|
forward: 'M13 19l9-7-9-7zM2 19l9-7-9-7z',
|
|
expand: 'M4 9V4h5M20 9V4h-5M4 15v5h5M20 15v5h-5',
|
|
comment: 'M4 4h16v12H8l-4 4z',
|
|
globe: 'M12 21a9 9 0 1 0 0-18 9 9 0 0 0 0 18zM3 12h18M12 3a14 14 0 0 1 0 18M12 3a14 14 0 0 0 0 18',
|
|
clock: 'M12 21a9 9 0 1 0 0-18 9 9 0 0 0 0 18zM12 7v5l3 2',
|
|
calendar: 'M4 6h16v14H4zM4 10h16M8 3v4M16 3v4',
|
|
share: 'M4 12v7a1 1 0 0 0 1 1h14a1 1 0 0 0 1-1v-7M16 6l-4-4-4 4M12 2v13',
|
|
video: 'M3 6h12v12H3zM15 10l6-3v10l-6-3',
|
|
logout: 'M15 4h4a1 1 0 0 1 1 1v14a1 1 0 0 1-1 1h-4M10 17l5-5-5-5M15 12H3',
|
|
sparkle: 'M12 3l2 6 6 2-6 2-2 6-2-6-6-2 6-2z',
|
|
brush: 'M14 4l6 6-8 8-6-6zM6 12l-3 7 7-3',
|
|
moon: 'M20 14.5A8 8 0 1 1 9.5 4a6.5 6.5 0 0 0 10.5 10.5z',
|
|
sun: 'M12 8a4 4 0 1 0 0 8 4 4 0 0 0 0-8zM12 2v2M12 20v2M4.9 4.9l1.4 1.4M17.7 17.7l1.4 1.4M2 12h2M20 12h2M4.9 19.1l1.4-1.4M17.7 6.3l1.4-1.4',
|
|
};
|
|
|
|
export function Icon({ name, size = 20, label }: { name: keyof typeof PATHS | string; size?: number; label?: string }) {
|
|
return (
|
|
<svg width={size} height={size} viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth={2} strokeLinecap="round" strokeLinejoin="round" aria-hidden={label ? undefined : true} role={label ? 'img' : undefined} aria-label={label}>
|
|
<path d={PATHS[name] ?? ''} />
|
|
</svg>
|
|
);
|
|
}
|
|
|
|
// Sirkul logo: the full wordmark, or just the "Sm" monogram where space is tight. Height drives the size.
|
|
export function Logo({ size = 34, mark = false }: { size?: number; mark?: boolean }) {
|
|
return <span className="logo" aria-hidden><img src={mark ? LOGO_MARK : LOGO_WORDMARK} alt="" style={{ height: mark ? size : size * 1.25 }} /></span>;
|
|
}
|
|
|
|
export const VIMEO_ORIGIN = 'https://player.vimeo.com';
|
|
export const VIMEO_PLACEHOLDER = `${VIMEO_ORIGIN}/video/1084537?dnt=1&title=0&byline=0&portrait=0`;
|
|
|
|
// Makeup icons from IconPark Outline (ByteDance, Apache-2.0), via iconify.design. 48-unit grid, 4-unit stroke.
|
|
const KIT: Record<string, ReactNode> = {
|
|
brush: <><path d="m16.1 25.829l22.627-19.8s2.12-2.12 4.242 0c2.121 2.122 0 4.243 0 4.243L23.17 32.9z" /><path strokeLinecap="round" d="m22.464 20.879l5.657 5.657" /><path d="m5.493 30.778l10.607-4.95l7.07 7.072l-4.95 10.606s-4.95.707-9.192-3.535c-4.243-4.243-3.536-9.193-3.536-9.193Z" /><path strokeLinecap="round" d="m6.908 36.435l4.95-2.121m.707 7.778l1.415-2.828" /><path d="m18.93 23.354l2.828-2.475l2.828-2.475m6.01 6.01l-2.475 2.828l-2.475 2.829" /></>,
|
|
foundation: <path strokeLinecap="round" d="M13 19a2 2 0 0 1 2-2h16a2 2 0 0 1 2 2v19s0 6-6 6h-8c-6 0-6-6-6-6zm5-7h10v5H18zm0 0V9c0-3 3-5 6-5h11s-7 2-7 6v2" />,
|
|
lipstick: <path strokeLinecap="round" d="M29 24h12v20H29zM7 24h14v20H7zm3-12.545V24h8V4c-6.5 0-8 5.636-8 7.454M7 32h14" />,
|
|
brow: <><path d="M24 40c9.941 0 18-10 18-10s-8.059-10-18-10S6 30 6 30s8.059 10 18 10Z" /><path d="M24 34a4 4 0 1 0 0-8a4 4 0 0 0 0 8Zm4-28c-7 0-18 3.5-21 6s-1 7 1 6s15.2-5.8 20-7s11.667.833 14 2c-2.333-2-7-7-14-7Z" /></>,
|
|
mirror: <><circle cx="24" cy="17" r="13" /><path strokeLinecap="round" d="M42 17c0 9.941-8.059 18-18 18S6 26.941 6 17m36 0h-4m-28 0H6m24 27H18m6 0v-8" /></>,
|
|
};
|
|
export function KitIcon({ name, size = 24 }: { name: keyof typeof KIT | string; size?: number }) {
|
|
return <svg width={size} height={size} viewBox="0 0 48 48" fill="none" stroke="currentColor" strokeWidth="4" strokeLinejoin="round" aria-hidden>{KIT[name]}</svg>;
|
|
}
|
|
|
|
const TONES = ['rose', 'clay', 'plum', 'sand', 'sage', 'ink'];
|
|
|
|
// Stand-in photos (apps/demo/public/photos) until courses get uploaded covers: one per category, in category order.
|
|
export const CAT_PHOTOS = ['habesha-harari.jpg', 'hero.jpg', 'habesha-trad.jpg', 'habesha-eritrean.jpg'];
|
|
export function coursePhoto(course: Course, categoryIds: string[]) {
|
|
return `/photos/${CAT_PHOTOS[Math.max(0, categoryIds.indexOf(course.categoryId)) % CAT_PHOTOS.length]}`;
|
|
}
|
|
|
|
export function Cover({ course, locale, badge }: { course: Course; locale: Locale; badge?: ReactNode }) {
|
|
const { ds, categories } = useApp();
|
|
// No image → the title itself, set in Ge'ez serif, is the cover (§11.2: the script is the visual identity).
|
|
// Shows the title in the other script from the page's language, so the cover adds a second language instead of repeating the card title.
|
|
const other = locale === 'am' || locale === 'ti' ? 'en' : 'am';
|
|
const title = course.translations[other]?.title ?? tr(course.translations, locale)?.title ?? '';
|
|
const tone = course.coverTone && TONES.includes(course.coverTone) ? course.coverTone : 'ink';
|
|
return (
|
|
<div className={`cover tone-${tone} has-img`}>
|
|
<img src={course.coverAssetId ? ds.assetUrl(course.coverAssetId) : coursePhoto(course, categories.map((k) => k.id))} alt="" loading="lazy" />
|
|
{badge}
|
|
<span className="ttl" lang={other} aria-hidden>{title}</span>
|
|
</div>
|
|
);
|
|
}
|
|
|
|
export function Empty({ children, action }: { children: ReactNode; action?: ReactNode }) {
|
|
return <div className="empty"><p>{children}</p>{action}</div>;
|
|
}
|
|
|
|
export function Skeleton({ h = 120, n = 1 }: { h?: number; n?: number }) {
|
|
return <div className="stack" aria-busy="true" aria-live="polite">{Array.from({ length: n }, (_, i) => <div key={i} className="skel" style={{ height: h }} />)}</div>;
|
|
}
|
|
|
|
export function Modal({ title, onClose, children }: { title: string; onClose(): void; children: ReactNode }) {
|
|
const ref = useRef<HTMLDivElement>(null);
|
|
useEffect(() => {
|
|
const k = (e: KeyboardEvent) => e.key === 'Escape' && onClose();
|
|
addEventListener('keydown', k);
|
|
ref.current?.querySelector<HTMLElement>('input,select,textarea,button')?.focus();
|
|
return () => removeEventListener('keydown', k);
|
|
}, [onClose]);
|
|
return (
|
|
<div className="modal-back" onClick={(e) => e.target === e.currentTarget && onClose()}>
|
|
<div className="modal" role="dialog" aria-modal="true" aria-label={title} ref={ref}>
|
|
<div className="row-between"><h2 style={{ fontSize: 'var(--fs-lg)' }}>{title}</h2><button className="icon-btn" onClick={onClose} aria-label="Close"><Icon name="x" /></button></div>
|
|
{children}
|
|
</div>
|
|
</div>
|
|
);
|
|
}
|
|
|
|
export function Ring({ pct, size = 56 }: { pct: number; size?: number }) {
|
|
const r = 24, c = 2 * Math.PI * r;
|
|
return (
|
|
<svg className="ring" width={size} height={size} viewBox="0 0 56 56" role="img" aria-label={`${pct}%`}>
|
|
<circle className="bg" cx="28" cy="28" r={r} />
|
|
<circle className="fg" cx="28" cy="28" r={r} strokeDasharray={c} strokeDashoffset={c * (1 - pct / 100)} />
|
|
<text x="28" y="32" textAnchor="middle" fontSize="13" fontWeight="700" fill="currentColor">{pct}%</text>
|
|
</svg>
|
|
);
|
|
}
|
|
|
|
const PILL_KIND: Record<string, string> = {
|
|
PAID: 'ok', ACTIVE: 'ok', PUBLISHED: 'ok', RESOLVED: 'ok', READY: 'ok', SENT: 'ok',
|
|
PENDING: 'warn', OPEN: 'warn', IN_PROGRESS: 'info', DRAFT: 'info', PROCESSING: 'info', UPLOADING: 'info', SCHEDULED: 'info',
|
|
FAILED: 'bad', EXPIRED: 'bad', DEACTIVATED: 'bad', CANCELLED: '', REFUNDED: 'info', ARCHIVED: '', CLOSED: '', NONE: '',
|
|
};
|
|
export function StatusPill({ status, label }: { status: string; label?: string }) {
|
|
const k = PILL_KIND[status];
|
|
return <span className={`pill ${k ? 'pill-' + k : ''}`}>{label ?? status.replace(/_/g, ' ').toLowerCase().replace(/^./, (c) => c.toUpperCase())}</span>;
|
|
}
|
|
|
|
/** "Leave feedback" — opens a Claude comment pinned to the current screen (§18.6). Hidden when comments are unavailable. */
|
|
export function FeedbackButton({ label, target }: { label: string; target: () => Element | null }) {
|
|
const { ds } = useApp();
|
|
const [ok, setOk] = useState(false);
|
|
useEffect(() => { ds.feedbackAvailable().then(setOk); }, [ds]);
|
|
if (!ok) return null;
|
|
return <button className="btn btn-ghost btn-sm feedback-btn" aria-label={label} title={label} onClick={() => { const el = target(); if (el) ds.feedback(el); }}><Icon name="comment" size={16} /><span className="lbl">{label}</span></button>;
|
|
}
|
|
|
|
export function CopyText({ text, copyLabel, copiedLabel }: { text: string; copyLabel: string; copiedLabel: string }) {
|
|
const [done, setDone] = useState(false);
|
|
return (
|
|
<button className="btn btn-ghost btn-sm" onClick={() => {
|
|
navigator.clipboard?.writeText(text).then(() => setDone(true), () => setDone(false));
|
|
}}>{done ? copiedLabel : copyLabel}</button>
|
|
);
|
|
}
|
|
|
|
// Gregorian, en-GB digits in every locale for the demo; Ethiopian calendar is P2 (§12).
|
|
export const fmtDate = (iso?: string | null) =>
|
|
iso ? new Date(iso).toLocaleDateString('en-GB', { day: 'numeric', month: 'short', year: 'numeric' }) : '—';
|
|
export const fmtDateTime = (iso?: string | null) =>
|
|
iso ? new Date(iso).toLocaleString('en-GB', { day: 'numeric', month: 'short', year: 'numeric', hour: '2-digit', minute: '2-digit' }) : '—';
|