Fix: reloadQW awaitet purgeOrphans vor dem Reload
Purge lief parallel zum Reload – Fragen wurden vor der Bereinigung geladen. Globaler Bereinigen-Button lädt jetzt auch direkt neu. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -180,11 +180,15 @@ export default function GenerateIt() {
|
|||||||
getObjectWords(selectedObjId, token).then(setObjWords).catch(console.error)
|
getObjectWords(selectedObjId, token).then(setObjWords).catch(console.error)
|
||||||
}, [selectedObjId, token])
|
}, [selectedObjId, token])
|
||||||
|
|
||||||
const reloadQW = (objId: string) => {
|
const reloadQW = async (objId: string) => {
|
||||||
if (!token) return
|
if (!token) return
|
||||||
purgeOrphans(objId, token).catch(console.error)
|
await purgeOrphans(objId, token).catch(console.error)
|
||||||
getObjectQuestions(objId, token).then(setQuestions).catch(console.error)
|
const [qs, ws] = await Promise.all([
|
||||||
getObjectWords(objId, token).then(setObjWords).catch(console.error)
|
getObjectQuestions(objId, token).catch(() => [] as ObjectQuestion[]),
|
||||||
|
getObjectWords(objId, token).catch(() => [] as ObjectWord[]),
|
||||||
|
])
|
||||||
|
setQuestions(qs)
|
||||||
|
setObjWords(ws)
|
||||||
}
|
}
|
||||||
|
|
||||||
const handleDeleteQuestion = async (qId: string) => {
|
const handleDeleteQuestion = async (qId: string) => {
|
||||||
@@ -348,6 +352,7 @@ export default function GenerateIt() {
|
|||||||
try {
|
try {
|
||||||
const r = await purgeAllOrphans(token)
|
const r = await purgeAllOrphans(token)
|
||||||
alert(`Bereinigt: ${r.orphans_removed} verwaiste Einträge entfernt`)
|
alert(`Bereinigt: ${r.orphans_removed} verwaiste Einträge entfernt`)
|
||||||
|
if (selectedObjId) await reloadQW(selectedObjId)
|
||||||
} catch (e: unknown) {
|
} catch (e: unknown) {
|
||||||
alert(`Fehler: ${e instanceof Error ? e.message : e}`)
|
alert(`Fehler: ${e instanceof Error ? e.message : e}`)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user