refresh speaking practice filter after create
Re-fetch practice options after creating a speaking practice and auto-select the new set so freshly created practices appear immediately in the filter and question list. Made-with: Cursor
This commit is contained in:
parent
dbfb4307fb
commit
7b08b228df
|
|
@ -268,10 +268,7 @@ export function SpeakingPage() {
|
||||||
fetchAudioQuestions()
|
fetchAudioQuestions()
|
||||||
}, [fetchAudioQuestions, audioPageSize, selectedPracticeId])
|
}, [fetchAudioQuestions, audioPageSize, selectedPracticeId])
|
||||||
|
|
||||||
useEffect(() => {
|
const fetchPracticeOptions = useCallback(async () => {
|
||||||
let cancelled = false
|
|
||||||
const fetchPractices = async () => {
|
|
||||||
try {
|
|
||||||
const batchSize = 100
|
const batchSize = 100
|
||||||
let offset = 0
|
let offset = 0
|
||||||
let total = Number.POSITIVE_INFINITY
|
let total = Number.POSITIVE_INFINITY
|
||||||
|
|
@ -297,24 +294,20 @@ export function SpeakingPage() {
|
||||||
if (chunk.length < batchSize) break
|
if (chunk.length < batchSize) break
|
||||||
offset += chunk.length
|
offset += chunk.length
|
||||||
}
|
}
|
||||||
if (!cancelled) {
|
|
||||||
setPracticeOptions(
|
setPracticeOptions(
|
||||||
all.map((p) => ({
|
all.map((p) => ({
|
||||||
id: p.id,
|
id: p.id,
|
||||||
title: p.title,
|
title: p.title,
|
||||||
})),
|
})),
|
||||||
)
|
)
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
if (!cancelled) setPracticeOptions([])
|
|
||||||
}
|
|
||||||
}
|
|
||||||
fetchPractices()
|
|
||||||
return () => {
|
|
||||||
cancelled = true
|
|
||||||
}
|
|
||||||
}, [])
|
}, [])
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
fetchPracticeOptions().catch(() => {
|
||||||
|
setPracticeOptions([])
|
||||||
|
})
|
||||||
|
}, [fetchPracticeOptions])
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
let cancelled = false
|
let cancelled = false
|
||||||
const fetchSubCourseOptions = async () => {
|
const fetchSubCourseOptions = async () => {
|
||||||
|
|
@ -894,6 +887,8 @@ export function SpeakingPage() {
|
||||||
setOpenCreate(false)
|
setOpenCreate(false)
|
||||||
setCurrentStep(1)
|
setCurrentStep(1)
|
||||||
resetCreateForm()
|
resetCreateForm()
|
||||||
|
await fetchPracticeOptions()
|
||||||
|
setSelectedPracticeId(String(setId))
|
||||||
toast.success(`Speaking practice created with ${draftsToCreate.length} AUDIO question(s)`)
|
toast.success(`Speaking practice created with ${draftsToCreate.length} AUDIO question(s)`)
|
||||||
await fetchAudioQuestions()
|
await fetchAudioQuestions()
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user