Dev Helpers
← Back

Course session planner

Place this file at app/courses/[course]/page.tsx in an App Router project.

Open this example in the interactive library

Source code

// app/courses/[course]/page.tsx

import { notFound } from "next/navigation";

export default async function CourseSessionPlanner({
  params,
}: {
  params: Promise<{ course: string }>;
}) {
  const courses = [
    {
      id: "drawing",
      lessons: ["Line", "Shade", "Depth"],
      minutes: [12, 20, 18],
      level: "Intro",
    },
    {
      id: "binding",
      lessons: ["Fold", "Stitch"],
      minutes: [15, 30],
      level: "Intermediate",
    },
  ];
  const { course } = await params;
  const c = courses.find((r) => r.id === course);
  if (!c) notFound();
  const total = c.minutes.reduce((a, b) => a + b, 0);
  return (
    <table>
      <caption>Study plan</caption>
      <tbody>
        {[10, 20, 30].map((n) => (
          <tr key={n}>
            <th>{n} minutes daily</th>
            <td>{Math.ceil(total / n)} days</td>
          </tr>
        ))}
      </tbody>
    </table>
  );
}