Skip to content

armgit / dashy

Public Imported from GitHub
0

πŸš€ A self-hostable personal dashboard built for you. Includes status-checking, widgets, themes, icon packs, a UI editor and tons more!

✨ Confirm dialog, for confirmation before deletions

Alicia Sykes8689a0eac417
diff --git a/src/assets/locales/en.json b/src/assets/locales/en.json
index d5faec85..8798edad 100644
--- a/src/assets/locales/en.json
+++ b/src/assets/locales/en.json
@@ -1,6 +1,8 @@
{
"general": {
- "close-modal": "Close dialog"
+ "close-modal": "Close dialog",
+ "confirm": "Confirm",
+ "cancel": "Cancel"
},
"home": {
"no-results": "No Search Results",
diff --git a/src/components/Configuration/ConfigContainer.vue b/src/components/Configuration/ConfigContainer.vue
index 050ef501..fd933ff8 100644
--- a/src/components/Configuration/ConfigContainer.vue
+++ b/src/components/Configuration/ConfigContainer.vue
@@ -91,6 +91,13 @@
<RebuildApp />
</TabItem>
</Tabs>
+ <ConfirmDialog
+ v-model:open="showResetConfirm"
+ danger
+ :title="$t('config.reset-settings-button')"
+ :message="resetConfirmMessage()"
+ @confirm="confirmResetLocalSettings"
+ />
</template>
<script>
@@ -108,6 +115,7 @@ import DebugInfo from '@/components/Configuration/DebugInfo';
import AppVersion from '@/components/Configuration/AppVersion';
import ExportConfigMenu from '@/components/InteractiveEditor/ExportConfigMenu';
import Button from '@/components/FormElements/Button';
+import ConfirmDialog from '@/components/FormElements/ConfirmDialog';
import Tabs from '@/components/FormElements/Tabs';
import TabItem from '@/components/FormElements/TabItem';
import DownloadIcon from '@/assets/interface-icons/config-download-file.svg';
@@ -135,6 +143,7 @@ export default {
backupId: localStorage[localStorageKeys.BACKUP_ID] || '',
appVersion: import.meta.env.VITE_APP_VERSION,
latestVersion: '',
+ showResetConfirm: false,
};
},
props: {
@@ -160,6 +169,7 @@ export default {
Tabs,
TabItem,
Button,
+ ConfirmDialog,
JsonEditor,
CustomCssEditor,
CloudBackupRestore,
@@ -226,14 +236,16 @@ export default {
/* Clears config-scoped localStorage entries for root + all sub-pages, then reloads config.
* Preserves unrelated keys (auth tokens, backup hashes, mostUsed etc) */
resetLocalSettings() {
- const msg = `${this.$t('config.reset-config-msg-l1')} `
- + `${this.$t('config.reset-config-msg-l2')}\n\n${this.$t('config.reset-config-msg-l3')}`;
- const isTheUserSure = confirm(msg);
- if (isTheUserSure) {
- clearScopedLocalConfig(this.$store.getters.pages);
- this.$toast(this.$t('config.data-cleared-msg'));
- this.$store.dispatch(StoreKeys.INITIALIZE_CONFIG, this.$store.state.currentConfigInfo.confId);
- }
+ this.showResetConfirm = true;
+ },
+ confirmResetLocalSettings() {
+ clearScopedLocalConfig(this.$store.getters.pages);
+ this.$toast(this.$t('config.data-cleared-msg'));
+ this.$store.dispatch(StoreKeys.INITIALIZE_CONFIG, this.$store.state.currentConfigInfo.confId);
+ },
+ resetConfirmMessage() {
+ return `${this.$t('config.reset-config-msg-l1')} `
+ + `${this.$t('config.reset-config-msg-l2')}\n\n${this.$t('config.reset-config-msg-l3')}`;
},
getLanguage() {
const lang = getUsersLanguage();
diff --git a/src/components/Configuration/JsonEditor.vue b/src/components/Configuration/JsonEditor.vue
index 56d0a9d6..e8f28f30 100644
--- a/src/components/Configuration/JsonEditor.vue
+++ b/src/components/Configuration/JsonEditor.vue
@@ -99,6 +99,19 @@
{{ $t('config-editor.not-admin-note') }}
</p>
<p class="note">{{ $t('config.backup-note') }}</p>
+ <ConfirmDialog
+ v-model:open="showSaveLocallyConfirm"
+ :title="$t('interactive-editor.menu.save-locally-btn')"
+ :message="$t('interactive-editor.menu.save-locally-warning')"
+ @confirm="confirmSaveLocally"
+ />
+ <ConfirmDialog
+ v-model:open="showResetConfirm"
+ danger
+ :title="$t('config-editor.reset-label')"
+ :message="$t('config-editor.reset-confirm-msg')"
+ @confirm="confirmReset"
+ />
</div>
<AccessError v-else />
</template>
@@ -123,6 +136,7 @@ import ConfigSavingMixin from '@/mixins/ConfigSaving';
import ErrorHandler, { InfoHandler, InfoKeys } from '@/utils/logging/ErrorHandler';
import StoreKeys from '@/utils/StoreMutations';
import Button from '@/components/FormElements/Button';
+import ConfirmDialog from '@/components/FormElements/ConfirmDialog';
import AccessError from '@/components/Configuration/AccessError';
import DownloadIcon from '@/assets/interface-icons/config-download-file.svg';
import CopyIcon from '@/assets/interface-icons/interactive-editor-copy-clipboard.svg';
@@ -152,6 +166,7 @@ export default {
mixins: [ConfigSavingMixin],
components: {
Button,
+ ConfirmDialog,
AccessError,
DownloadIcon,
CopyIcon,
@@ -165,6 +180,9 @@ export default {
wordWrap: true,
errorMessages: [],
initialDoc: '',
+ showSaveLocallyConfirm: false,
+ showResetConfirm: false,
+ pendingSaveData: null,
};
},
setup() {
@@ -329,8 +347,13 @@ export default {
onSaveLocally() {
const data = this.parseCurrent();
if (data == null) return;
-
- if (!confirm(this.$t('interactive-editor.menu.save-locally-warning'))) return;
+ this.pendingSaveData = data;
+ this.showSaveLocallyConfirm = true;
+ },
+ confirmSaveLocally() {
+ const data = this.pendingSaveData;
+ this.pendingSaveData = null;
+ if (data == null) return;
this.saveConfigLocally(data);
this.applyConfigToStore(data);
this.initialDoc = this.currentText();
@@ -351,8 +374,12 @@ export default {
const dirty = this.view.state.doc.toString() !== this.initialDoc;
const inPreview = this.$store.state.editMode;
if (!dirty && !inPreview) return;
-
- if (!confirm(this.$t('config-editor.reset-confirm-msg'))) return;
+ this.showResetConfirm = true;
+ },
+ confirmReset() {
+ if (!this.view) return;
+ const dirty = this.view.state.doc.toString() !== this.initialDoc;
+ const inPreview = this.$store.state.editMode;
if (dirty) {
this.view.dispatch({
changes: { from: 0, to: this.view.state.doc.length, insert: this.initialDoc },
diff --git a/src/components/FormElements/ConfirmDialog.vue b/src/components/FormElements/ConfirmDialog.vue
new file mode 100644
index 00000000..1138473c
--- /dev/null
+++ b/src/components/FormElements/ConfirmDialog.vue
@@ -0,0 +1,140 @@
+<template>
+ <dialog
+ ref="dlg"
+ class="confirm-dialog"
+ :class="{ danger }"
+ @close="onNativeClose"
+ @cancel.prevent="cancel"
+ @keydown.enter.prevent="confirm"
+ >
+ <h3 v-if="title" class="title">{{ title }}</h3>
+ <div class="body">
+ <p v-if="message" class="message">{{ message }}</p>
+ <slot />
+ </div>
+ <div class="actions">
+ <button ref="cancelBtn" type="button" class="btn cancel" @click="cancel">
+ {{ cancelText || $t('general.cancel') }}
+ </button>
+ <button type="button" class="btn confirm" @click="confirm">
+ {{ confirmText || $t('general.confirm') }}
+ </button>
+ </div>
+ </dialog>
+</template>
+
+<script>
+export default {
+ name: 'ConfirmDialog',
+ props: {
+ open: { type: Boolean, default: false },
+ title: { type: String, default: '' },
+ message: { type: String, default: '' },
+ confirmText: { type: String, default: '' },
+ cancelText: { type: String, default: '' },
+ danger: { type: Boolean, default: false },
+ },
+ emits: ['update:open', 'confirm', 'cancel'],
+ watch: {
+ open: {
+ immediate: true,
+ handler(v) { this.$nextTick(() => (v ? this.show() : this.hide())); },
+ },
+ },
+ beforeUnmount() { this.hide(); },
+ methods: {
+ show() {
+ const d = this.$refs.dlg;
+ if (!d || d.open) return;
+ d.showModal();
+ this.$nextTick(() => this.$refs.cancelBtn?.focus());
+ },
+ hide() {
+ const d = this.$refs.dlg;
+ if (d?.open) d.close();
+ },
+ confirm() {
+ this.$emit('confirm');
+ this.$emit('update:open', false);
+ },
+ cancel() {
+ this.$emit('cancel');
+ this.$emit('update:open', false);
+ },
+ onNativeClose() {
+ if (this.open) this.$emit('update:open', false);
+ },
+ },
+};
+</script>
+
+<style scoped lang="scss">
+.confirm-dialog {
+ padding: 0;
+ width: min(28rem, calc(100vw - 2rem));
+ color: var(--config-settings-color);
+ background: var(--config-settings-background);
+ border: 1px solid var(--primary);
+ border-radius: var(--curve-factor);
+ box-shadow: 0 20px 50px -10px hsl(0deg 0% 0% / 60%);
+
+ &::backdrop {
+ background: #00000080;
+ }
+
+ .title {
+ margin: 0;
+ padding: 1rem 1.25rem;
+ font-size: 1.2rem;
+ color: var(--primary);
+ border-bottom: 1px solid var(--primary);
+ }
+
+ .body {
+ padding: 1rem 1.25rem;
+ .message {
+ margin: 0;
+ white-space: pre-line;
+ line-height: 1.4;
+ }
+ }
+
+ .actions {
+ display: flex;
+ justify-content: flex-end;
+ gap: 0.5rem;
+ padding: 0.75rem 1.25rem 1rem;
+
+ .btn {
+ padding: 0.4rem 0.9rem;
+ font-size: 1rem;
+ cursor: pointer;
+ color: var(--primary);
+ background: transparent;
+ border: 1px solid var(--primary);
+ border-radius: var(--curve-factor);
+
+ &:hover, &:focus-visible {
+ color: var(--background);
+ background: var(--primary);
+ outline: none;
+ }
+ }
+
+ .cancel {
+ opacity: var(--dimming-factor);
+ &:hover, &:focus-visible { opacity: 1; }
+ }
+ }
+
+ &.danger .actions .confirm {
+ color: var(--danger);
+ border-color: var(--danger);
+ &:hover, &:focus-visible {
+ color: var(--background);
+ background: var(--danger);
+ border-color: var(--danger);
+ }
+ }
+}
+</style>
diff --git a/src/components/InteractiveEditor/EditModeSaveMenu.vue b/src/components/InteractiveEditor/EditModeSaveMenu.vue
index ff25ae79..2711d10e 100644
--- a/src/components/InteractiveEditor/EditModeSaveMenu.vue
+++ b/src/components/InteractiveEditor/EditModeSaveMenu.vue
@@ -103,12 +103,19 @@
<EditPageInfo />
<EditAppConfig />
<EditMultiPages />
+ <ConfirmDialog
+ v-model:open="showSaveLocallyConfirm"
+ :title="$t('interactive-editor.menu.save-locally-btn')"
+ :message="$t('interactive-editor.menu.save-locally-warning')"
+ @confirm="confirmSaveLocally"
+ />
</div>
</template>
<script>
import ConfigSavingMixin from '@/mixins/ConfigSaving';
import Button from '@/components/FormElements/Button';
+import ConfirmDialog from '@/components/FormElements/ConfirmDialog';
import StoreKeys from '@/utils/StoreMutations';
import EditPageInfo from '@/components/InteractiveEditor/EditPageInfo';
import EditAppConfig from '@/components/InteractiveEditor/EditAppConfig';
@@ -129,6 +136,7 @@ export default {
mixins: [ConfigSavingMixin],
components: {
Button,
+ ConfirmDialog,
EditPageInfo,
EditAppConfig,
EditMultiPages,
@@ -142,6 +150,11 @@ export default {
ConfigFileIcon,
AccessError,
},
+ data() {
+ return {
+ showSaveLocallyConfirm: false,
+ };
+ },
computed: {
configToSave() {
return this.$store.state.configSource;
@@ -191,11 +204,10 @@ export default {
this.$toast[success ? 'success' : 'error'](message);
},
saveLocally() {
- const msg = this.$t('interactive-editor.menu.save-locally-warning');
- const youSure = confirm(msg);
- if (youSure) {
- this.saveConfigLocally(this.configToSave);
- }
+ this.showSaveLocallyConfirm = true;
+ },
+ confirmSaveLocally() {
+ this.saveConfigLocally(this.configToSave);
},
writeToDisk() {
this.writeConfigToDisk(this.configToSave);
diff --git a/src/components/LinkItems/Section.vue b/src/components/LinkItems/Section.vue
index a198d875..b64ac6ea 100644
--- a/src/components/LinkItems/Section.vue
+++ b/src/components/LinkItems/Section.vue
@@ -94,6 +94,13 @@
@expandCollapseSection="expandCollapseSection"
@removeSection="removeSection"
/>
+ <ConfirmDialog
+ v-model:open="showRemoveConfirm"
+ danger
+ :title="$t('context-menus.section.remove-section')"
+ :message="$t('interactive-editor.edit-section.remove-confirm')"
+ @confirm="confirmRemoveSection"
+ />
</Collapsable>
</template>
@@ -106,6 +113,7 @@ import WidgetBase from '@/components/Widgets/WidgetBase';
import Collapsable from '@/components/LinkItems/Collapsable.vue';
import IframeModal from '@/components/LinkItems/IframeModal.vue';
import ContextMenu from '@/components/LinkItems/SectionContextMenu.vue';
+import ConfirmDialog from '@/components/FormElements/ConfirmDialog.vue';
const EditSection = defineAsyncComponent(() => import('@/components/InteractiveEditor/EditSection.vue'));
import ErrorHandler from '@/utils/logging/ErrorHandler';
@@ -136,6 +144,7 @@ export default {
WidgetBase,
IframeModal,
EditSection,
+ ConfirmDialog,
},
data() {
return {
@@ -147,6 +156,7 @@ export default {
},
sectionWidth: 0,
resizeObserver: null,
+ showRemoveConfirm: false,
};
},
computed: {
@@ -232,13 +242,12 @@ export default {
},
/* Deletes current section, in local state */
removeSection() {
- const confirmMsg = this.$t('interactive-editor.edit-section.remove-confirm');
- const youSure = confirm(confirmMsg);
- if (youSure) {
- const payload = { sectionIndex: this.index, sectionName: this.title };
- this.$store.commit(StoreKeys.REMOVE_SECTION, payload);
- }
this.closeContextMenu();
+ this.showRemoveConfirm = true;
+ },
+ confirmRemoveSection() {
+ const payload = { sectionIndex: this.index, sectionName: this.title };
+ this.$store.commit(StoreKeys.REMOVE_SECTION, payload);
},
/* Open custom context menu, and set position */
openContextMenu(e) {
diff --git a/src/components/Settings/LocalConfigWarning.vue b/src/components/Settings/LocalConfigWarning.vue
index c66b9b83..a206abc2 100644
--- a/src/components/Settings/LocalConfigWarning.vue
+++ b/src/components/Settings/LocalConfigWarning.vue
@@ -13,6 +13,13 @@
</div>
</div>
</transition>
+ <ConfirmDialog
+ v-model:open="showResetConfirm"
+ danger
+ :title="$t('config.reset-config-label')"
+ :message="resetConfirmMessage()"
+ @confirm="confirmReset"
+ />
</template>
<script>
@@ -21,14 +28,17 @@ import { localStorageKeys, modalNames } from '@/utils/config/defaults';
import { clearScopedLocalConfig } from '@/utils/config/ConfigHelpers';
import StoreKeys from '@/utils/StoreMutations';
import configSavingMixin from '@/mixins/ConfigSaving';
+import ConfirmDialog from '@/components/FormElements/ConfirmDialog';
export default {
name: 'KeyboardShortcutInfo',
mixins: [configSavingMixin],
+ components: { ConfirmDialog },
data() {
return {
shouldHide: true, // False = show/ true = hide. Intuitive, eh?
timeDelay: 2000, // Short delay in ms before popup appears
+ showResetConfirm: false,
popupContent: {
title: '⚠️ You\'re using a local config',
message: `This means that your settings are saved in this browser only,
@@ -50,15 +60,17 @@ export default {
this.shouldHide = true;
},
resetLocalConfig() {
- const msg = `${this.$t('config.reset-config-msg-l1')} `
- + `${this.$t('config.reset-config-msg-l2')}\n\n${this.$t('config.reset-config-msg-l3')}`;
- const isTheUserSure = confirm(msg);
- if (isTheUserSure) {
- clearScopedLocalConfig(this.$store.getters.pages);
- this.$toast(this.$t('config.data-cleared-msg'));
- this.$store.dispatch(StoreKeys.INITIALIZE_CONFIG);
- this.shouldHide = true;
- }
+ this.showResetConfirm = true;
+ },
+ resetConfirmMessage() {
+ return `${this.$t('config.reset-config-msg-l1')} `
+ + `${this.$t('config.reset-config-msg-l2')}\n\n${this.$t('config.reset-config-msg-l3')}`;
+ },
+ confirmReset() {
+ clearScopedLocalConfig(this.$store.getters.pages);
+ this.$toast(this.$t('config.data-cleared-msg'));
+ this.$store.dispatch(StoreKeys.INITIALIZE_CONFIG);
+ this.shouldHide = true;
},
/**
* Returns true if the key exists in session storage, otherwise false
diff --git a/src/views/Home.vue b/src/views/Home.vue
index 6816d1a0..47e2b54b 100644
--- a/src/views/Home.vue
+++ b/src/views/Home.vue
@@ -16,7 +16,7 @@
<!-- Main content, section for each group of items -->
<div v-if="checkTheresData(sections) || isEditMode" :class="computedClass"
ref="sectionsContainer">
- <template v-for="(section, index) in filteredSections" :key="index">
+ <template v-for="(section, index) in filteredSections" :key="makeSectionId(section)">
<Section
:index="index"
:title="section.name"
diff --git a/src/views/Minimal.vue b/src/views/Minimal.vue
index 1e4cf571..5ce0d07d 100644
--- a/src/views/Minimal.vue
+++ b/src/views/Minimal.vue
@@ -38,7 +38,7 @@
<!-- Section item groups -->
<MinimalSection
v-for="(section, index) in sections"
- :key="`body-${index}`"
+ :key="makeSectionId(section)"
:index="index"
:title="section.name"
:icon="section.icon || undefined"