Fix stale edit-lesson form after save

Made-with: Cursor
This commit is contained in:
Yared Yemane 2026-04-16 04:44:32 -07:00
parent 7c3f2192ef
commit b5946b9da3
2 changed files with 18 additions and 7 deletions

View File

@ -299,8 +299,19 @@ export const deleteSubModule = (subModuleId: number) =>
export const getVideosBySubModule = (subModuleId: number) => export const getVideosBySubModule = (subModuleId: number) =>
http.get<GetSubCourseVideosResponse>(`/course-management/sub-modules/${subModuleId}/videos`) http.get<GetSubCourseVideosResponse>(`/course-management/sub-modules/${subModuleId}/videos`)
export const getSubModuleLessonById = (lessonId: number) => export const getSubModuleLessonById = (
http.get<GetSubModuleLessonDetailResponse>(`/course-management/sub-module-lessons/${lessonId}`) lessonId: number,
options?: {
/**
* Cache-bust the request to avoid serving stale lesson data after edits.
* This is intentionally implemented via query string to work with default axios config.
*/
cacheBust?: boolean
},
) =>
http.get<GetSubModuleLessonDetailResponse>(`/course-management/sub-module-lessons/${lessonId}`, {
params: options?.cacheBust ? { _t: Date.now() } : undefined,
})
export const createSubCourseVideo = (data: CreateSubCourseVideoRequest) => export const createSubCourseVideo = (data: CreateSubCourseVideoRequest) =>
http.post("/course-management/sub-module-videos", { http.post("/course-management/sub-module-videos", {

View File

@ -944,7 +944,7 @@ export function HumanLanguagePage() {
}) })
if (skipFetch) return if (skipFetch) return
try { try {
const res = await withTimeout(getSubModuleLessonById(lessonId), 12000) const res = await withTimeout(getSubModuleLessonById(lessonId, { cacheBust: forceRefresh }), 12000)
const data = res.data?.data const data = res.data?.data
if (!data) throw new Error("Missing lesson detail payload") if (!data) throw new Error("Missing lesson detail payload")
setLessonDetailState((prev) => ({ setLessonDetailState((prev) => ({
@ -1022,7 +1022,7 @@ export function HumanLanguagePage() {
setLessonDialog({ open: true, lessonId: lesson.id, questionSetId: lesson.question_set_id }) setLessonDialog({ open: true, lessonId: lesson.id, questionSetId: lesson.question_set_id })
setSavingLesson(false) setSavingLesson(false)
try { try {
const detail = (await getSubModuleLessonById(lesson.id)).data?.data const detail = (await getSubModuleLessonById(lesson.id, { cacheBust: true })).data?.data
setLessonForm({ setLessonForm({
title: detail?.title ?? lesson.title ?? "", title: detail?.title ?? lesson.title ?? "",
description: detail?.description ?? "", description: detail?.description ?? "",
@ -2704,7 +2704,7 @@ export function HumanLanguagePage() {
if (!open) setLessonDialog({ open: false }) if (!open) setLessonDialog({ open: false })
}} }}
> >
<DialogContent className="sm:max-w-lg"> <DialogContent className="sm:max-w-5xl max-h-[calc(100vh-6rem)] overflow-y-auto">
<DialogHeader> <DialogHeader>
<DialogTitle>Edit lesson</DialogTitle> <DialogTitle>Edit lesson</DialogTitle>
<DialogDescription>Update lesson metadata stored in the linked question set.</DialogDescription> <DialogDescription>Update lesson metadata stored in the linked question set.</DialogDescription>
@ -2800,7 +2800,7 @@ export function HumanLanguagePage() {
</div> </div>
</div> </div>
<div className="p-4"> <div className="p-4">
{lessonFetch?.status !== "ok" ? ( {lessonFetch?.status !== "ok" ? (
<div className="flex flex-col items-center justify-center gap-2 py-12 text-sm text-grayScale-500"> <div className="flex flex-col items-center justify-center gap-2 py-12 text-sm text-grayScale-500">
<SpinnerIcon className="h-5 w-5 text-brand-500" alt="" /> <SpinnerIcon className="h-5 w-5 text-brand-500" alt="" />
@ -2815,7 +2815,7 @@ export function HumanLanguagePage() {
</p> </p>
</div> </div>
) : ( ) : (
<ul className="max-h-[min(28rem,calc(100vh-16rem))] space-y-3 overflow-y-auto pr-1 [scrollbar-gutter:stable]"> <ul className="space-y-3 pr-1 [scrollbar-gutter:stable]">
{lessonFetch.questions.map((q, qIdx) => { {lessonFetch.questions.map((q, qIdx) => {
const qType = String(q.question_type ?? "—") const qType = String(q.question_type ?? "—")
const embeddedUrls = extractUrls(q.question_text || "") const embeddedUrls = extractUrls(q.question_text || "")