import { useEffect, useState } from "react" import { Link, useParams, useSearchParams } from "react-router-dom" import { ArrowLeft, ArrowRight, BookOpen, CheckCircle2, LockKeyhole, Search } from "lucide-react" import { BrandLogo } from "../../components/brand/BrandLogo" import { catalogThumbnail, getPublicCourse, getPublicCourses, type PublicCatalogPage as Catalog, type PublicCourseOutline } from "../../api/publicCatalog.api" const learnerApp = import.meta.env.VITE_LEARNER_APP_URL as string | undefined export function PublicCatalogPage() { const { courseId } = useParams<{ courseId: string }>() const [params, setParams] = useSearchParams() const search = params.get("q") ?? "" const offset = Math.max(0, Number(params.get("offset")) || 0) const [draftSearch, setDraftSearch] = useState(search) const [catalog, setCatalog] = useState(null) const [course, setCourse] = useState(null) const [loading, setLoading] = useState(true) const [error, setError] = useState("") const [retry, setRetry] = useState(0) useEffect(() => { const controller = new AbortController() async function load() { setLoading(true); setError(""); setCourse(null) try { if (courseId) { const id = Number(courseId) if (!Number.isSafeInteger(id) || id < 1) throw new Error("This course is not available.") const outline = await getPublicCourse(id, controller.signal) if (!controller.signal.aborted) setCourse(outline) } else { const page = await getPublicCourses(search, offset, controller.signal) if (!controller.signal.aborted) setCatalog(page) } } catch (problem) { if (!controller.signal.aborted) setError(problem instanceof Error ? problem.message : "Unable to load courses.") } finally { if (!controller.signal.aborted) setLoading(false) } } void load() return () => controller.abort() }, [courseId, search, offset, retry]) return
{courseId ? All courses :

Your next chapter starts here

Build skills.
Open new possibilities.

Explore our courses, discover what you will learn, and find the right place to begin. Browse every published course without an account.

{ event.preventDefault(); setParams(draftSearch.trim() ? { q: draftSearch.trim() } : {}) }} className="mt-7 flex max-w-xl gap-2 rounded-xl border border-[#163d35]/15 bg-white p-2">
} {loading ?

Loading courses...

: error ?

{error}

: course ? <>

{course.access_tier === "PREMIUM" ? "Premium course" : "Free course"}

{course.name}

{course.description}

{course.chapter_count} chapters · {course.lesson_count} lessons · {course.quiz_count} quizzes

{learnerApp ? Sign in to learn :

Sign in through your learning app to watch lessons and take quizzes.

}
{course.thumbnail ? : }

What you will learn

{course.chapters.map((chapter, index) =>
{index + 1}. {chapter.name}{chapter.lessons.length} lessons

{chapter.description}

    {chapter.lessons.map(lesson =>
  • {lesson.title}

    {lesson.description}

    {lesson.access_tier === "PREMIUM" ? "Premium lesson" : "Free lesson"}
  • )} {chapter.quizzes.map(quiz =>
  • {quiz.title}

    Chapter quiz · {quiz.question_count} questions

  • )}
)} {!course.chapters.length &&

The course outline will be available soon.

}
:

{search ? `Results for “${search}”` : "Explore our courses"}

{catalog?.total_count ?? 0} courses
{catalog?.courses.map(item =>
{item.thumbnail ? : }
{item.access_tier === "PREMIUM" ? "Premium" : "Free"}

{item.name}

{item.description}

{item.chapter_count} chapters · {item.lesson_count} lessons · {item.quiz_count} quizzes

View course
)}
{!catalog?.courses.length &&

{search ? "No courses match your search. Try another topic." : "New courses are on their way. Check back soon."}

} {!!catalog?.total_count && }
}
}