filter speaking practice dropdown to audio-only sets
Limit the Speaking page practice filter options to sets that contain AUDIO questions and clear stale selected filter values when unavailable. Made-with: Cursor
This commit is contained in:
parent
2fcf2b47b0
commit
e7e64ad2ed
|
|
@ -319,8 +319,26 @@ export function SpeakingPage() {
|
||||||
if (chunk.length < batchSize) break
|
if (chunk.length < batchSize) break
|
||||||
offset += chunk.length
|
offset += chunk.length
|
||||||
}
|
}
|
||||||
|
// Speaking page should only offer practices that already contain AUDIO questions.
|
||||||
|
const checks = await Promise.all(
|
||||||
|
all.map(async (practice) => {
|
||||||
|
try {
|
||||||
|
const res = await getPracticeQuestionsByPractice(practice.id, {
|
||||||
|
limit: 1,
|
||||||
|
offset: 0,
|
||||||
|
question_type: "AUDIO",
|
||||||
|
})
|
||||||
|
const total = res.data?.data?.total_count ?? 0
|
||||||
|
return total > 0 ? practice : null
|
||||||
|
} catch {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
|
||||||
|
const speakingPractices = checks.filter((p): p is QuestionSet => p !== null)
|
||||||
setPracticeOptions(
|
setPracticeOptions(
|
||||||
all.map((p) => ({
|
speakingPractices.map((p) => ({
|
||||||
id: p.id,
|
id: p.id,
|
||||||
title: p.title,
|
title: p.title,
|
||||||
})),
|
})),
|
||||||
|
|
@ -333,6 +351,12 @@ export function SpeakingPage() {
|
||||||
})
|
})
|
||||||
}, [fetchPracticeOptions])
|
}, [fetchPracticeOptions])
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (!selectedPracticeId) return
|
||||||
|
const exists = practiceOptions.some((option) => option.id === Number(selectedPracticeId))
|
||||||
|
if (!exists) setSelectedPracticeId("")
|
||||||
|
}, [practiceOptions, selectedPracticeId])
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
let cancelled = false
|
let cancelled = false
|
||||||
const fetchSubCourseOptions = async () => {
|
const fetchSubCourseOptions = async () => {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user