From e9f44635d1f37a4b6616aca8993d57073db2f269 Mon Sep 17 00:00:00 2001 From: im-rk Date: Sat, 3 Oct 2026 10:05:27 +0530 Subject: [PATCH 1/3] feat(concepts): concept map and compare reel, the same idea from every teacher --- src/app/api/concepts/[key]/route.ts | 28 +++++++++++ src/app/api/concepts/route.ts | 11 +++++ src/app/concepts/[key]/page.tsx | 58 ++++++++++++++++++++++ src/app/concepts/page.tsx | 74 +++++++++++++++++++++++++++++ src/app/layout.tsx | 3 ++ src/app/sitemap.ts | 2 + src/components/ConceptView.tsx | 70 +++++++++++++++++++++++++++ src/components/LearningPathView.tsx | 31 ++++-------- src/components/ReelPlayer.tsx | 26 ++++++++++ src/lib/concept-map.ts | 40 ++++++++++++++++ src/lib/concepts.ts | 36 ++++++++++++++ src/lib/hood-items.ts | 24 ++++++++++ src/lib/search.ts | 14 ++++++ tests/unit/concept-map.test.ts | 52 ++++++++++++++++++++ 14 files changed, 447 insertions(+), 22 deletions(-) create mode 100644 src/app/api/concepts/[key]/route.ts create mode 100644 src/app/api/concepts/route.ts create mode 100644 src/app/concepts/[key]/page.tsx create mode 100644 src/app/concepts/page.tsx create mode 100644 src/components/ConceptView.tsx create mode 100644 src/components/ReelPlayer.tsx create mode 100644 src/lib/concept-map.ts create mode 100644 src/lib/concepts.ts create mode 100644 tests/unit/concept-map.test.ts diff --git a/src/app/api/concepts/[key]/route.ts b/src/app/api/concepts/[key]/route.ts new file mode 100644 index 0000000..896b853 --- /dev/null +++ b/src/app/api/concepts/[key]/route.ts @@ -0,0 +1,28 @@ +import { NextResponse } from "next/server"; + +import { getConcept } from "@/lib/concepts"; +import { apiError } from "@/lib/http"; + +export const dynamic = "force-dynamic"; + +type Props = { params: Promise<{ key: string }> }; + +// One concept and the moments, across sessions, that explain it. +export async function GET(_request: Request, { params }: Props) { + const { key } = await params; + const concept = /^[a-z0-9-]{1,80}$/.test(key) ? await getConcept(key) : null; + if (!concept) return apiError(404, "not_found", "No such concept."); + return NextResponse.json({ + key: concept.key, + name: concept.name, + moments: concept.moments.map((m) => ({ + lectureId: m.lectureId, + title: m.title, + speaker: m.speaker, + startS: m.startS, + endS: m.endS, + text: m.text, + related: m.related, + })), + }); +} diff --git a/src/app/api/concepts/route.ts b/src/app/api/concepts/route.ts new file mode 100644 index 0000000..d80f55a --- /dev/null +++ b/src/app/api/concepts/route.ts @@ -0,0 +1,11 @@ +import { NextResponse } from "next/server"; + +import { listConcepts } from "@/lib/concepts"; + +export const dynamic = "force-dynamic"; + +// The concept map: every concept the published library teaches and how many sessions explain it. +export async function GET() { + const concepts = await listConcepts(); + return NextResponse.json(concepts.map((c) => ({ key: c.key, name: c.name, sessions: c.entries.length }))); +} diff --git a/src/app/concepts/[key]/page.tsx b/src/app/concepts/[key]/page.tsx new file mode 100644 index 0000000..9cd36ba --- /dev/null +++ b/src/app/concepts/[key]/page.tsx @@ -0,0 +1,58 @@ +import type { Metadata } from "next"; +import Link from "next/link"; +import { notFound } from "next/navigation"; + +import { ConceptView } from "@/components/ConceptView"; +import { UnderTheHood } from "@/components/UnderTheHood"; +import { getConcept } from "@/lib/concepts"; +import { conceptHoodItems } from "@/lib/hood-items"; +import { SHARE_CARD, shareCardUrl } from "@/lib/media"; + +export const dynamic = "force-dynamic"; + +type Props = { params: Promise<{ key: string }> }; + +const validKey = (key: string) => /^[a-z0-9-]{1,80}$/.test(key); + +export async function generateMetadata({ params }: Props): Promise { + const { key } = await params; + const concept = validKey(key) ? await getConcept(key) : null; + const first = concept?.moments[0]; + if (!concept || !first) return { title: "Concept not found — Pravaha" }; + const description = `${concept.name}, explained by ${concept.moments.length} moments from the lecture library, back to back.`; + const image = shareCardUrl(first.publicId, first.startS, { title: concept.name, subtitle: `Concept map · ${concept.moments.length} explanations` }); + return { + title: `${concept.name} — Pravaha`, + description, + openGraph: { type: "article", siteName: "Pravaha", title: concept.name, description, url: `/concepts/${key}`, images: [{ url: image, ...SHARE_CARD, alt: concept.name }] }, + twitter: { card: "summary_large_image", title: concept.name, description, images: [image] }, + }; +} + +export default async function ConceptPage({ params }: Props) { + const { key } = await params; + const concept = validKey(key) ? await getConcept(key) : null; + if (!concept || concept.moments.length === 0) notFound(); + return ( +
+

+ + ← Concept map + +

+

{concept.name}

+

+ {concept.moments.length} explanation{concept.moments.length === 1 ? "" : "s"} from your library + {concept.taughtBy > 1 ? `, ${concept.taughtBy} of them named by the sessions' own Study Packs` : ""}. +

+ + +

+ Want a guided order, basics first?{" "} + + Turn {concept.name} into a short course → + +

+
+ ); +} diff --git a/src/app/concepts/page.tsx b/src/app/concepts/page.tsx new file mode 100644 index 0000000..5f5ad58 --- /dev/null +++ b/src/app/concepts/page.tsx @@ -0,0 +1,74 @@ +import type { Metadata } from "next"; +import Link from "next/link"; + +import { listConcepts } from "@/lib/concepts"; + +export const dynamic = "force-dynamic"; + +export const metadata: Metadata = { + title: "Concept map — Pravaha", + description: "Every concept your lectures teach, and how many different teachers explain each one. Hear them back to back.", +}; + +export default async function ConceptsPage() { + const concepts = await listConcepts(); + const shared = concepts.filter((c) => c.entries.length > 1); + const single = concepts.filter((c) => c.entries.length === 1); + return ( +
+

+ One idea, every teacher. +

+

+ Pravaha reads every session and maps the concepts it teaches. Open one to hear the same idea from each lecturer in your + library, edited by Cloudinary into one video, until one explanation clicks. +

+ + {concepts.length === 0 && ( +

+ No concepts yet: they appear once sessions are published with a Study Pack. +

+ )} + + {shared.length > 0 && ( +
+

+ Taught by more than one lecturer +

+
    + {shared.map((c) => ( +
  • + + {c.name} + + {c.entries.length} sessions + + +
  • + ))} +
+
+ )} + + {single.length > 0 && ( +
+

+ More concepts +

+
    + {single.map((c) => ( +
  • + + {c.name} + +
  • + ))} +
+
+ )} +
+ ); +} diff --git a/src/app/layout.tsx b/src/app/layout.tsx index 92e694b..0ca2c0c 100644 --- a/src/app/layout.tsx +++ b/src/app/layout.tsx @@ -57,6 +57,9 @@ export default function RootLayout({ children }: { children: React.ReactNode }) Learn + + Concepts + Saved diff --git a/src/app/sitemap.ts b/src/app/sitemap.ts index cbf0400..76c4726 100644 --- a/src/app/sitemap.ts +++ b/src/app/sitemap.ts @@ -15,6 +15,8 @@ export default async function sitemap(): Promise { }); return [ { url: base, changeFrequency: "daily", priority: 1 }, + { url: `${base}/learn`, changeFrequency: "monthly", priority: 0.6 }, + { url: `${base}/concepts`, changeFrequency: "weekly", priority: 0.7 }, { url: `${base}/try`, changeFrequency: "monthly", priority: 0.6 }, { url: `${base}/privacy`, changeFrequency: "yearly", priority: 0.2 }, { url: `${base}/terms`, changeFrequency: "yearly", priority: 0.2 }, diff --git a/src/components/ConceptView.tsx b/src/components/ConceptView.tsx new file mode 100644 index 0000000..193fcfc --- /dev/null +++ b/src/components/ConceptView.tsx @@ -0,0 +1,70 @@ +"use client"; + +import Image from "next/image"; +import Link from "next/link"; + +import { MomentButton } from "@/components/MomentButton"; +import { ReelPlayer } from "@/components/ReelPlayer"; +import type { ConceptView as Concept } from "@/lib/concepts"; +import { formatTime } from "@/lib/format"; +import { reelUrl, thumbUrl } from "@/lib/media"; + +const firstName = (speaker: string | null, title: string) => (speaker ?? title).split(",")[0]!.slice(0, 38); + +// One concept, every teacher: the same idea explained in different voices, as one Cloudinary-stitched +// video (each clip labelled with who is speaking) and as cards that open the full session. +export function ConceptView({ concept }: { concept: Concept }) { + const { moments } = concept; + const reel = reelUrl(moments.map((m, i) => ({ publicId: m.publicId, startS: m.startS, endS: m.endS, label: `${i + 1} · ${firstName(m.speaker, m.title)}` }))); + const teachers = new Set(moments.map((m) => m.speaker ?? m.lectureId)).size; + + return ( +
+ {reel && moments.length > 1 && ( + + )} +
    + {moments.map((m, i) => ( +
  1. + + {`${m.title}, + {i + 1} + {formatTime(m.startS)} + +

    {m.speaker ?? "Unknown speaker"}

    +

    {m.title}

    +

    “{m.text}”

    + {m.related &&

    Closest moment in this session: it teaches the idea without listing it as a key concept.

    } +
    + + Open full session + + +
    +
  2. + ))} +
+
+ ); +} diff --git a/src/components/LearningPathView.tsx b/src/components/LearningPathView.tsx index b0b450d..7a964d9 100644 --- a/src/components/LearningPathView.tsx +++ b/src/components/LearningPathView.tsx @@ -2,9 +2,9 @@ import Image from "next/image"; import Link from "next/link"; -import { useState } from "react"; import { MomentButton } from "@/components/MomentButton"; +import { ReelPlayer } from "@/components/ReelPlayer"; import { formatTime } from "@/lib/format"; import { thumbUrl } from "@/lib/media"; import type { LearningPath } from "@/lib/paths"; @@ -29,7 +29,14 @@ export function LearningPathView({ path }: { path: LearningPath }) { ) : null}

- {path.reel && } + {path.reel && ( + + )}
    {path.steps.map((step) => ( @@ -84,23 +91,3 @@ export function LearningPathView({ path }: { path: LearningPath }) { ); } - -function CourseReel({ url, steps, durationS }: { url: string; steps: number; durationS: number }) { - const [playing, setPlaying] = useState(false); - if (playing) return