feat(course): course page polish P1–P5
- P1: sticky buy/continue bar hides while the buy card's button is on screen - P2: price, preview and "lifetime" shown once; button reads "Buy course" - P3: phones drop the tabs and stack overview, curriculum and about in one scroll - P4: owners land on the curriculum with the next lesson's chapter open and an "Up next" card instead of the sales list - P5: instructor tab removed; course count moves to the creator row - i18n: course.about in all locales (om/ti drafts)
This commit is contained in:
parent
754cebeeff
commit
a94514eb6b
|
|
@ -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,27 @@ 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 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">
|
||||
|
|
@ -583,13 +599,12 @@ function CoursePage({ slug }: { slug?: string }) {
|
|||
<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>}
|
||||
</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-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-updated"><Icon name="calendar" size={14} />{t('course.lastUpdated')} <span className="num">{fmtDate(c.updatedAt)}</span></span>
|
||||
</div>
|
||||
</section>
|
||||
|
|
@ -600,25 +615,24 @@ 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>}
|
||||
{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><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('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>
|
||||
{c.prices.ETB != null && <div className="cd-price"><span className="num">{formatMoney(c.prices.ETB, 'ETB')}</span><span>{t('checkout.lifetime')}</span></div>}
|
||||
<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>
|
||||
<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 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,25 +642,22 @@ function CoursePage({ slug }: { slug?: string }) {
|
|||
</>}
|
||||
</div>}
|
||||
|
||||
<section className="cd-body">
|
||||
<section className={`cd-body${mine ? ' is-owner' : ''}`}>
|
||||
{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 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} />)}
|
||||
</details>
|
||||
|
|
@ -656,8 +667,12 @@ function CoursePage({ slug }: { slug?: string }) {
|
|||
<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>}
|
||||
</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>
|
||||
);
|
||||
|
|
|
|||
|
|
@ -905,6 +905,29 @@ fieldset[disabled] .quiz-opt { cursor: default; }
|
|||
.cd-bar .btn { border-radius: 999px; min-height: 48px; padding-inline: 22px; }
|
||||
@media (min-width: 1024px) { .cd-bar { display: none; } }
|
||||
|
||||
/* ---------- course page polish 2026-10-26 (P1–P5) ---------- */
|
||||
/* P1: the bar repeats the buy card's button, so it steps aside while that button is on screen */
|
||||
.cd-bar { transition: transform 220ms var(--ease-out), opacity 220ms var(--ease-out); }
|
||||
.cd-bar[data-hidden="true"] { transform: translateY(100%); opacity: 0; pointer-events: none; }
|
||||
/* P2: price once, with its terms underneath */
|
||||
.cd-price { flex-direction: column; align-items: flex-start; gap: 2px; }
|
||||
.cd-price > span:last-child { font-weight: 600; color: var(--ink-3); }
|
||||
/* P4: owners see the next lesson instead of the sales list */
|
||||
.cd-next { margin: 0; display: flex; flex-direction: column; gap: 2px; padding: 12px 14px; border-radius: 14px; background: var(--mist); }
|
||||
.cd-next > span:first-child { font-size: 12px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--ink-3); }
|
||||
.cd-next > .num { font-size: var(--fs-sm); color: var(--ink-3); }
|
||||
/* P5: what the instructor tab said, in the creator row */
|
||||
.cd-by-n { font-size: 12px; color: var(--ink-3); }
|
||||
/* P3: desktop keeps tabs (one section at a time); phones drop them and stack every section in one scroll */
|
||||
.cd-pane-h { margin-bottom: 4px; }
|
||||
@media (min-width: 1024px) { .cd-pane[data-active="false"], .cd-pane-h { display: none; } }
|
||||
@media (max-width: 1023px) {
|
||||
.cd-tabs { display: none; }
|
||||
.cd-body { gap: 0; }
|
||||
.cd-body > .banner { order: -2; }
|
||||
.cd-body.is-owner > .cd-content { order: -1; } /* P4: owners land on the curriculum */
|
||||
}
|
||||
|
||||
/* help: big ask, three contact doors, FAQ beside the report form */
|
||||
.help { display: flex; flex-direction: column; gap: clamp(28px, 4vw, 48px); }
|
||||
.help-hero { display: flex; flex-direction: column; gap: 10px; padding-top: clamp(8px, 3vw, 32px); }
|
||||
|
|
|
|||
|
|
@ -151,6 +151,7 @@
|
|||
"watchAgain": "እንደገና ይመልከቱ",
|
||||
"tabOverview": "አጠቃላይ እይታ",
|
||||
"tabInstructor": "አሠልጣኝ",
|
||||
"about": "ስለ ኮርሱ",
|
||||
"summary": "ማጠቃለያ",
|
||||
"duration": "ጠቅላላ ርዝመት",
|
||||
"language": "ቋንቋ",
|
||||
|
|
|
|||
|
|
@ -151,6 +151,7 @@
|
|||
"watchAgain": "Watch again",
|
||||
"tabOverview": "Overview",
|
||||
"tabInstructor": "Instructor",
|
||||
"about": "About this course",
|
||||
"summary": "Summary",
|
||||
"duration": "Total duration",
|
||||
"language": "Language",
|
||||
|
|
|
|||
|
|
@ -151,6 +151,7 @@
|
|||
"watchAgain": "Irra deebi'ii ilaali",
|
||||
"tabOverview": "Overview",
|
||||
"tabInstructor": "Instructor",
|
||||
"about": "Waa'ee koorsii kanaa",
|
||||
"summary": "Summary",
|
||||
"duration": "Total duration",
|
||||
"language": "Language",
|
||||
|
|
|
|||
|
|
@ -151,6 +151,7 @@
|
|||
"watchAgain": "እንደገና ርአ",
|
||||
"tabOverview": "Overview",
|
||||
"tabInstructor": "Instructor",
|
||||
"about": "ብዛዕባ እዚ ኮርስ",
|
||||
"summary": "Summary",
|
||||
"duration": "Total duration",
|
||||
"language": "Language",
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user