diff --git a/src/pages/content-management/HumanLanguagePage.tsx b/src/pages/content-management/HumanLanguagePage.tsx index 3419790..3b8da01 100644 --- a/src/pages/content-management/HumanLanguagePage.tsx +++ b/src/pages/content-management/HumanLanguagePage.tsx @@ -1042,6 +1042,9 @@ export function HumanLanguagePage() { }) toast.error("Could not load full lesson details") } + + // Preload questions so the lesson edit dialog can show the question bank immediately. + if (lesson.question_set_id > 0) void loadLessonQuestionsIfNeeded(lesson.question_set_id) } const handleSaveLesson = async () => { @@ -1845,11 +1848,9 @@ export function HumanLanguagePage() { const selectedLessonFetch = cardSel.lessonId !== null ? lessonDetailState[cardSel.lessonId] : undefined const selectedLessonDetail = - selectedLessonFetch?.status === "ok" ? selectedLessonFetch.data : null - const selectedLessonQuestionSetId = - selectedLessonDetail?.question_set_id ?? selectedLesson?.question_set_id ?? 0 - const lessonFetch = - selectedLessonQuestionSetId > 0 ? lessonQuestionsState[selectedLessonQuestionSetId] : undefined + selectedLessonFetch && selectedLessonFetch.status === "ok" + ? selectedLessonFetch.data + : null const selectedLessonIds = selectedLessonIdsBySubModule[smKey] ?? [] const selectedLessonRows = lessonRows.filter((row) => selectedLessonIds.includes(row.id)) const selectedPracticeMeta = @@ -2006,6 +2007,16 @@ export function HumanLanguagePage() {
{lessonRows.map((v, idx) => { const isActive = cardSel.lessonId === v.id + const fetchedLessonCount = (() => { + const detailFetch = lessonDetailState[v.id] + if (detailFetch?.status === "ok") return detailFetch.data.question_count + + const questionFetch = lessonQuestionsState[v.question_set_id] + if (questionFetch?.status === "ok") return questionFetch.questions.length + + return undefined + })() + const questionCountToShow = fetchedLessonCount ?? v.question_count return (
@@ -2148,242 +2159,7 @@ export function HumanLanguagePage() { - {selectedLessonQuestionSetId > 0 && ( -
-
-
-
-

- Question bank -

-

- {selectedLessonDetail?.title ?? selectedLesson?.title} -

-

- {selectedLessonDetail?.question_count ?? selectedLesson?.question_count ?? 0}{" "} - {Number( - selectedLessonDetail?.question_count ?? selectedLesson?.question_count ?? 0, - ) === 1 - ? "question" - : "questions"}{" "} - in this lesson -

-
-
- - {lessonFetch?.status === "ok" ? ( - - {lessonFetch.questions.length} loaded - - ) : null} -
-
-
-
- {!lessonFetch || lessonFetch.status === "loading" ? ( -
- - Loading questions… -
- ) : null} - {lessonFetch?.status === "error" ? ( -
-
- -
-

{lessonFetch.message}

- -
-
-
- ) : null} - {lessonFetch?.status === "ok" && lessonFetch.questions.length === 0 ? ( -
- -

No questions in this lesson yet.

-

- Add them via Open editor. -

-
- ) : null} - {lessonFetch?.status === "ok" && lessonFetch.questions.length > 0 ? ( - - ) : null} -
-
- )} + {/* Question bank for lessons is shown inside the Edit lesson dialog. */} ) : (

@@ -2980,6 +2756,168 @@ export function HumanLanguagePage() { ? renderMediaPreview(lessonForm.introVideoUrl, "video", "", "Intro video") : null} + + {lessonDialog.open && lessonDialog.questionSetId > 0 ? ( + (() => { + const lessonQuestionSetId = lessonDialog.questionSetId + const lessonId = lessonDialog.lessonId + const lessonFetch = lessonQuestionsState[lessonQuestionSetId] + const lessonDetailFetch = lessonDetailState[lessonId] + const questionCount = + lessonDetailFetch?.status === "ok" + ? lessonDetailFetch.data.question_count + : lessonFetch?.status === "ok" + ? lessonFetch.questions.length + : 0 + + return ( +

+
+
+
+

+ Question bank +

+

+ {lessonForm.title} +

+

+ {questionCount} {questionCount === 1 ? "question" : "questions"} in this lesson +

+
+
+ +
+
+
+ +
+ {lessonFetch?.status !== "ok" ? ( +
+ + Loading questions… +
+ ) : lessonFetch.questions.length === 0 ? ( +
+ +

No questions in this lesson yet.

+

+ Add them via Open editor. +

+
+ ) : ( + + )} +
+
+ ) + })() + ) : null}