From db7e4a3434f4d50f38113018e2de12bd478d1e4b Mon Sep 17 00:00:00 2001 From: Henry Jameson Date: Mon, 15 Dec 2025 22:56:04 +0200 Subject: [PATCH] actual countdown --- .../settings_modal/settings_modal.js | 2 +- .../settings_modal/settings_modal.vue | 4 ++-- src/i18n/en.json | 1 + src/modules/config.js | 1 - src/stores/interface.js | 22 ++++++++++++++----- 5 files changed, 21 insertions(+), 9 deletions(-) diff --git a/src/components/settings_modal/settings_modal.js b/src/components/settings_modal/settings_modal.js index b4677fe7f..789ebd0ee 100644 --- a/src/components/settings_modal/settings_modal.js +++ b/src/components/settings_modal/settings_modal.js @@ -170,7 +170,7 @@ const SettingsModal = { }, computed: { ...mapState(useInterfaceStore, { - temporaryChangesTimeoutId: store => store.temporaryChangesTimeoutId, + temporaryChangesCountdown: store => store.temporaryChangesCountdown, currentSaveStateNotice: store => store.settings.currentSaveStateNotice, modalActivated: store => store.settingsModalState !== 'hidden', modalMode: store => store.settingsModalMode, diff --git a/src/components/settings_modal/settings_modal.vue b/src/components/settings_modal/settings_modal.vue index b4ccba191..d2b4f60ee 100644 --- a/src/components/settings_modal/settings_modal.vue +++ b/src/components/settings_modal/settings_modal.vue @@ -158,14 +158,14 @@ - {{ $t('settings.confirm_new_question') }} + {{ $t('settings.confirm_new_question_countdown', temporaryChangesCountdown) }} diff --git a/src/i18n/en.json b/src/i18n/en.json index c1c3978d1..05a2d5ae5 100644 --- a/src/i18n/en.json +++ b/src/i18n/en.json @@ -411,6 +411,7 @@ "appearance": "Appearance", "confirm_new_setting": "Confirm new setting?", "confirm_new_question": "Does this look ok? Setting will be reverted in 10 seconds.", + "confirm_new_question_countdown": "Does this look ok? Setting will be reverted in 1 second. | Does this look ok? Setting will be reverted in {count} seconds.", "revert": "Revert", "confirm": "Confirm", "text_size": "Text and interface size", diff --git a/src/modules/config.js b/src/modules/config.js index 7b54225ef..8b4691341 100644 --- a/src/modules/config.js +++ b/src/modules/config.js @@ -116,7 +116,6 @@ const config = { } useInterfaceStore().setTemporaryChanges({ - timeoutId: setTimeout(revert, 10000), confirm, revert }) diff --git a/src/stores/interface.js b/src/stores/interface.js index 56999217f..51ed42f65 100644 --- a/src/stores/interface.js +++ b/src/stores/interface.js @@ -18,9 +18,10 @@ export const useInterfaceStore = defineStore('interface', { paletteDataUsed: null, themeNameUsed: null, themeDataUsed: null, - temporaryChangesTimeoutId: null, // used for temporary options that revert after a timeout + temporaryChangesTimeoutId: null, + temporaryChangesCountdown: -1, // used for temporary options that revert after a timeout temporaryChangesConfirm: () => {}, // used for applying temporary options - temporaryChangesRevert: () => {}, // used for reverting temporary options + temporaryChangesRevert: () => {}, // used for reverting temporary options settingsModalState: 'hidden', settingsModalLoadedUser: false, settingsModalLoadedAdmin: false, @@ -44,14 +45,25 @@ export const useInterfaceStore = defineStore('interface', { lastTimeline: null }), actions: { - setTemporaryChanges ({ timeoutId, confirm, revert }) { - this.temporaryChangesTimeoutId = timeoutId + setTemporaryChanges ({ confirm, revert }) { + this.temporaryChangesCountdown = 10 this.temporaryChangesConfirm = confirm this.temporaryChangesRevert = revert + const countdownFunc = () => { + if (this.temporaryChangesCountdown === 1) { + this.temporaryChangesRevert() + this.clearTemporaryChanges() + } else { + this.temporaryChangesCountdown-- + this.temporaryChangesTimeoutId = setTimeout(countdownFunc, 1000) + } + } + this.temporaryChangesTimeoutId = setTimeout(countdownFunc, 1000) }, clearTemporaryChanges () { - clearTimeout(this.temporaryChangesTimeoutId) + this.temporaryChangesTimeoutId ?? clearTimeout(this.temporaryChangesTimeoutId) this.temporaryChangesTimeoutId = null + this.temporaryChangesCountdown = -1 this.temporaryChangesConfirm = () => {} this.temporaryChangesRevert = () => {} },