|
|
|
|
@ -532,9 +532,19 @@ 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('overview');
|
|
|
|
|
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 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);
|
|
|
|
|
@ -549,21 +559,29 @@ 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);
|
|
|
|
|
const play = mine && r ? `/${locale}/learn/${c.slug}/${r.lesson.id}` : preview ? `/${locale}/learn/${c.slug}/${preview.id}` : null;
|
|
|
|
|
// 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 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));
|
|
|
|
|
const tabs: [string, string][] = [['overview', t('course.tabOverview')], ['content', t('course.content')], ['instructor', t('course.tabInstructor')]];
|
|
|
|
|
// 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 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">
|
|
|
|
|
@ -576,21 +594,20 @@ function CoursePage({ slug }: { slug?: string }) {
|
|
|
|
|
</nav>
|
|
|
|
|
<span className="row" style={{ gap: 6 }}>
|
|
|
|
|
{c.status === 'ARCHIVED' && <StatusPill status="ARCHIVED" />}
|
|
|
|
|
{mine && <span className="cd-chip"><Icon name="check" size={12} />{done ? t('course.completed') : t('course.owned')}</span>}
|
|
|
|
|
<button className="cd-share" onClick={share} aria-label={t('course.share')}><Icon name="share" size={16} /></button>
|
|
|
|
|
</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>
|
|
|
|
|
{previews > 0 && <span className="muted small">{t('course.previewLessons', { n: previews })}</span>}
|
|
|
|
|
{mine && <span className="cd-pill cd-pill-own"><Icon name="check" size={14} /><strong>{done ? t('course.completed') : t('course.owned')}</strong></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>
|
|
|
|
|
<span className="cd-updated"><Icon name="calendar" size={14} />{t('course.lastUpdated')} <span className="num">{fmtDate(c.updatedAt)}</span></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>
|
|
|
|
|
</div>
|
|
|
|
|
</section>
|
|
|
|
|
|
|
|
|
|
@ -600,25 +617,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>
|
|
|
|
|
{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>}
|
|
|
|
|
{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>}
|
|
|
|
|
</> : <>
|
|
|
|
|
{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>
|
|
|
|
|
{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>}
|
|
|
|
|
</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>
|
|
|
|
|
|
|
|
|
|
{(mine ? r : c.prices.ETB != null && c.status === 'PUBLISHED') && <div className="cd-bar">
|
|
|
|
|
{showBar && <div className="cd-bar" data-hidden={barHidden} aria-hidden={barHidden || undefined} inert={barHidden || undefined}>
|
|
|
|
|
{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>
|
|
|
|
|
@ -628,36 +645,38 @@ function CoursePage({ slug }: { slug?: string }) {
|
|
|
|
|
</>}
|
|
|
|
|
</div>}
|
|
|
|
|
|
|
|
|
|
<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>}
|
|
|
|
|
<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>
|
|
|
|
|
</div>}
|
|
|
|
|
{tab === 'content' && <div className="cd-pane cd-content">
|
|
|
|
|
<div className="cd-pane cd-content" data-tab="content" data-active={active === 'content'}>
|
|
|
|
|
<h2 className="cd-pane-h">{t('course.content')}</h2>
|
|
|
|
|
<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={i === 0}>
|
|
|
|
|
<details key={ch.id} className="ch" open={nextChapter ? ch.id === nextChapter : 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>
|
|
|
|
|
);
|
|
|
|
|
})}
|
|
|
|
|
{!!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} />)}
|
|
|
|
|
{!!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} />)}
|
|
|
|
|
</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>
|
|
|
|
|
);
|
|
|
|
|
@ -672,9 +691,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 ? <span className="num">{n}</span> : <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 ? <Icon name="play" size={12} /> : <Icon name="lock" size={14} />}</span>
|
|
|
|
|
<span className="lr-txt">
|
|
|
|
|
<span className="lr-title">{current || done || !access.ok ? `${n}. ` : ''}{lessonTitle(l, locale)}</span>
|
|
|
|
|
<span className="lr-title">{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>
|
|
|
|
|
@ -685,18 +704,21 @@ function LessonRow({ c, l, current }: { c: Course; l: Lesson; current?: boolean
|
|
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------- assessments
|
|
|
|
|
|
|
|
|
|
function AssessmentRow({ c, a }: { c: Course; a: Assessment }) {
|
|
|
|
|
function AssessmentRow({ c, a, inline }: { c: Course; a: Assessment; inline?: boolean }) {
|
|
|
|
|
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 = ch ? t('assess.chapter', { chapter: tr(ch.translations, locale)?.title ?? '' }) : t('assess.final');
|
|
|
|
|
const where = inline ? '' : ch ? t('assess.chapter', { chapter: tr(ch.translations, locale)?.title ?? '' }) : t('assess.final');
|
|
|
|
|
return (
|
|
|
|
|
<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>
|
|
|
|
|
<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>
|
|
|
|
|
<Icon name="chevron" size={16} />
|
|
|
|
|
</button>
|
|
|
|
|
);
|
|
|
|
|
|