SPB Git

Repository Public

ResumeCard.tsx 1.6 KB 30 lines tsx

1"use client";2import Link from "next/link";3import { Icon } from "@/components/ui/Icon";4import { useAtlas, useHydrated } from "@/lib/client/store";5import { formatTime, watchPath } from "@/modules/content-schema/urls";6import { capsuleKey } from "@/modules/learning-engine/state";78interface S { id: string; slug: string; title: string; number: number; capsules: { id: string; title: string }[] }910/** « Reprendre » : the most recently played, unfinished capsule found in the browser’s local state. */11export function ResumeCard({ sessions }: { sessions: S[] }) {12  const state = useAtlas();13  const hydrated = useHydrated();14  if (!hydrated) return null;15  let best: { s: S; c: S["capsules"][number]; position: number; updatedAt: string } | null = null;16  for (const s of sessions) for (const c of s.capsules) {17    const p = state.capsules[capsuleKey(s.id, c.id)];18    if (p && !p.completed && p.position >= 5 && (!best || p.updatedAt > best.updatedAt)) best = { s, c, position: p.position, updatedAt: p.updatedAt };19  }20  if (!best) return null;21  return (22    <div className="border-b border-line bg-blue-soft" data-testid="resume-card">23      <div className="shell flex flex-wrap items-center justify-between gap-4 py-4">24        <p className="text-[0.97rem]"><span className="eyebrow mr-3 !text-blue">Reprendre</span>Séance {best.s.number} — {best.c.title}, à {formatTime(best.position)}</p>25        <Link href={watchPath(best.s.slug, { capsule: best.c.id })} className="btn btn-accent btn-sm"><Icon name="play" size={16} />Reprendre la lecture</Link>26      </div>27    </div>28  );29}30
Files main
Menu

Theme