From c2ea61d0442bf6606f8256a37e2ea46bae0fc472 Mon Sep 17 00:00:00 2001 From: Andrei Serban Date: Wed, 6 Nov 2024 14:38:33 +0200 Subject: [PATCH] Add Confirmation Dialog (#155) --- src/App.vue | 3 ++ src/components/DialogComponent.vue | 15 ++++++ src/components/Dialogs/ConfirmationDialog.vue | 51 +++++++++++++++++++ src/components/SidebarComponent.vue | 39 ++++---------- src/stores/app.ts | 11 +++- src/stores/dialogs.ts | 33 ++++++++++++ 6 files changed, 123 insertions(+), 29 deletions(-) create mode 100644 src/components/DialogComponent.vue create mode 100644 src/components/Dialogs/ConfirmationDialog.vue create mode 100644 src/stores/dialogs.ts diff --git a/src/App.vue b/src/App.vue index bf2a5f3..9712517 100644 --- a/src/App.vue +++ b/src/App.vue @@ -12,6 +12,7 @@ > {{ snackbar.text }} + @@ -20,6 +21,7 @@ import { invoke } from "@tauri-apps/api/core"; import { listen, UnlistenFn } from "@tauri-apps/api/event"; import { mapState } from "pinia"; import { defineComponent, provide } from "vue"; +import DialogComponent from "./components/DialogComponent.vue"; import SidebarComponent from "./components/SidebarComponent.vue"; import TopbarComponent from "./components/TopbarComponent.vue"; import { useAppStore } from "./stores/app"; @@ -31,6 +33,7 @@ export default defineComponent({ components: { SidebarComponent, TopbarComponent, + DialogComponent }, data() { return { diff --git a/src/components/DialogComponent.vue b/src/components/DialogComponent.vue new file mode 100644 index 0000000..e396743 --- /dev/null +++ b/src/components/DialogComponent.vue @@ -0,0 +1,15 @@ + + + diff --git a/src/components/Dialogs/ConfirmationDialog.vue b/src/components/Dialogs/ConfirmationDialog.vue new file mode 100644 index 0000000..b9f1510 --- /dev/null +++ b/src/components/Dialogs/ConfirmationDialog.vue @@ -0,0 +1,51 @@ + + + diff --git a/src/components/SidebarComponent.vue b/src/components/SidebarComponent.vue index 8af5bed..12781ec 100644 --- a/src/components/SidebarComponent.vue +++ b/src/components/SidebarComponent.vue @@ -36,36 +36,10 @@ :subtitle="appVersion" append-icon="mdi-power" append-color="red" - @append-click="showExitDialog = true" + @append-click="confirmExit" /> - - - - Exit Application - - Are you sure you want to exit the application? - - - - Cancel - - - Exit - - - - diff --git a/src/stores/app.ts b/src/stores/app.ts index 2af9df8..138e5b2 100644 --- a/src/stores/app.ts +++ b/src/stores/app.ts @@ -3,8 +3,17 @@ import { defineStore } from "pinia"; import { IGitProject } from "../types/gitProject"; import { DEFAULT_USER } from "../types/user"; +interface IAppState { + title: string; + user: typeof DEFAULT_USER; + projects: IGitProject[]; + isNavbarOpen: boolean; + selectedProject: IGitProject | null; + appVersion: string; +} + export const useAppStore = defineStore('app', { - state: () => ( + state: (): IAppState => ( { title: "BranchWise", user: DEFAULT_USER, diff --git a/src/stores/dialogs.ts b/src/stores/dialogs.ts new file mode 100644 index 0000000..f897e36 --- /dev/null +++ b/src/stores/dialogs.ts @@ -0,0 +1,33 @@ +import { defineStore } from "pinia"; + +interface IDialogState { + confirmationDialog: { + isOpen: boolean; + title: string; + message: string; + onConfirm: () => void; + } +} + +export const useDialogStore = defineStore('dialog', { + state: (): IDialogState => ( + { + confirmationDialog: { + isOpen: false, + title: "", + message: "", + onConfirm: () => { } + } + }), + actions: { + openConfirmationDialog({title, message, onConfirm}: {title: string, message: string, onConfirm: () => void}) { + this.confirmationDialog.isOpen = true; + this.confirmationDialog.title = title; + this.confirmationDialog.message = message; + this.confirmationDialog.onConfirm = onConfirm; + }, + closeConfirmationDialog() { + this.confirmationDialog.isOpen = false; + } + } +});