diff --git a/src/api/learningHierarchy.api.ts b/src/api/learningHierarchy.api.ts index 3b7bf79..ff2fc24 100644 --- a/src/api/learningHierarchy.api.ts +++ b/src/api/learningHierarchy.api.ts @@ -4,6 +4,7 @@ import type { QuestionSetQuestion } from "../types/course.types" export type LearningKind = "course" | "chapter" | "lesson" | "quiz" export type LearningItem = { id: number + is_archived?: boolean course_id?: number chapter_id?: number name?: string diff --git a/src/pages/content-management/LearningHierarchyPage.tsx b/src/pages/content-management/LearningHierarchyPage.tsx index cc77622..a4d95d4 100644 --- a/src/pages/content-management/LearningHierarchyPage.tsx +++ b/src/pages/content-management/LearningHierarchyPage.tsx @@ -32,6 +32,7 @@ export function LearningHierarchyPage() { const [failed, setFailed] = useState(false) const [busy, setBusy] = useState(false) const [search, setSearch] = useState("") + const [showLegacy, setShowLegacy] = useState(false) const [editor, setEditor] = useState(null) const [deleting, setDeleting] = useState<{ item: Item; kind: Kind } | null>(null) const [form, setForm] = useState({ name: "", description: "", thumbnail: "", video_url: "", access_tier: "FREE" }) @@ -100,9 +101,10 @@ export function LearningHierarchyPage() { catch (error) { notifyApiError(error, "Unable to delete content") } finally { setBusy(false) } } + const movableIndices = items.flatMap((item, index) => kind !== "course" || !item.is_archived ? [index] : []) async function move(index: number, direction: number) { - const ordered = [...items]; const target = index + direction - if (target < 0 || target >= ordered.length) return + const ordered = [...items]; const target = movableIndices[movableIndices.indexOf(index) + direction] + if (target === undefined) return ;[ordered[index], ordered[target]] = [ordered[target], ordered[index]] setBusy(true) try { await http.put(`${path}/reorder`, { ordered_ids: ordered.map(item => item.id) }); setItems(ordered) } @@ -110,15 +112,15 @@ export function LearningHierarchyPage() { finally { setBusy(false) } } const title = chapter?.name ?? course?.name ?? "Courses" - const matches = (item: Item) => (item.name ?? item.title ?? "").toLowerCase().includes(search.toLowerCase()) + const matches = (item: Item) => (kind !== "course" || !!item.is_archived === showLegacy) && (item.name ?? item.title ?? "").toLowerCase().includes(search.toLowerCase()) function card(item: Item, itemKind: Kind, index?: number) { return

{item.name ?? item.title}

{item.publish_status === "PUBLISHED" ? "Published" : "Draft"}{item.access_tier ? ` · ${item.access_tier.toLowerCase()}` : ""}

- {index !== undefined && !search && <>} - - + {index !== undefined && !search && !showLegacy && <>} + +
{item.description &&

{item.description}

} @@ -127,7 +129,7 @@ export function LearningHierarchyPage() { {itemKind === "course" && } {itemKind === "chapter" && } {itemKind === "quiz" && } - +
} @@ -135,9 +137,16 @@ export function LearningHierarchyPage() {

{title}

{chapterId ? "Manage the lessons and quizzes in this chapter." : courseId ? "Organize this course into chapters." : "Create courses, organize chapters, and add lessons and chapter quizzes."}

{courseId && } + {kind === "course" &&
+
+ + +
+ {showLegacy &&

Retired general-learning fixtures are kept here to preserve historical records and learner progress. They are unavailable in the learner catalog.

} +
} setSearch(event.target.value)} /> {loading ?

Loading content…

: failed ?

Content could not be loaded.

: <> -

{collection[kind]}

{items.map((item, index) => matches(item) ? card(item, kind, index) : null)}
{!items.some(matches) &&

{search ? "No matching content." : `No ${collection[kind]} yet. Add your first ${kind} to get started.`}

}
+

{collection[kind]}

{items.map((item, index) => matches(item) ? card(item, kind, index) : null)}
{!items.some(matches) &&

{search ? "No matching content." : showLegacy ? "No archived courses." : `No ${collection[kind]} yet. Add your first ${kind} to get started.`}

}
{chapterId &&

Chapter quizzes

{quizzes.filter(matches).map(item => card(item, "quiz"))}
{!quizzes.some(matches) &&

{search ? "No matching quizzes." : "No quizzes yet. Create a quiz, add its questions, then publish it."}

}
} } { if (!open && !busy) setEditor(null) }}>{editor?.item ? "Edit" : "Add"} {editor?.kind}