Prevent stale edit lesson form
Made-with: Cursor
This commit is contained in:
parent
b5946b9da3
commit
3607e4491b
|
|
@ -311,6 +311,12 @@ export const getSubModuleLessonById = (
|
||||||
) =>
|
) =>
|
||||||
http.get<GetSubModuleLessonDetailResponse>(`/course-management/sub-module-lessons/${lessonId}`, {
|
http.get<GetSubModuleLessonDetailResponse>(`/course-management/sub-module-lessons/${lessonId}`, {
|
||||||
params: options?.cacheBust ? { _t: Date.now() } : undefined,
|
params: options?.cacheBust ? { _t: Date.now() } : undefined,
|
||||||
|
headers: options?.cacheBust
|
||||||
|
? {
|
||||||
|
"Cache-Control": "no-cache",
|
||||||
|
Pragma: "no-cache",
|
||||||
|
}
|
||||||
|
: undefined,
|
||||||
})
|
})
|
||||||
|
|
||||||
export const createSubCourseVideo = (data: CreateSubCourseVideoRequest) =>
|
export const createSubCourseVideo = (data: CreateSubCourseVideoRequest) =>
|
||||||
|
|
|
||||||
|
|
@ -339,6 +339,7 @@ export function HumanLanguagePage() {
|
||||||
const navigate = useNavigate()
|
const navigate = useNavigate()
|
||||||
const location = useLocation()
|
const location = useLocation()
|
||||||
const emptyStateRetryCountRef = useRef(0)
|
const emptyStateRetryCountRef = useRef(0)
|
||||||
|
const lessonEditFetchIdRef = useRef(0)
|
||||||
const [loading, setLoading] = useState(false)
|
const [loading, setLoading] = useState(false)
|
||||||
const [categoryId, setCategoryId] = useState<number | null>(null)
|
const [categoryId, setCategoryId] = useState<number | null>(null)
|
||||||
const [subCategories, setSubCategories] = useState<HumanLanguageSubCategoryTree[]>([])
|
const [subCategories, setSubCategories] = useState<HumanLanguageSubCategoryTree[]>([])
|
||||||
|
|
@ -1019,20 +1020,34 @@ export function HumanLanguagePage() {
|
||||||
}
|
}
|
||||||
|
|
||||||
const openEditLessonDialog = async (lesson: { id: number; question_set_id: number; title: string }) => {
|
const openEditLessonDialog = async (lesson: { id: number; question_set_id: number; title: string }) => {
|
||||||
|
const requestId = ++lessonEditFetchIdRef.current
|
||||||
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)
|
||||||
|
|
||||||
|
// Set something immediately to avoid showing stale values while the refetch is in-flight.
|
||||||
|
setLessonForm({
|
||||||
|
title: lesson.title ?? "",
|
||||||
|
description: "",
|
||||||
|
introVideoUrl: "",
|
||||||
|
status: "DRAFT",
|
||||||
|
})
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const detail = (await getSubModuleLessonById(lesson.id, { cacheBust: true })).data?.data
|
const detail = (await getSubModuleLessonById(lesson.id, { cacheBust: true })).data?.data
|
||||||
|
if (lessonEditFetchIdRef.current !== requestId) return
|
||||||
|
|
||||||
setLessonForm({
|
setLessonForm({
|
||||||
title: detail?.title ?? lesson.title ?? "",
|
title: detail?.title ?? lesson.title ?? "",
|
||||||
description: detail?.description ?? "",
|
description: detail?.description ?? "",
|
||||||
introVideoUrl: detail?.intro_video_url ?? "",
|
introVideoUrl: detail?.intro_video_url ?? "",
|
||||||
status:
|
status:
|
||||||
(detail?.status as "DRAFT" | "PUBLISHED" | "ARCHIVED" | undefined) && ["DRAFT", "PUBLISHED", "ARCHIVED"].includes(detail.status)
|
(detail?.status as "DRAFT" | "PUBLISHED" | "ARCHIVED" | undefined) &&
|
||||||
|
["DRAFT", "PUBLISHED", "ARCHIVED"].includes(detail.status)
|
||||||
? (detail.status as "DRAFT" | "PUBLISHED" | "ARCHIVED")
|
? (detail.status as "DRAFT" | "PUBLISHED" | "ARCHIVED")
|
||||||
: "DRAFT",
|
: "DRAFT",
|
||||||
})
|
})
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
if (lessonEditFetchIdRef.current !== requestId) return
|
||||||
console.error("Failed to load lesson detail:", error)
|
console.error("Failed to load lesson detail:", error)
|
||||||
setLessonForm({
|
setLessonForm({
|
||||||
title: lesson.title ?? "",
|
title: lesson.title ?? "",
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user