diff --git a/vue/src/components/util/ConfirmDialog.vue b/vue/src/components/util/ConfirmDialog.vue new file mode 100644 index 0000000..11a4e26 --- /dev/null +++ b/vue/src/components/util/ConfirmDialog.vue @@ -0,0 +1,65 @@ + + + + + diff --git a/vue/src/components/util/Modal.vue b/vue/src/components/util/Modal.vue index fecd148..882b01d 100644 --- a/vue/src/components/util/Modal.vue +++ b/vue/src/components/util/Modal.vue @@ -1,62 +1,26 @@ diff --git a/vue/src/js/useOverlayStack.js b/vue/src/js/useOverlayStack.js new file mode 100644 index 0000000..0b31aca --- /dev/null +++ b/vue/src/js/useOverlayStack.js @@ -0,0 +1,42 @@ +import { onUnmounted, watch } from "vue"; + +const entries = []; +let listening = false; + +function onKeydown(event) { + if (event.key !== "Escape") return; + entries.at(-1)?.close(); +} + +function updateListener() { + if (entries.length && !listening) { + window.addEventListener("keydown", onKeydown); + listening = true; + } else if (!entries.length && listening) { + window.removeEventListener("keydown", onKeydown); + listening = false; + } +} + +/** Registers one open overlay so Escape always closes only the topmost one. */ +export function useOverlayStack(open, close) { + let entry = null; + + function register() { + if (entry) return; + entry = { close }; + entries.push(entry); + updateListener(); + } + + function unregister() { + if (!entry) return; + const index = entries.indexOf(entry); + if (index !== -1) entries.splice(index, 1); + entry = null; + updateListener(); + } + + watch(open, (isOpen) => (isOpen ? register() : unregister()), { immediate: true }); + onUnmounted(unregister); +} diff --git a/vue/src/views/admin/Environment.vue b/vue/src/views/admin/Environment.vue index feeebfe..f9ddb6e 100644 --- a/vue/src/views/admin/Environment.vue +++ b/vue/src/views/admin/Environment.vue @@ -19,12 +19,15 @@ import { ref, reactive, computed, onMounted, onUnmounted } from "vue"; import { api } from "@/api"; import Button from "@/components/input/Button.vue"; import SecretReveal from "@/components/admin/SecretReveal.vue"; +import ConfirmDialog from "@/components/util/ConfirmDialog.vue"; import "./env.css"; const groups = ref([]); const status = ref(null); const error = ref(""); const loading = ref(true); +const applyConfirmationOpen = ref(false); +const applyConfirmation = ref({ title: "Apply changes", message: "", confirmLabel: "Apply" }); // Staged edits, none of which exist anywhere but this component until Apply. // drafts: name -> text in the row's input @@ -127,7 +130,12 @@ async function apply() { `This recreates: ${affectedServices.value.join(", ")}. The site's API is unavailable for a few seconds.`, ...warnings, ]; - if (!confirm(lines.join("\n"))) return; + applyConfirmation.value = { title: "Apply environment changes", message: lines.join("\n"), confirmLabel: "Apply" }; + applyConfirmationOpen.value = true; +} + +async function confirmApply() { + applyConfirmationOpen.value = false; const body = { set: {}, generate: [] }; for (const { change } of changes.value) { @@ -377,6 +385,14 @@ onUnmounted(stopPolling); + diff --git a/vue/src/views/admin/ManagePages.vue b/vue/src/views/admin/ManagePages.vue index 825a567..6d12019 100644 --- a/vue/src/views/admin/ManagePages.vue +++ b/vue/src/views/admin/ManagePages.vue @@ -10,12 +10,23 @@ */ import { usePagesStore } from "@/stores/pages"; import PageForm from "@/views/canvas/PageForm.vue"; +import { ref } from "vue"; +import ConfirmDialog from "@/components/util/ConfirmDialog.vue"; const pages = usePagesStore(); pages.fetch(); +const removeTarget = ref(null); +const confirmationOpen = ref(false); async function remove(page) { - if (!confirm(`Delete the page “${page.title}” and everything on it?`)) return; + removeTarget.value = page; + confirmationOpen.value = true; +} + +async function confirmRemove() { + const page = removeTarget.value; + removeTarget.value = null; + if (!page) return; try { await pages.remove(page.id); } catch (err) { @@ -61,5 +72,15 @@ async function remove(page) {

New page

+ + diff --git a/vue/src/views/canvas/CanvasPage.vue b/vue/src/views/canvas/CanvasPage.vue index 494e32f..4af7c3d 100644 --- a/vue/src/views/canvas/CanvasPage.vue +++ b/vue/src/views/canvas/CanvasPage.vue @@ -19,6 +19,7 @@ import { PAGE_FIELDS, usePagesStore } from "@/stores/pages"; import BoxCanvas from "@/views/home3/BoxCanvas.vue"; import NotFound from "@/views/404/404.vue"; import PageForm from "./PageForm.vue"; +import ConfirmDialog from "@/components/util/ConfirmDialog.vue"; const route = useRoute(); const router = useRouter(); @@ -59,6 +60,7 @@ auth.ensureLoaded(); const settingsOpen = ref(false); const draft = ref({ title: "", slug: "", adminOnly: false }); const settingsError = ref(""); +const deleteConfirmationOpen = ref(false); function openSettings() { draft.value = { title: page.value.title, slug: page.value.slug, adminOnly: page.value.adminOnly }; @@ -83,7 +85,11 @@ async function saveSettings() { } async function deletePage() { - if (!confirm(`Delete the page “${page.value.title}” and everything on it?`)) return; + deleteConfirmationOpen.value = true; +} + +async function confirmDeletePage() { + deleteConfirmationOpen.value = false; try { await pages.remove(page.value.id); router.push("/"); @@ -126,6 +132,15 @@ async function deletePage() { + +