diff --git a/src/components/Sommaire.astro b/src/components/Sommaire.astro index ca0713c..7f2c76b 100644 --- a/src/components/Sommaire.astro +++ b/src/components/Sommaire.astro @@ -1,7 +1,7 @@ --- import type { BookModule } from '../lib/moodle'; -interface Props { slug: string; modules: BookModule[]; } -const { slug, modules } = Astro.props; +interface Props { slug: string; modules: BookModule[]; readSet?: Set; } +const { slug, modules, readSet } = Astro.props; ---
{modules.map((m, mi) => ( @@ -12,8 +12,17 @@ const { slug, modules } = Astro.props;
  • - {ci + 1} - {ch.title} + {readSet?.has(`${mi + 1}-${ci + 1}`) ? ( + <> + + {ch.title} + + ) : ( + <> + {ci + 1} + {ch.title} + + )}
  • ))} diff --git a/src/pages/cours/[slug]/index.astro b/src/pages/cours/[slug]/index.astro index c45d292..61e22ed 100644 --- a/src/pages/cours/[slug]/index.astro +++ b/src/pages/cours/[slug]/index.astro @@ -26,14 +26,22 @@ if (user) { if (reads.some((r) => !r.moodle_synced)) syncToMoodle({ sub: user.sub, email: user.email, name: user.name }, course.slug).catch(() => {}); } +const readSet = new Set(reads.map((r) => `${r.module_n}-${r.chapitre_n}`)); const hubData = { slug: course.slug, modules: modules.map((m, mi) => ({ title: m.title, - chapters: m.chapters.map((ch, ci) => ({ title: ch.title, url: `/cours/${course.slug}/module-${mi + 1}/chapitre-${ci + 1}` })), + chapters: m.chapters.map((ch, ci) => ({ + title: ch.title, + url: `/cours/${course.slug}/module-${mi + 1}/chapitre-${ci + 1}`, + read: readSet.has(`${mi + 1}-${ci + 1}`), + })), })), }; +const total = modules.reduce((s, m) => s + m.chapters.length, 0); +const nbLus = hubData.modules.reduce((s, m) => s + m.chapters.filter((c) => c.read).length, 0); +const pct = total ? Math.round((nbLus / total) * 100) : 0; ---