Update VocabPracticeDialog and VocabChapterView components to manage practice dialog state

- Changed the close button visibility in VocabPracticeDialog to false for a cleaner UI.
- Enhanced VocabChapterView to manage the practice dialog state with a new `practiceOpen` flag.
- Updated the `openPractice` method to handle the dialog's open and close events, ensuring proper state management.
This commit is contained in:
Torsten Schulz (local)
2025-12-30 18:44:35 +01:00
parent 83597d9e02
commit df64c0a4b5
2 changed files with 53 additions and 40 deletions

View File

@@ -2,7 +2,7 @@
<DialogWidget <DialogWidget
ref="dialog" ref="dialog"
:title="$t('socialnetwork.vocab.practice.title')" :title="$t('socialnetwork.vocab.practice.title')"
:show-close="true" :show-close="false"
:buttons="buttons" :buttons="buttons"
:modal="true" :modal="true"
:isTitleTranslated="false" :isTitleTranslated="false"
@@ -10,7 +10,6 @@
height="32em" height="32em"
name="VocabPracticeDialog" name="VocabPracticeDialog"
display="flex" display="flex"
@close="close"
> >
<div class="layout"> <div class="layout">
<div class="left"> <div class="left">
@@ -112,6 +111,7 @@ export default {
data() { data() {
return { return {
openParams: null, // { languageId, chapterId } openParams: null, // { languageId, chapterId }
onClose: null,
loading: false, loading: false,
allVocabs: false, allVocabs: false,
simpleMode: false, simpleMode: false,
@@ -168,12 +168,13 @@ export default {
}, },
}, },
methods: { methods: {
open({ languageId, chapterId }) { open({ languageId, chapterId, onClose = null }) {
if (this.autoAdvanceTimer) { if (this.autoAdvanceTimer) {
clearTimeout(this.autoAdvanceTimer); clearTimeout(this.autoAdvanceTimer);
this.autoAdvanceTimer = null; this.autoAdvanceTimer = null;
} }
this.openParams = { languageId, chapterId }; this.openParams = { languageId, chapterId };
this.onClose = typeof onClose === 'function' ? onClose : null;
this.allVocabs = false; this.allVocabs = false;
this.simpleMode = false; this.simpleMode = false;
this.correctCount = 0; this.correctCount = 0;
@@ -191,7 +192,12 @@ export default {
clearTimeout(this.autoAdvanceTimer); clearTimeout(this.autoAdvanceTimer);
this.autoAdvanceTimer = null; this.autoAdvanceTimer = null;
} }
const cb = this.onClose;
this.onClose = null;
this.$refs.dialog.close(); this.$refs.dialog.close();
try {
if (cb) cb();
} catch (_) {}
}, },
normalize(s) { normalize(s) {
return String(s || '') return String(s || '')

View File

@@ -5,6 +5,7 @@
<div v-if="loading">{{ $t('general.loading') }}</div> <div v-if="loading">{{ $t('general.loading') }}</div>
<div v-else-if="!chapter">{{ $t('socialnetwork.vocab.notFound') }}</div> <div v-else-if="!chapter">{{ $t('socialnetwork.vocab.notFound') }}</div>
<div v-else> <div v-else>
<div v-show="!practiceOpen">
<div class="row"> <div class="row">
<button @click="back">{{ $t('general.back') }}</button> <button @click="back">{{ $t('general.back') }}</button>
<button v-if="vocabs.length" @click="openPractice">{{ $t('socialnetwork.vocab.practice.open') }}</button> <button v-if="vocabs.length" @click="openPractice">{{ $t('socialnetwork.vocab.practice.open') }}</button>
@@ -46,6 +47,7 @@
</table> </table>
</div> </div>
</div> </div>
</div>
<VocabPracticeDialog ref="practiceDialog" /> <VocabPracticeDialog ref="practiceDialog" />
</template> </template>
@@ -61,6 +63,7 @@ export default {
return { return {
loading: false, loading: false,
saving: false, saving: false,
practiceOpen: false,
chapter: null, chapter: null,
vocabs: [], vocabs: [],
learning: '', learning: '',
@@ -77,9 +80,13 @@ export default {
this.$router.push(`/socialnetwork/vocab/${this.$route.params.languageId}`); this.$router.push(`/socialnetwork/vocab/${this.$route.params.languageId}`);
}, },
openPractice() { openPractice() {
this.practiceOpen = true;
this.$refs.practiceDialog?.open?.({ this.$refs.practiceDialog?.open?.({
languageId: this.$route.params.languageId, languageId: this.$route.params.languageId,
chapterId: this.$route.params.chapterId, chapterId: this.$route.params.chapterId,
onClose: () => {
this.practiceOpen = false;
},
}); });
}, },
async load() { async load() {