|
|
|
|
@ -35,29 +35,22 @@ const ct = (c: Course, l: Locale) => tr(c.translations, l) ?? { title: c.slug, d
|
|
|
|
|
const lessonTitle = (l: Lesson, loc: Locale) => tr(l.translations, loc)?.title ?? '';
|
|
|
|
|
const lessonNumber = (c: Course, id: string) => publishedLessons(c).findIndex((l) => l.id === id) + 1;
|
|
|
|
|
|
|
|
|
|
// C1: one quiet "lessons · length" line, with "new course" / student count as a tag on the photo.
|
|
|
|
|
// C2: the whole card is the target, so the footer is just the price. C3: owned cards say what's next.
|
|
|
|
|
// `tall` keeps the photo-on-top layout on phones too (the home Featured rail, C4).
|
|
|
|
|
function CourseCard({ c, tall }: { c: Course; tall?: boolean }) {
|
|
|
|
|
function CourseCard({ c }: { c: Course }) {
|
|
|
|
|
const { locale, nav, me, signedIn } = useApp();
|
|
|
|
|
const t = useTranslations();
|
|
|
|
|
const { catName } = useCatalog();
|
|
|
|
|
const p = courseProgress(c, me);
|
|
|
|
|
const mine = signedIn && owns(me, c.id);
|
|
|
|
|
const r = mine ? resumePoint(c, me) : null;
|
|
|
|
|
const tag = c.enrolledCount ? t('course.enrolled', { n: c.enrolledCount }) : t('course.newCourse');
|
|
|
|
|
return (
|
|
|
|
|
<button className={`ccard${tall ? ' ccard-tall' : ''}`} onClick={() => nav(`/${locale}/course/${c.slug}`)}>
|
|
|
|
|
<Cover course={c} locale={locale} badge={<><span className="pill">{catName(c.categoryId)}</span>{!mine && <span className="ccard-tag">{tag}</span>}</>} />
|
|
|
|
|
<button className="ccard" onClick={() => nav(`/${locale}/course/${c.slug}`)}>
|
|
|
|
|
<Cover course={c} locale={locale} badge={<span className="pill">{catName(c.categoryId)}</span>} />
|
|
|
|
|
<div className="ccard-body">
|
|
|
|
|
<h3>{ct(c, locale).title}</h3>
|
|
|
|
|
<span className="meta num">{t('course.lessons', { n: p.total })} · {formatDuration(courseDuration(c))}</span>
|
|
|
|
|
<span className="meta"><span><Icon name="video" size={14} />{t('course.lessons', { n: p.total })}</span><span><Icon name="clock" size={14} />{formatDuration(courseDuration(c))}</span><span><Icon name="users" size={14} />{c.enrolledCount ? t('course.enrolled', { n: c.enrolledCount }) : t('course.newCourse')}</span></span>
|
|
|
|
|
<span className="ccard-by">{t('course.by', { name: c.instructorName })}</span>
|
|
|
|
|
<div className="ccard-foot">
|
|
|
|
|
{mine ? <>
|
|
|
|
|
{r && <span className="ccard-next">{p.pct === 100 ? <b>{t('course.completed')}</b> : <><b>{t('player.upNext')}</b> {r.index + 1}. {lessonTitle(r.lesson, locale)} · <span className="num">{formatDuration(r.lesson.durationSec)}</span></>}</span>}
|
|
|
|
|
<span className="ccard-prog"><span className="bar grow" aria-label={`${p.pct}%`}><i style={{ width: `${p.pct}%` }} /></span><span className="small num">{p.pct}%</span></span>
|
|
|
|
|
</> : c.prices.ETB != null && <strong className="num">{formatMoney(c.prices.ETB, 'ETB')}</strong>}
|
|
|
|
|
{mine ? <><div className="bar grow" aria-label={`${p.pct}%`}><i style={{ width: `${p.pct}%` }} /></div><span className="small num">{p.pct}%</span></>
|
|
|
|
|
: <>{c.prices.ETB != null ? <strong className="num">{formatMoney(c.prices.ETB, 'ETB')}</strong> : <span />}<span className="ccard-go" aria-hidden><Icon name="chevron" size={18} /></span></>}
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</button>
|
|
|
|
|
@ -99,10 +92,9 @@ export function StudentApp() {
|
|
|
|
|
const tabs: [string, string, string][] = [['', 'home', t('nav.home')], ['courses', 'grid', t('nav.courses')], ['my', 'book', t('nav.myCourses')], ['help', 'help', t('nav.help')], ['profile', 'user', t('nav.profile')]];
|
|
|
|
|
const links = tabs.filter(([p]) => p !== 'profile' && (p !== 'my' || signedIn));
|
|
|
|
|
const current = (s: string) => (s === section || (s === 'courses' && (section === 'course')) || (s === 'profile' && (section === 'progress' || section === 'history')) ? 'page' : undefined);
|
|
|
|
|
const focus = section === 'learn'; // L1: watching a lesson drops the site links and the marketing footer
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<div lang={locale} className={focus ? 's-focus' : undefined}>
|
|
|
|
|
<div lang={locale}>
|
|
|
|
|
<header className={`s-top${scrolled ? ' scrolled' : ''}`}>
|
|
|
|
|
<div className="s-top-in">
|
|
|
|
|
<button className="brand" onClick={() => go('')} aria-label={settings.brandName}><Logo size={36} /><Logo size={36} mark /></button>
|
|
|
|
|
@ -143,7 +135,7 @@ export function StudentApp() {
|
|
|
|
|
{settings.maintenanceBanner && <div className="banner small" role="status">{settings.maintenanceBanner}</div>}
|
|
|
|
|
<StudentRoutes />
|
|
|
|
|
</main>
|
|
|
|
|
{!focus && <Footer />}
|
|
|
|
|
<Footer />
|
|
|
|
|
{signedIn && section !== 'learn' && section !== 'course' && <nav className="s-tabs" aria-label="Main">
|
|
|
|
|
{tabs.map(([p, icon, label]) => <button key={p} data-tour={p} aria-current={current(p)} onClick={() => go(p ? '/' + p : '')}><Icon name={icon} size={22} />{label}</button>)}
|
|
|
|
|
</nav>}
|
|
|
|
|
@ -470,44 +462,33 @@ function Home() {
|
|
|
|
|
const others = visible.filter((c) => !owns(me, c.id));
|
|
|
|
|
return (
|
|
|
|
|
<>
|
|
|
|
|
<div className="home-top">
|
|
|
|
|
<h1 style={{ fontSize: 'var(--fs-2xl)' }}>{t('home.hello', { name: me?.name.split(' ')[0] ?? '' })}</h1>
|
|
|
|
|
{cont ? <ContinueCard c={cont} /> : <Empty action={<button className="btn" onClick={() => nav(`/${locale}/courses`)}>{t('landing.browse')}</button>}>{t('home.emptyMine')}</Empty>}
|
|
|
|
|
</div>
|
|
|
|
|
<h1 style={{ fontSize: 'var(--fs-2xl)' }}>{t('home.hello', { name: me?.name.split(' ')[0] ?? '' })}</h1>
|
|
|
|
|
{cont ? <ContinueCard c={cont} /> : <Empty action={<button className="btn" onClick={() => nav(`/${locale}/courses`)}>{t('landing.browse')}</button>}>{t('home.emptyMine')}</Empty>}
|
|
|
|
|
{mine.length > 1 && <section className="stack"><div className="section-h"><h2>{t('nav.myCourses')}</h2><button className="link" onClick={() => nav(`/${locale}/my`)}>{t('my.viewProgress')}</button></div><div className="grid-cards">{mine.map((c) => <CourseCard key={c.id} c={c} />)}</div></section>}
|
|
|
|
|
<section className="stack">
|
|
|
|
|
<div className="section-h"><h2>{t('home.categories')}</h2></div>
|
|
|
|
|
<div className="chips">{categories.filter((c) => c.isActive).map((c) => <button key={c.id} className="chip" onClick={() => nav(`/${locale}/courses/${c.slug}`)}>{tr(c.translations, locale)?.name}</button>)}</div>
|
|
|
|
|
</section>
|
|
|
|
|
{others.length > 0 && <section className="stack"><div className="section-h"><h2>{others.some((c) => c.isFeatured) ? t('home.featured') : t('home.new')}</h2><button className="link" onClick={() => nav(`/${locale}/courses`)}>{t('catalog.title')}</button></div><div className="rail">{[...others.filter((c) => c.isFeatured), ...others.filter((c) => !c.isFeatured)].slice(0, 4).map((c) => <CourseCard key={c.id} c={c} tall />)}</div></section>}
|
|
|
|
|
{others.length > 0 && <section className="stack"><div className="section-h"><h2>{others.some((c) => c.isFeatured) ? t('home.featured') : t('home.new')}</h2><button className="link" onClick={() => nav(`/${locale}/courses`)}>{t('catalog.title')}</button></div><div className="grid-cards">{[...others.filter((c) => c.isFeatured), ...others.filter((c) => !c.isFeatured)].slice(0, 4).map((c) => <CourseCard key={c.id} c={c} />)}</div></section>}
|
|
|
|
|
</>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// H1/H2: a short photo header carries the course and its progress; the body leads with the next lesson and how long
|
|
|
|
|
// it takes, with the button at the bottom where a thumb reaches it.
|
|
|
|
|
function ContinueCard({ c }: { c: Course }) {
|
|
|
|
|
const t = useTranslations();
|
|
|
|
|
const { me, locale, nav, ds, categories } = useApp();
|
|
|
|
|
const { me, locale, nav } = useApp();
|
|
|
|
|
const p = courseProgress(c, me);
|
|
|
|
|
const r = resumePoint(c, me);
|
|
|
|
|
const finished = p.pct === 100;
|
|
|
|
|
const photo = c.coverAssetId ? ds.assetUrl(c.coverAssetId) : coursePhoto(c, categories.map((k) => k.id));
|
|
|
|
|
return (
|
|
|
|
|
<section className="continue" aria-label={t('home.continue')}>
|
|
|
|
|
<div className="continue-media">
|
|
|
|
|
<img src={photo} alt="" />
|
|
|
|
|
<span className="continue-kicker">{t('home.continue')}</span>
|
|
|
|
|
<h2>{ct(c, locale).title}</h2>
|
|
|
|
|
<span className="continue-bar" role="progressbar" aria-valuenow={p.pct} aria-valuemin={0} aria-valuemax={100} aria-label={t('my.lessonsDone', { done: p.done, total: p.total })}><i style={{ width: `${p.pct}%` }} /></span>
|
|
|
|
|
</div>
|
|
|
|
|
<div className="continue-body">
|
|
|
|
|
{r && <p className="continue-next">
|
|
|
|
|
<span>{finished ? t('course.completed') : t('player.upNext')}</span>
|
|
|
|
|
<strong>{r.index + 1}. {lessonTitle(r.lesson, locale)}</strong>
|
|
|
|
|
<span className="num">{formatDuration(r.lesson.durationSec)} · {t('my.lessonsDone', { done: p.done, total: p.total })}</span>
|
|
|
|
|
</p>}
|
|
|
|
|
{r && <button className="btn btn-accent btn-lg" onClick={() => nav(`/${locale}/learn/${c.slug}/${r.lesson.id}`)}><Icon name="play" size={16} />{finished ? t('course.watchAgain') : t('course.continue', { n: r.index + 1 })}</button>}
|
|
|
|
|
<Cover course={c} locale={locale} />
|
|
|
|
|
<div className="stack-sm">
|
|
|
|
|
<span className="small" style={{ opacity: .8 }}>{t('home.continue')}</span>
|
|
|
|
|
<h2 style={{ fontSize: 'var(--fs-xl)' }}>{ct(c, locale).title}</h2>
|
|
|
|
|
{r && <p style={{ opacity: .85 }}>{r.index + 1}. {lessonTitle(r.lesson, locale)}</p>}
|
|
|
|
|
<div className="bar"><i style={{ width: `${p.pct}%` }} /></div>
|
|
|
|
|
<span className="small num" style={{ opacity: .8 }}>{t('my.lessonsDone', { done: p.done, total: p.total })}</span>
|
|
|
|
|
{r && <div><button className="btn btn-accent" onClick={() => nav(`/${locale}/learn/${c.slug}/${r.lesson.id}`)}><Icon name="play" size={16} />{p.pct === 100 ? t('course.watchAgain') : t('course.continue', { n: r.index + 1 })}</button></div>}
|
|
|
|
|
</div>
|
|
|
|
|
</section>
|
|
|
|
|
);
|
|
|
|
|
@ -520,43 +501,27 @@ function Catalog({ categorySlug }: { categorySlug?: string }) {
|
|
|
|
|
const { categories, locale, nav, catalogLoaded } = useApp();
|
|
|
|
|
const { visible, catName } = useCatalog();
|
|
|
|
|
const [q, setQ] = useState('');
|
|
|
|
|
const [lang, setLang] = useState(''); // '' = any language the course is taught in (CT3)
|
|
|
|
|
const searchRef = useRef<HTMLInputElement>(null);
|
|
|
|
|
const dq = q.trim().toLowerCase(); // the list is in memory: filter on every keystroke, no debounce (CT2)
|
|
|
|
|
const [dq, setDq] = useState('');
|
|
|
|
|
useEffect(() => { const id = setTimeout(() => setDq(q.trim().toLowerCase()), 300); return () => clearTimeout(id); }, [q]);
|
|
|
|
|
const cat = categories.find((c) => c.slug === categorySlug);
|
|
|
|
|
const langs = [...new Set(visible.map((c) => c.instructionLocale))];
|
|
|
|
|
const list = visible.filter((c) => (!cat || c.categoryId === cat.id) && (!lang || c.instructionLocale === lang) && (!dq || [
|
|
|
|
|
const list = visible.filter((c) => (!cat || c.categoryId === cat.id) && (!dq || [
|
|
|
|
|
...Object.values(c.translations).map((x) => x?.title ?? ''), c.instructorName,
|
|
|
|
|
...Object.values(categories.find((k) => k.id === c.categoryId)?.translations ?? {}).map((x) => x?.name ?? ''),
|
|
|
|
|
].some((s) => s.toLowerCase().includes(dq))));
|
|
|
|
|
const clear = () => { setQ(''); searchRef.current?.focus(); };
|
|
|
|
|
return (
|
|
|
|
|
<section className="stack">
|
|
|
|
|
<h1 style={{ fontSize: 'var(--fs-2xl)' }}>{cat ? catName(cat.id) : t('catalog.title')}</h1>
|
|
|
|
|
<label className="search">
|
|
|
|
|
<span className="sr-only">{t('catalog.search')}</span>
|
|
|
|
|
<Icon name="search" size={18} />
|
|
|
|
|
<input ref={searchRef} id="search" className="input" type="search" placeholder={t('catalog.search')} value={q} onChange={(e) => setQ(e.target.value)} onKeyDown={(e) => { if (e.key === 'Escape' && q) clear(); }} />
|
|
|
|
|
{q && <button type="button" className="search-clear" onClick={clear} aria-label={t('catalog.clearSearch')}><Icon name="x" size={16} /></button>}
|
|
|
|
|
<label className="field"><span className="sr-only">{t('catalog.search')}</span>
|
|
|
|
|
<input id="search" className="input" type="search" placeholder={t('catalog.search')} value={q} onChange={(e) => setQ(e.target.value)} />
|
|
|
|
|
</label>
|
|
|
|
|
<div className="chips" role="group">
|
|
|
|
|
<button className="chip" aria-pressed={!cat} onClick={() => nav(`/${locale}/courses`)}>{t('catalog.all')}</button>
|
|
|
|
|
{categories.filter((c) => c.isActive).map((c) => <button key={c.id} className="chip" aria-pressed={cat?.id === c.id} onClick={() => nav(`/${locale}/courses/${c.slug}`)}>{tr(c.translations, locale)?.name}</button>)}
|
|
|
|
|
</div>
|
|
|
|
|
{!catalogLoaded ? <Skeleton h={220} n={2} /> : <>
|
|
|
|
|
<div className="catalog-bar">
|
|
|
|
|
<p className="muted small" aria-live="polite">{t('catalog.count', { n: list.length })}</p>
|
|
|
|
|
{langs.length > 1 && <label className="catalog-lang">
|
|
|
|
|
<span>{t('catalog.taughtIn')}</span>
|
|
|
|
|
<select id="catalog-lang" value={lang} onChange={(e) => setLang(e.target.value)}>
|
|
|
|
|
<option value="">{t('catalog.anyLanguage')}</option>
|
|
|
|
|
{langs.map((l) => <option key={l} value={l}>{LOCALE_NAMES[l]}</option>)}
|
|
|
|
|
</select>
|
|
|
|
|
</label>}
|
|
|
|
|
</div>
|
|
|
|
|
{list.length ? <div className="grid-cards">{list.map((c) => <CourseCard key={c.id} c={c} />)}</div>
|
|
|
|
|
: <Empty action={dq || lang ? <button className="btn btn-ghost" onClick={() => { setQ(''); setLang(''); }}>{t('catalog.clearFilters')}</button> : undefined}>{dq ? t('catalog.empty', { q }) : lang ? t('catalog.emptyLanguage') : t('catalog.emptyCategory')}</Empty>}
|
|
|
|
|
</>}
|
|
|
|
|
{!catalogLoaded ? <Skeleton h={220} n={2} /> : list.length ? <>
|
|
|
|
|
<p className="muted small" aria-live="polite">{t('catalog.count', { n: list.length })}</p>
|
|
|
|
|
<div className="grid-cards">{list.map((c) => <CourseCard key={c.id} c={c} />)}</div>
|
|
|
|
|
</> : <Empty action={dq ? <button className="btn btn-ghost" onClick={() => setQ('')}>{t('catalog.all')}</button> : undefined}>{dq ? t('catalog.empty', { q }) : t('catalog.emptyCategory')}</Empty>}
|
|
|
|
|
</section>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
@ -567,19 +532,9 @@ function CoursePage({ slug }: { slug?: string }) {
|
|
|
|
|
const t = useTranslations();
|
|
|
|
|
const { courses, categories, me, locale, nav, catalogLoaded, toast, ds } = useApp();
|
|
|
|
|
const { catName } = useCatalog();
|
|
|
|
|
const [tab, setTab] = useState<string | null>(null); // null: the viewer's default (curriculum once they own it)
|
|
|
|
|
// The sticky bar repeats the buy card's button, so it only shows while that button is off screen (P1).
|
|
|
|
|
const [ctaEl, setCtaEl] = useState<HTMLDivElement | null>(null);
|
|
|
|
|
const [ctaInView, setCtaInView] = useState(true); // start hidden: the bar slides in once the button is known to be off screen, never flashes out on load
|
|
|
|
|
const [tab, setTab] = useState('overview');
|
|
|
|
|
const c = courses.find((x) => x.slug === slug);
|
|
|
|
|
useEffect(() => { if (c) document.title = `${ct(c, locale).title} · Sirkul Makeup`; }, [c, locale]); // before the early returns: hooks must run every render
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
if (!ctaEl || typeof IntersectionObserver === 'undefined') { setCtaInView(false); return; }
|
|
|
|
|
// The bottom margin is the bar's own height: a button still underneath the bar doesn't count as visible.
|
|
|
|
|
const io = new IntersectionObserver(([e]) => setCtaInView(e.isIntersecting), { rootMargin: '0px 0px -88px 0px' });
|
|
|
|
|
io.observe(ctaEl);
|
|
|
|
|
return () => io.disconnect();
|
|
|
|
|
}, [ctaEl]);
|
|
|
|
|
if (!catalogLoaded) return <Skeleton h={260} n={2} />;
|
|
|
|
|
if (!c || !isStudentVisible(c, me)) return <Empty action={<button className="btn" onClick={() => nav(`/${locale}/courses`)}>{t('catalog.title')}</button>}>{t('course.notFound')}</Empty>;
|
|
|
|
|
const text = ct(c, locale);
|
|
|
|
|
@ -594,29 +549,21 @@ function CoursePage({ slug }: { slug?: string }) {
|
|
|
|
|
const previews = lessons.filter((l) => l.isPreview).length;
|
|
|
|
|
const cat = categories.find((k) => k.id === c.categoryId);
|
|
|
|
|
const chapters = [...c.chapters].sort((a, b) => a.sortOrder - b.sortOrder);
|
|
|
|
|
// The hero only offers the free preview; once owned, the progress card below carries the one "continue" button (P2).
|
|
|
|
|
const play = !mine && preview ? `/${locale}/learn/${c.slug}/${preview.id}` : null;
|
|
|
|
|
const play = mine && r ? `/${locale}/learn/${c.slug}/${r.lesson.id}` : preview ? `/${locale}/learn/${c.slug}/${preview.id}` : null;
|
|
|
|
|
const playLabel = mine && r ? (done ? t('course.watchAgain') : t('course.continue', { n: r.index + 1 })) : t('course.watchPreview');
|
|
|
|
|
const share = () => { navigator.clipboard?.writeText(location.href).then(() => toast(t('course.linkCopied')), () => { /* clipboard blocked */ }); };
|
|
|
|
|
const teaches = courses.filter((x) => x.instructorName === c.instructorName && isStudentVisible(x, me)).length;
|
|
|
|
|
// No uploaded cover in the demo → a category photo stands in on the preview card.
|
|
|
|
|
const photo = c.coverAssetId ? ds.assetUrl(c.coverAssetId) : coursePhoto(c, categories.map((k) => k.id));
|
|
|
|
|
// Owners come back for the curriculum, buyers for the pitch (P4). Desktop shows one tab at a time;
|
|
|
|
|
// phones drop the tabs and stack every section in one scroll (P3).
|
|
|
|
|
const active = tab ?? (mine ? 'content' : 'overview');
|
|
|
|
|
const tabs: [string, string][] = [['overview', t('course.tabOverview')], ['content', t('course.content')]];
|
|
|
|
|
const quizzes = c.assessments ?? [];
|
|
|
|
|
const finalQuizzes = quizzes.filter((a) => !a.chapterId || !chapters.some((ch) => ch.id === a.chapterId && ch.lessons.some((l) => l.isPublished)));
|
|
|
|
|
const nextChapter = mine && r ? chapters.find((ch) => ch.lessons.some((l) => l.id === r.lesson.id))?.id : undefined;
|
|
|
|
|
const tabs: [string, string][] = [['overview', t('course.tabOverview')], ['content', t('course.content')], ['instructor', t('course.tabInstructor')]];
|
|
|
|
|
const includes: [string, ReactNode][] = [
|
|
|
|
|
['globe', LOCALE_NAMES[c.instructionLocale]],
|
|
|
|
|
['video', t('course.lessons', { n: lessons.length })],
|
|
|
|
|
['clock', formatDuration(courseDuration(c))],
|
|
|
|
|
...(previews ? [['play', t('course.previewLessons', { n: previews })] as [string, ReactNode]] : []),
|
|
|
|
|
...(c.assessments?.length ? [['quiz', t('assess.title')] as [string, ReactNode]] : []),
|
|
|
|
|
['shield', t('course.lifetimeAccess')],
|
|
|
|
|
];
|
|
|
|
|
const showBar = !!(mine ? r : c.prices.ETB != null && c.status === 'PUBLISHED');
|
|
|
|
|
const barHidden = showBar && ctaInView;
|
|
|
|
|
return (
|
|
|
|
|
<div className="cd">
|
|
|
|
|
<section className="cd-head">
|
|
|
|
|
@ -629,20 +576,21 @@ function CoursePage({ slug }: { slug?: string }) {
|
|
|
|
|
</nav>
|
|
|
|
|
<span className="row" style={{ gap: 6 }}>
|
|
|
|
|
{c.status === 'ARCHIVED' && <StatusPill status="ARCHIVED" />}
|
|
|
|
|
<button className="cd-share" onClick={share} aria-label={t('course.share')}><Icon name="share" size={16} /></button>
|
|
|
|
|
{mine && <span className="cd-chip"><Icon name="check" size={12} />{done ? t('course.completed') : t('course.owned')}</span>}
|
|
|
|
|
</span>
|
|
|
|
|
</div>
|
|
|
|
|
<h1>{text.title}</h1>
|
|
|
|
|
<div className="cd-stats">
|
|
|
|
|
<span className="cd-pill"><Icon name="video" size={14} /><strong className="num">{lessons.length}</strong>{t('course.lessonsLabel')}</span>
|
|
|
|
|
<span className="cd-pill"><Icon name="clock" size={14} /><strong className="num">{formatDuration(courseDuration(c))}</strong></span>
|
|
|
|
|
{mine && <span className="cd-pill cd-pill-own"><Icon name="check" size={14} /><strong>{done ? t('course.completed') : t('course.owned')}</strong></span>}
|
|
|
|
|
{previews > 0 && <span className="muted small">{t('course.previewLessons', { n: previews })}</span>}
|
|
|
|
|
</div>
|
|
|
|
|
{(text.subtitle || text.description) && <p className="cd-lead">{text.subtitle || text.description}</p>}
|
|
|
|
|
{play && <button className="cd-hero-play" onClick={() => nav(play)}><span className="play-dot"><Icon name="play" size={12} /></span>{playLabel}</button>}
|
|
|
|
|
<div className="cd-by">
|
|
|
|
|
<span className="avatar" aria-hidden>{initials(c.instructorName)}</span>
|
|
|
|
|
<span className="cd-by-txt"><em>{t('course.createdBy')}</em><strong>{c.instructorName}</strong><span className="cd-by-n">{t('course.teaches', { n: teaches })}</span></span>
|
|
|
|
|
<span className="cd-by-txt"><em>{t('course.createdBy')}</em><strong>{c.instructorName}</strong></span>
|
|
|
|
|
<span className="cd-updated"><Icon name="calendar" size={14} />{t('course.lastUpdated')} <span className="num">{fmtDate(c.updatedAt)}</span></span>
|
|
|
|
|
</div>
|
|
|
|
|
</section>
|
|
|
|
|
|
|
|
|
|
@ -652,25 +600,25 @@ function CoursePage({ slug }: { slug?: string }) {
|
|
|
|
|
<div className="row-between"><strong>{done ? t('course.completed') : t('course.owned')}</strong><span className="small num">{p.pct}%</span></div>
|
|
|
|
|
<div className="bar"><i style={{ width: `${p.pct}%` }} /></div>
|
|
|
|
|
<span className="small muted num">{t('my.lessonsDone', { done: p.done, total: p.total })}</span>
|
|
|
|
|
{pre && !preDone && <p className="cd-prereq"><Icon name="lock" size={14} /><span>{t('course.prereq', { title: ct(pre, locale).title })} <button className="link" onClick={() => nav(`/${locale}/course/${pre.slug}`)}>{t('course.prereqLink', { title: ct(pre, locale).title })}</button></span></p>}
|
|
|
|
|
{r && !done && <p className="cd-next"><span>{t('player.upNext')}</span><strong>{r.index + 1}. {lessonTitle(r.lesson, locale)}</strong><span className="num">{clock(r.lesson.durationSec)}</span></p>}
|
|
|
|
|
{r && <div className="cd-cta" ref={setCtaEl}><button className={`btn btn-lg ${done ? 'btn-ghost' : 'btn-accent'}`} onClick={() => nav(`/${locale}/learn/${c.slug}/${r.lesson.id}`)}>{playLabel}</button></div>}
|
|
|
|
|
{r && <div className="cd-cta"><button className={`btn btn-lg ${done ? 'btn-ghost' : 'btn-accent'}`} onClick={() => nav(`/${locale}/learn/${c.slug}/${r.lesson.id}`)}>{playLabel}</button><button className="cd-round" onClick={share} aria-label={t('course.share')}><Icon name="share" size={18} /></button></div>}
|
|
|
|
|
</> : <>
|
|
|
|
|
{c.prices.ETB != null && <div className="cd-price"><span className="num">{formatMoney(c.prices.ETB, 'ETB')}</span><span>{t('checkout.lifetime')}</span></div>}
|
|
|
|
|
{pre && !preDone && <p className="cd-prereq"><Icon name="lock" size={14} /><span>{t('course.prereq', { title: ct(pre, locale).title })} <button className="link" onClick={() => nav(`/${locale}/course/${pre.slug}`)}>{t('course.prereqLink', { title: ct(pre, locale).title })}</button></span></p>}
|
|
|
|
|
<div className="cd-cta" ref={setCtaEl}>
|
|
|
|
|
<button className="btn btn-accent btn-lg" disabled={c.status !== 'PUBLISHED' || c.prices.ETB == null} onClick={() => nav(`/${locale}/checkout/${c.slug}`)}>{t('course.buyShort')}</button>
|
|
|
|
|
</div>
|
|
|
|
|
<div className="cd-includes">
|
|
|
|
|
<h2>{t('course.includes')}</h2>
|
|
|
|
|
<ul>{includes.map(([icon, label], k) => <li key={k}><Icon name={icon} size={18} />{label}</li>)}</ul>
|
|
|
|
|
{c.sequentialLessons && <p className="small muted">{t('course.sequential')}</p>}
|
|
|
|
|
{c.prices.ETB != null && <div className="cd-price"><span className="num">{formatMoney(c.prices.ETB, 'ETB')}</span><span>{t('course.lifetime')}</span></div>}
|
|
|
|
|
<div className="cd-cta">
|
|
|
|
|
<button className="btn btn-accent btn-lg" disabled={c.status !== 'PUBLISHED' || c.prices.ETB == null} onClick={() => nav(`/${locale}/checkout/${c.slug}`)}>{t('course.buy', { price: formatMoney(c.prices.ETB ?? 0, 'ETB') })}</button>
|
|
|
|
|
<button className="cd-round" onClick={share} aria-label={t('course.share')}><Icon name="share" size={18} /></button>
|
|
|
|
|
</div>
|
|
|
|
|
{preview && <button className="btn btn-ghost btn-block" onClick={() => nav(`/${locale}/learn/${c.slug}/${preview.id}`)}><Icon name="play" size={16} />{t('course.watchPreview')}</button>}
|
|
|
|
|
<p className="cd-note"><Icon name="lock" size={14} />{t('checkout.lifetime')}</p>
|
|
|
|
|
</>}
|
|
|
|
|
<div className="cd-includes">
|
|
|
|
|
<h2>{t('course.includes')}</h2>
|
|
|
|
|
<ul>{includes.map(([icon, label], k) => <li key={k}><Icon name={icon} size={18} />{label}</li>)}</ul>
|
|
|
|
|
{c.sequentialLessons && <p className="small muted">{t('course.sequential')}</p>}
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</aside>
|
|
|
|
|
|
|
|
|
|
{showBar && <div className="cd-bar" data-hidden={barHidden} aria-hidden={barHidden || undefined} inert={barHidden || undefined}>
|
|
|
|
|
{(mine ? r : c.prices.ETB != null && c.status === 'PUBLISHED') && <div className="cd-bar">
|
|
|
|
|
{mine && r ? <>
|
|
|
|
|
<span className="cd-bar-txt"><strong className="num">{p.pct}%</strong><span>{t('my.lessonsDone', { done: p.done, total: p.total })}</span></span>
|
|
|
|
|
<button className="btn btn-accent" onClick={() => nav(`/${locale}/learn/${c.slug}/${r.lesson.id}`)}>{playLabel}</button>
|
|
|
|
|
@ -680,38 +628,36 @@ function CoursePage({ slug }: { slug?: string }) {
|
|
|
|
|
</>}
|
|
|
|
|
</div>}
|
|
|
|
|
|
|
|
|
|
<section className={`cd-body${mine ? ' is-owner' : ''}`}>
|
|
|
|
|
<div className="cd-tabs" role="tablist">{tabs.map(([k, label]) => <button key={k} role="tab" aria-selected={active === k} onClick={() => setTab(k)}>{label}</button>)}</div>
|
|
|
|
|
{!!text.outcomes?.length && <div className="cd-pane" data-tab="overview" data-active={active === 'overview'}>
|
|
|
|
|
<h2><KitIcon name="brush" size={22} />{t('course.outcomes')}</h2>
|
|
|
|
|
<ul className="cd-learn">{text.outcomes.map((o, k) => <li key={k}><Icon name="check" size={16} />{o}</li>)}</ul>
|
|
|
|
|
<section className="cd-body">
|
|
|
|
|
{pre && !preDone && <div className="banner">{t('course.prereq', { title: ct(pre, locale).title })} <button className="link" onClick={() => nav(`/${locale}/course/${pre.slug}`)}>{t('course.prereqLink', { title: ct(pre, locale).title })}</button></div>}
|
|
|
|
|
<div className="cd-tabs" role="tablist">{tabs.map(([k, label]) => <button key={k} role="tab" aria-selected={tab === k} onClick={() => setTab(k)}>{label}</button>)}</div>
|
|
|
|
|
{tab === 'overview' && <div className="cd-pane">
|
|
|
|
|
{!!text.outcomes?.length && <>
|
|
|
|
|
<h2><KitIcon name="brush" size={22} />{t('course.outcomes')}</h2>
|
|
|
|
|
<ul className="cd-learn">{text.outcomes.map((o, k) => <li key={k}><Icon name="check" size={16} />{o}</li>)}</ul>
|
|
|
|
|
</>}
|
|
|
|
|
{text.description && <p style={{ whiteSpace: 'pre-line' }}>{text.description}</p>}
|
|
|
|
|
{text.audience && <p className="small"><strong>{t('course.audience')}: </strong>{text.audience}</p>}
|
|
|
|
|
</div>}
|
|
|
|
|
<div className="cd-pane cd-content" data-tab="content" data-active={active === 'content'}>
|
|
|
|
|
<h2 className="cd-pane-h">{t('course.content')}</h2>
|
|
|
|
|
{tab === 'content' && <div className="cd-pane cd-content">
|
|
|
|
|
<p className="small muted num">{t('course.lessons', { n: lessons.length })} · {formatDuration(courseDuration(c))}</p>
|
|
|
|
|
{chapters.map((ch, i) => {
|
|
|
|
|
const ls = [...ch.lessons].sort((a, b) => a.sortOrder - b.sortOrder).filter((l) => l.isPublished);
|
|
|
|
|
if (!ls.length) return null;
|
|
|
|
|
const d = ls.filter((l) => isCompleted(me, l.id)).length;
|
|
|
|
|
return (
|
|
|
|
|
<details key={ch.id} className="ch" open={nextChapter ? ch.id === nextChapter : i === 0}>
|
|
|
|
|
<details key={ch.id} className="ch" open={i === 0}>
|
|
|
|
|
<summary><span className="grow"><strong>{tr(ch.translations, locale)?.title}</strong><span className="small muted num">{d}/{ls.length} · {formatDuration(ls.reduce((s, l) => s + l.durationSec, 0))}</span></span><Icon name="down" size={18} /></summary>
|
|
|
|
|
{ls.map((l) => <LessonRow key={l.id} c={c} l={l} />)}
|
|
|
|
|
{quizzes.filter((a) => a.chapterId === ch.id).map((a) => <AssessmentRow key={a.id} c={c} a={a} inline />)}
|
|
|
|
|
</details>
|
|
|
|
|
);
|
|
|
|
|
})}
|
|
|
|
|
{!!finalQuizzes.length && <details className="ch" open>
|
|
|
|
|
<summary><span className="grow"><strong>{t('assess.title')}</strong><span className="small muted num">{finalQuizzes.filter((a) => me?.assessments?.[a.id]?.passed).length}/{finalQuizzes.length}</span></span><Icon name="down" size={18} /></summary>
|
|
|
|
|
{finalQuizzes.map((a) => <AssessmentRow key={a.id} c={c} a={a} />)}
|
|
|
|
|
{!!c.assessments?.length && <details className="ch" open>
|
|
|
|
|
<summary><span className="grow"><strong>{t('assess.title')}</strong><span className="small muted num">{c.assessments.filter((a) => me?.assessments?.[a.id]?.passed).length}/{c.assessments.length}</span></span><Icon name="down" size={18} /></summary>
|
|
|
|
|
{c.assessments.map((a) => <AssessmentRow key={a.id} c={c} a={a} />)}
|
|
|
|
|
</details>}
|
|
|
|
|
</div>
|
|
|
|
|
{(text.description || text.audience) && <div className="cd-pane" data-tab="overview" data-active={active === 'overview'}>
|
|
|
|
|
<h2>{t('course.about')}</h2>
|
|
|
|
|
{text.description && <p style={{ whiteSpace: 'pre-line' }}>{text.description}</p>}
|
|
|
|
|
{text.audience && <p className="small"><strong>{t('course.audience')}: </strong>{text.audience}</p>}
|
|
|
|
|
<p className="cd-updated"><Icon name="calendar" size={14} />{t('course.lastUpdated')} <span className="num">{fmtDate(c.updatedAt)}</span></p>
|
|
|
|
|
</div>}
|
|
|
|
|
{tab === 'instructor' && <div className="cd-pane"><div className="row"><span className="avatar avatar-lg" aria-hidden>{initials(c.instructorName)}</span><div><strong>{c.instructorName}</strong><p className="small muted">{t('course.teaches', { n: teaches })}</p></div></div></div>}
|
|
|
|
|
</section>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
@ -726,9 +672,9 @@ function LessonRow({ c, l, current }: { c: Course; l: Lesson; current?: boolean
|
|
|
|
|
const seen = !done && l.durationSec ? Math.min(100, ((me?.progress?.[l.id]?.maxPositionSec ?? 0) / l.durationSec) * 100) : 0;
|
|
|
|
|
return (
|
|
|
|
|
<button className={`lesson-row${current ? ' is-current' : ''}${done ? ' is-done' : ''}${access.ok ? '' : ' is-locked'}`} aria-current={current ? 'step' : undefined} onClick={() => nav(`/${locale}/learn/${c.slug}/${l.id}`)}>
|
|
|
|
|
<span className="lr-ic" aria-hidden>{current && !done ? <span className="eq"><i /><i /><i /></span> : done ? <Icon name="check" size={14} /> : access.ok ? <Icon name="play" size={12} /> : <Icon name="lock" size={14} />}</span>
|
|
|
|
|
<span className="lr-ic" aria-hidden>{current && !done ? <span className="eq"><i /><i /><i /></span> : done ? <Icon name="check" size={14} /> : access.ok ? <span className="num">{n}</span> : <Icon name="lock" size={14} />}</span>
|
|
|
|
|
<span className="lr-txt">
|
|
|
|
|
<span className="lr-title">{n}. {lessonTitle(l, locale)}</span>
|
|
|
|
|
<span className="lr-title">{current || done || !access.ok ? `${n}. ` : ''}{lessonTitle(l, locale)}</span>
|
|
|
|
|
<span className="lr-meta num">{clock(l.durationSec)}{l.isPreview && !owns(me, c.id) && <span className="lr-tag">{t('course.preview')}</span>}{!access.ok && access.reason === 'COMING_SOON' && <span className="lr-tag">{t('course.comingSoon')}</span>}</span>
|
|
|
|
|
{seen > 0 && <span className="lr-seen" aria-hidden><i style={{ width: `${seen}%` }} /></span>}
|
|
|
|
|
</span>
|
|
|
|
|
@ -739,21 +685,18 @@ function LessonRow({ c, l, current }: { c: Course; l: Lesson; current?: boolean
|
|
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------- assessments
|
|
|
|
|
|
|
|
|
|
function AssessmentRow({ c, a, inline }: { c: Course; a: Assessment; inline?: boolean }) {
|
|
|
|
|
function AssessmentRow({ c, a }: { c: Course; a: Assessment }) {
|
|
|
|
|
const t = useTranslations();
|
|
|
|
|
const { me, locale, nav } = useApp();
|
|
|
|
|
const r = me?.assessments?.[a.id];
|
|
|
|
|
const mine = owns(me, c.id);
|
|
|
|
|
const ch = a.chapterId ? c.chapters.find((x) => x.id === a.chapterId) : undefined;
|
|
|
|
|
const where = inline ? '' : ch ? t('assess.chapter', { chapter: tr(ch.translations, locale)?.title ?? '' }) : t('assess.final');
|
|
|
|
|
const where = ch ? t('assess.chapter', { chapter: tr(ch.translations, locale)?.title ?? '' }) : t('assess.final');
|
|
|
|
|
return (
|
|
|
|
|
<button className={`lesson-row is-quiz${r?.passed ? ' is-done' : ''}${mine ? '' : ' is-locked'}`} onClick={() => nav(`/${locale}/assess/${c.slug}/${a.id}`)}>
|
|
|
|
|
<span className="lr-ic" aria-hidden>{r?.passed ? <Icon name="check" size={14} /> : mine ? <Icon name="quiz" size={14} /> : <Icon name="lock" size={14} />}</span>
|
|
|
|
|
<span className="lr-txt">
|
|
|
|
|
<span className="lr-title">{tr(a.translations, locale)?.title}</span>
|
|
|
|
|
<span className="lr-meta num">{where && <>{where} · </>}{t('assess.questions', { n: a.questions.length })}
|
|
|
|
|
{r && <span className={`lr-tag ${r.passed ? 'quiz-ok' : 'quiz-todo'}`}>{r.passed ? t('assess.passed') : t('assess.notPassed')} · {t('assess.best', { pct: r.bestPct })}</span>}</span>
|
|
|
|
|
</span>
|
|
|
|
|
<button className="lesson-row" onClick={() => nav(`/${locale}/assess/${c.slug}/${a.id}`)}>
|
|
|
|
|
<span className={`ic ${r?.passed ? 'done' : ''}`}>{r?.passed ? <Icon name="check" size={14} /> : owns(me, c.id) ? <Icon name="quiz" size={14} /> : <Icon name="lock" size={14} />}</span>
|
|
|
|
|
<span className="grow"><span style={{ display: 'block', fontWeight: 700 }}>{tr(a.translations, locale)?.title}</span>
|
|
|
|
|
<span className="small muted num">{where} · {t('assess.questions', { n: a.questions.length })}</span>
|
|
|
|
|
{r && <span className={`small num ${r.passed ? 'quiz-ok' : 'quiz-todo'}`}>{r.passed ? t('assess.passed') : t('assess.notPassed')} · {t('assess.best', { pct: r.bestPct })}</span>}</span>
|
|
|
|
|
<Icon name="chevron" size={16} />
|
|
|
|
|
</button>
|
|
|
|
|
);
|
|
|
|
|
@ -848,33 +791,30 @@ function AssessmentPage({ slug, id }: { slug?: string; id?: string }) {
|
|
|
|
|
function Player({ slug, lessonId }: { slug?: string; lessonId?: string }) {
|
|
|
|
|
const t = useTranslations();
|
|
|
|
|
const { courses, me, locale, nav, catalogLoaded, signedIn, viewer } = useApp();
|
|
|
|
|
const sheet = useRef<HTMLDialogElement>(null);
|
|
|
|
|
useEffect(() => { sheet.current?.close(); }, [lessonId]); // picking a lesson in the sheet closes it
|
|
|
|
|
const c = courses.find((x) => x.slug === slug);
|
|
|
|
|
const lessons = c ? publishedLessons(c) : [];
|
|
|
|
|
const lesson = lessons.find((l) => l.id === lessonId);
|
|
|
|
|
if (!catalogLoaded) return <Skeleton h={320} />;
|
|
|
|
|
if (!c || !lesson || !isStudentVisible(c, me)) return <Empty action={<button className="btn" onClick={() => nav(`/${locale}/courses`)}>{t('catalog.title')}</button>}>{t('course.notFound')}</Empty>;
|
|
|
|
|
const access = lessonAccess(c, lesson, signedIn ? me : null, courses);
|
|
|
|
|
const p = courseProgress(c, me);
|
|
|
|
|
const idx = lessons.indexOf(lesson);
|
|
|
|
|
const next = lessons[idx + 1];
|
|
|
|
|
const notes = tr(lesson.translations, locale)?.description;
|
|
|
|
|
const chapter = c.chapters.find((ch) => ch.lessons.some((l) => l.id === lesson.id));
|
|
|
|
|
// L2: the video comes first; where you are (course, chapter, lesson) sits right under it
|
|
|
|
|
const head = (
|
|
|
|
|
<div className="p-head">
|
|
|
|
|
<p className="p-crumb">
|
|
|
|
|
<button onClick={() => nav(`/${locale}/course/${c.slug}`)} aria-label={`${t('player.back')}: ${ct(c, locale).title}`}><Icon name="back" size={14} />{ct(c, locale).title}</button>
|
|
|
|
|
{chapter && <span>{tr(chapter.translations, locale)?.title}</span>}
|
|
|
|
|
</p>
|
|
|
|
|
<h1>{idx + 1}. {lessonTitle(lesson, locale)}</h1>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
return (
|
|
|
|
|
<div className="stack">
|
|
|
|
|
<div className="row-between">
|
|
|
|
|
<button className="btn btn-quiet" onClick={() => nav(`/${locale}/course/${c.slug}`)}><Icon name="back" size={16} />{t('player.back')}</button>
|
|
|
|
|
<span className="small muted">{ct(c, locale).title}</span>
|
|
|
|
|
</div>
|
|
|
|
|
<div className="p-wrap">
|
|
|
|
|
<div className="stack p-main">
|
|
|
|
|
{access.ok ? <VideoPanel key={lesson.id} c={c} lesson={lesson} next={next} head={head} /> : <>
|
|
|
|
|
<div className="stack">
|
|
|
|
|
<div className="stack-sm">
|
|
|
|
|
<span className="small muted">{tr(chapter?.translations, locale)?.title}</span>
|
|
|
|
|
<h1 style={{ fontSize: 'var(--fs-xl)' }}>{idx + 1}. {lessonTitle(lesson, locale)}</h1>
|
|
|
|
|
</div>
|
|
|
|
|
{access.ok ? <VideoPanel key={lesson.id} c={c} lesson={lesson} next={next} /> : (
|
|
|
|
|
<div className="screen"><div className="sim">
|
|
|
|
|
<Icon name="lock" size={36} />
|
|
|
|
|
<p>{t(`player.${access.reason}`)}</p>
|
|
|
|
|
@ -883,63 +823,44 @@ function Player({ slug, lessonId }: { slug?: string; lessonId?: string }) {
|
|
|
|
|
{access.reason === 'PREREQUISITE_REQUIRED' && <button className="btn btn-accent" onClick={() => { const pre = courses.find((x) => x.id === c.prerequisiteCourseId); if (pre) nav(`/${locale}/course/${pre.slug}`); }}>{t('course.prereqLink', { title: ct(courses.find((x) => x.id === c.prerequisiteCourseId) ?? c, locale).title })}</button>}
|
|
|
|
|
{access.reason === 'ACCOUNT_DEACTIVATED' && <button className="btn btn-accent" onClick={() => nav(`/${locale}/help`)}>{t('nav.help')}</button>}
|
|
|
|
|
</div></div>
|
|
|
|
|
{head}
|
|
|
|
|
</>}
|
|
|
|
|
{/* L5: only real lesson notes; no card standing in with the course blurb */}
|
|
|
|
|
{notes && <div className="card stack-sm">
|
|
|
|
|
)}
|
|
|
|
|
<div className="card stack-sm">
|
|
|
|
|
<h2 style={{ fontSize: 'var(--fs-lg)' }}>{t('player.notes')}</h2>
|
|
|
|
|
<p style={{ whiteSpace: 'pre-line', color: 'var(--ink-2)' }}>{notes}</p>
|
|
|
|
|
</div>}
|
|
|
|
|
<p style={{ whiteSpace: 'pre-line', color: 'var(--ink-2)' }}>{notes || ct(c, locale).subtitle || ct(c, locale).description}</p>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
<aside className="card p-side p-side-order" aria-label={t('player.contents')}><CourseContents c={c} lesson={lesson} /></aside>
|
|
|
|
|
<aside className="card p-side p-side-order" aria-label={t('player.contents')}>
|
|
|
|
|
<div className="ps-head">
|
|
|
|
|
{owns(me, c.id) && <Ring pct={p.pct} size={52} />}
|
|
|
|
|
<div className="ps-head-txt"><span className="ps-kicker">{t('course.content')}</span><strong>{ct(c, locale).title}</strong>
|
|
|
|
|
{owns(me, c.id) && <span className="small muted num">{t('player.progress', { done: p.done, total: p.total })}</span>}</div>
|
|
|
|
|
</div>
|
|
|
|
|
{[...c.chapters].sort((a, b) => a.sortOrder - b.sortOrder).map((ch, ci) => {
|
|
|
|
|
const ls = [...ch.lessons].sort((a, b) => a.sortOrder - b.sortOrder).filter((l) => l.isPublished);
|
|
|
|
|
if (!ls.length) return null;
|
|
|
|
|
const doneN = ls.filter((l) => isCompleted(me, l.id)).length;
|
|
|
|
|
return <details key={ch.id} className={`ps-ch${doneN === ls.length ? ' is-done' : ''}`} open={ls.some((l) => l.id === lesson.id) || undefined}>
|
|
|
|
|
<summary>
|
|
|
|
|
<span className="ps-ch-n num">{doneN === ls.length ? <Icon name="check" size={14} /> : String(ci + 1).padStart(2, '0')}</span>
|
|
|
|
|
<span className="ps-ch-txt"><strong>{tr(ch.translations, locale)?.title}</strong><span className="small muted num">{doneN}/{ls.length} · {clock(ls.reduce((a, l) => a + l.durationSec, 0))}</span></span>
|
|
|
|
|
<Icon name="down" size={16} />
|
|
|
|
|
</summary>
|
|
|
|
|
<div className="ps-ch-list">{ls.map((l) => <LessonRow key={l.id} c={c} l={l} current={l.id === lesson.id} />)}</div>
|
|
|
|
|
</details>;
|
|
|
|
|
})}
|
|
|
|
|
</aside>
|
|
|
|
|
</div>
|
|
|
|
|
{viewer && !viewer.id && <p className="small muted">{t('auth.noIdentity')}</p>}
|
|
|
|
|
<nav className="l-bar" aria-label={t('player.contents')}>
|
|
|
|
|
<button disabled={idx === 0} onClick={() => nav(`/${locale}/learn/${c.slug}/${lessons[idx - 1].id}`)}><Icon name="back" size={18} />{t('player.prev')}</button>
|
|
|
|
|
<button aria-haspopup="dialog" onClick={() => sheet.current?.showModal()}><Icon name="list" size={18} /><span className="num">{idx + 1} / {lessons.length}</span></button>
|
|
|
|
|
<button className="l-next" disabled={!next} onClick={() => nav(`/${locale}/learn/${c.slug}/${next.id}`)}>{t('player.nextShort')}<Icon name="chevron" size={18} /></button>
|
|
|
|
|
<button onClick={() => document.querySelector('.p-side')?.scrollIntoView({ behavior: 'smooth' })}><Icon name="list" size={18} /><span className="num">{idx + 1} / {lessons.length}</span></button>
|
|
|
|
|
<button className="l-next" disabled={!next} onClick={() => nav(`/${locale}/learn/${c.slug}/${next.id}`)}>{t('player.next')}<Icon name="chevron" size={18} /></button>
|
|
|
|
|
</nav>
|
|
|
|
|
{/* L6: on phones and tablets the lesson list slides up over the video instead of scrolling the page away from it */}
|
|
|
|
|
<dialog ref={sheet} className="lsheet" aria-label={t('player.contents')} onClick={(e) => { if (e.target === sheet.current) sheet.current?.close(); }}>
|
|
|
|
|
<div className="lsheet-in">
|
|
|
|
|
<div className="lsheet-top"><span className="lsheet-grip" aria-hidden /><button className="icon-btn" aria-label={t('common.close')} onClick={() => sheet.current?.close()}><Icon name="x" size={20} /></button></div>
|
|
|
|
|
<CourseContents c={c} lesson={lesson} />
|
|
|
|
|
</div>
|
|
|
|
|
</dialog>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// The course's chapters and lessons with progress: the player's sidebar on desktop and its lesson sheet on phones.
|
|
|
|
|
function CourseContents({ c, lesson }: { c: Course; lesson: Lesson }) {
|
|
|
|
|
const t = useTranslations();
|
|
|
|
|
const { me, locale } = useApp();
|
|
|
|
|
const p = courseProgress(c, me);
|
|
|
|
|
return <>
|
|
|
|
|
<div className="ps-head">
|
|
|
|
|
{owns(me, c.id) && <Ring pct={p.pct} size={52} />}
|
|
|
|
|
<div className="ps-head-txt"><span className="ps-kicker">{t('course.content')}</span><strong>{ct(c, locale).title}</strong>
|
|
|
|
|
{owns(me, c.id) && <span className="small muted num">{t('player.progress', { done: p.done, total: p.total })}</span>}</div>
|
|
|
|
|
</div>
|
|
|
|
|
{[...c.chapters].sort((a, b) => a.sortOrder - b.sortOrder).map((ch, ci) => {
|
|
|
|
|
const ls = [...ch.lessons].sort((a, b) => a.sortOrder - b.sortOrder).filter((l) => l.isPublished);
|
|
|
|
|
if (!ls.length) return null;
|
|
|
|
|
const doneN = ls.filter((l) => isCompleted(me, l.id)).length;
|
|
|
|
|
return <details key={ch.id} className={`ps-ch${doneN === ls.length ? ' is-done' : ''}`} open={ls.some((l) => l.id === lesson.id) || undefined}>
|
|
|
|
|
<summary>
|
|
|
|
|
<span className="ps-ch-n num">{doneN === ls.length ? <Icon name="check" size={14} /> : String(ci + 1).padStart(2, '0')}</span>
|
|
|
|
|
<span className="ps-ch-txt"><strong>{tr(ch.translations, locale)?.title}</strong><span className="small muted num">{doneN}/{ls.length} · {clock(ls.reduce((a, l) => a + l.durationSec, 0))}</span></span>
|
|
|
|
|
<Icon name="down" size={16} />
|
|
|
|
|
</summary>
|
|
|
|
|
<div className="ps-ch-list">{ls.map((l) => <LessonRow key={l.id} c={c} l={l} current={l.id === lesson.id} />)}</div>
|
|
|
|
|
</details>;
|
|
|
|
|
})}
|
|
|
|
|
</>;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const AUTO_NEXT_SEC = 5;
|
|
|
|
|
|
|
|
|
|
function VideoPanel({ c, lesson, next, head }: { c: Course; lesson: Lesson; next?: Lesson; head?: ReactNode }) {
|
|
|
|
|
function VideoPanel({ c, lesson, next }: { c: Course; lesson: Lesson; next?: Lesson }) {
|
|
|
|
|
const t = useTranslations();
|
|
|
|
|
const { me, locale, nav, ds, write, signedIn, viewer } = useApp();
|
|
|
|
|
const vimeo = !lesson.videoAssetId; // no upload yet: play the Vimeo placeholder instead
|
|
|
|
|
@ -953,9 +874,6 @@ function VideoPanel({ c, lesson, next, head }: { c: Course; lesson: Lesson; next
|
|
|
|
|
const [saver, setSaver] = useState<boolean>(() => !!conn && (conn.saveData || /2g|3g/.test(conn.effectiveType ?? '')));
|
|
|
|
|
const [quality, setQuality] = useState('auto');
|
|
|
|
|
const [justDone, setJustDone] = useState(false);
|
|
|
|
|
// L4: when a lesson ends, "up next" appears over the video and plays it after a short count the student can cancel
|
|
|
|
|
const [ended, setEnded] = useState(false);
|
|
|
|
|
const [auto, setAuto] = useState<number | null>(null);
|
|
|
|
|
const videoRef = useRef<HTMLVideoElement>(null);
|
|
|
|
|
const frameRef = useRef<HTMLIFrameElement>(null);
|
|
|
|
|
const screenRef = useRef<HTMLDivElement>(null);
|
|
|
|
|
@ -989,9 +907,8 @@ function VideoPanel({ c, lesson, next, head }: { c: Course; lesson: Lesson; next
|
|
|
|
|
let m: any; try { m = typeof e.data === 'string' ? JSON.parse(e.data) : e.data; } catch { return; }
|
|
|
|
|
if (m.event === 'ready') vlisten();
|
|
|
|
|
else if (m.event === 'timeupdate') { setPos(m.data.seconds); if (m.data.duration) setVdur(m.data.duration); }
|
|
|
|
|
else if (m.event === 'play') { setPlaying(true); setEnded(false); setAuto(null); }
|
|
|
|
|
else if (m.event === 'pause') setPlaying(false);
|
|
|
|
|
else if (m.event === 'ended') { setPlaying(false); setEnded(true); }
|
|
|
|
|
else if (m.event === 'play') setPlaying(true);
|
|
|
|
|
else if (m.event === 'pause' || m.event === 'ended') setPlaying(false);
|
|
|
|
|
else if (m.method === 'getDuration' && m.value) setVdur(m.value);
|
|
|
|
|
};
|
|
|
|
|
addEventListener('message', on);
|
|
|
|
|
@ -1006,14 +923,6 @@ function VideoPanel({ c, lesson, next, head }: { c: Course; lesson: Lesson; next
|
|
|
|
|
}, [heartbeat]);
|
|
|
|
|
useEffect(() => { const v = videoRef.current; if (v) v.playbackRate = rate; }, [rate]);
|
|
|
|
|
useEffect(() => { if (vimeo && rate !== 1) vcall('setPlaybackRate', rate); }, [rate]);
|
|
|
|
|
const goNext = () => { if (next) nav(`/${locale}/learn/${c.slug}/${next.id}`); };
|
|
|
|
|
useEffect(() => { if (ended && next) setAuto(AUTO_NEXT_SEC); }, [ended, next]);
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
if (auto == null) return;
|
|
|
|
|
if (auto <= 0) { goNext(); return; }
|
|
|
|
|
const id = setTimeout(() => setAuto((a) => (a == null ? null : a - 1)), 1000);
|
|
|
|
|
return () => clearTimeout(id);
|
|
|
|
|
}, [auto]);
|
|
|
|
|
|
|
|
|
|
const toggle = () => {
|
|
|
|
|
const v = videoRef.current;
|
|
|
|
|
@ -1024,7 +933,6 @@ function VideoPanel({ c, lesson, next, head }: { c: Course; lesson: Lesson; next
|
|
|
|
|
const full = () => { screenRef.current?.requestFullscreen?.().catch(() => { /* not allowed in this frame */ }); };
|
|
|
|
|
const onKey = (e: React.KeyboardEvent) => {
|
|
|
|
|
if ((e.target as HTMLElement).tagName === 'SELECT' || (e.target as HTMLElement).tagName === 'INPUT') return;
|
|
|
|
|
if (e.key === 'Escape' && auto != null) { setAuto(null); return; }
|
|
|
|
|
if (e.key === ' ') { e.preventDefault(); toggle(); } else if (e.key === 'ArrowLeft') seek(pos - 10); else if (e.key === 'ArrowRight') seek(pos + 10); else if (e.key === 'f') full(); else if (e.key === 'm' && videoRef.current) videoRef.current.muted = !videoRef.current.muted;
|
|
|
|
|
};
|
|
|
|
|
const mark = (me?.phone || me?.email || viewer?.name || 'student').replace(/^(.{3}).*(.{2})$/, '$1•••$2');
|
|
|
|
|
@ -1036,20 +944,11 @@ function VideoPanel({ c, lesson, next, head }: { c: Course; lesson: Lesson; next
|
|
|
|
|
{lesson.videoAssetId ? (
|
|
|
|
|
<video ref={videoRef} src={ds.assetUrl(lesson.videoAssetId)} playsInline preload="metadata"
|
|
|
|
|
onLoadedMetadata={(e) => { if (pos) e.currentTarget.currentTime = pos; }}
|
|
|
|
|
onTimeUpdate={(e) => setPos(e.currentTarget.currentTime)} onPlay={() => { setPlaying(true); setEnded(false); setAuto(null); }} onPause={() => setPlaying(false)} onEnded={() => { setPlaying(false); setEnded(true); }} />
|
|
|
|
|
onTimeUpdate={(e) => setPos(e.currentTarget.currentTime)} onPlay={() => setPlaying(true)} onPause={() => setPlaying(false)} onEnded={() => setPlaying(false)} />
|
|
|
|
|
) : (
|
|
|
|
|
<iframe ref={frameRef} src={VIMEO_PLACEHOLDER} onLoad={vlisten} title={lessonTitle(lesson, locale)} allow="autoplay; fullscreen; picture-in-picture" allowFullScreen />
|
|
|
|
|
)}
|
|
|
|
|
{canSave && <span className="wm" aria-hidden>{mark}</span>}
|
|
|
|
|
{auto != null && next && <div className="p-upnext" role="status">
|
|
|
|
|
<span className="p-upnext-k">{t('player.upNext')}</span>
|
|
|
|
|
<strong>{lessonNumber(c, next.id)}. {lessonTitle(next, locale)}</strong>
|
|
|
|
|
<span className="p-upnext-n num" aria-hidden><svg viewBox="0 0 24 24" width="18" height="18"><circle cx="12" cy="12" r="10" /></svg>{t('player.autoNext', { n: auto })}</span>
|
|
|
|
|
<div className="p-upnext-go">
|
|
|
|
|
<button className="btn btn-accent" onClick={goNext}><Icon name="play" size={14} />{t('player.playNow')}</button>
|
|
|
|
|
<button className="btn btn-quiet" onClick={() => setAuto(null)}>{t('common.cancel')}</button>
|
|
|
|
|
</div>
|
|
|
|
|
</div>}
|
|
|
|
|
{!vimeo && <div className="controls">
|
|
|
|
|
<input type="range" min={0} max={dur} step={1} value={Math.floor(pos)} onChange={(e) => seek(Number(e.target.value))} aria-label={`${clock(pos)} / ${clock(dur)}`} />
|
|
|
|
|
<div className="row">
|
|
|
|
|
@ -1069,8 +968,7 @@ function VideoPanel({ c, lesson, next, head }: { c: Course; lesson: Lesson; next
|
|
|
|
|
</div>
|
|
|
|
|
</div>}
|
|
|
|
|
</div>
|
|
|
|
|
{head}
|
|
|
|
|
{vimeo && <p className="small muted">{t('player.demoVideo')}{canSave && !done && <> · <button className="link" onClick={() => { setPos(dur); posRef.current = dur; heartbeat(); setEnded(true); }}>{t('player.markWatched')}</button></>}</p>}
|
|
|
|
|
{vimeo && <p className="small muted">{t('player.demoVideo')}{canSave && !done && <> · <button className="link" onClick={() => { setPos(dur); posRef.current = dur; heartbeat(); }}>{t('player.markWatched')}</button></>}</p>}
|
|
|
|
|
{done && pct === 100 && (
|
|
|
|
|
<div className="course-done" role="status">
|
|
|
|
|
<div className="confetti" aria-hidden>{Array.from({ length: 18 }, (_, k) => <i key={k} style={{ '--k': k } as React.CSSProperties} />)}</div>
|
|
|
|
|
@ -1083,7 +981,7 @@ function VideoPanel({ c, lesson, next, head }: { c: Course; lesson: Lesson; next
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
{done && pct < 100 && auto == null && (
|
|
|
|
|
{done && pct < 100 && (
|
|
|
|
|
<div className="lesson-done" role="status">
|
|
|
|
|
<span className="ld-check" aria-hidden><svg viewBox="0 0 24 24" width="22" height="22"><path d="M5 12.5l4.5 4.5L19 7" /></svg></span>
|
|
|
|
|
<span className="ld-txt"><strong>{t('player.completed')}</strong><span className="small muted num">{t('player.courseProgress', { pct })}</span></span>
|
|
|
|
|
|