Skip to content

Commit

Permalink
Add Confirmation Dialog (#155)
Browse files Browse the repository at this point in the history
  • Loading branch information
hateofhades authored Nov 6, 2024
1 parent 41af0ba commit c2ea61d
Show file tree
Hide file tree
Showing 6 changed files with 123 additions and 29 deletions.
3 changes: 3 additions & 0 deletions src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
>
{{ snackbar.text }}
</v-snackbar>
<DialogComponent />
</v-app>
</template>

Expand All @@ -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";
Expand All @@ -31,6 +33,7 @@ export default defineComponent({
components: {
SidebarComponent,
TopbarComponent,
DialogComponent
},
data() {
return {
Expand Down
15 changes: 15 additions & 0 deletions src/components/DialogComponent.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<template>
<ConfirmationDialog />
</template>

<script lang="ts">
import { defineComponent } from 'vue';
import ConfirmationDialog from './Dialogs/ConfirmationDialog.vue';
export default defineComponent({
name: 'DialogComponent',
components: {
ConfirmationDialog
}
})
</script>
51 changes: 51 additions & 0 deletions src/components/Dialogs/ConfirmationDialog.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<template>
<v-dialog
v-model="isShowing"
persistent
>
<v-card>
<v-card-title class="headline">
{{ confirmationDialog.title }}
</v-card-title>
<v-card-text>{{ confirmationDialog.message }}</v-card-text>
<v-card-actions>
<v-spacer />
<v-btn
rounded
@click="isShowing = false"
>
Cancel
</v-btn>
<v-btn
rounded
@click="confirmationDialog.onConfirm"
>
Confirm
</v-btn>
</v-card-actions>
</v-card>
</v-dialog>
</template>

<script lang="ts">
import { defineComponent } from 'vue';
import { useDialogStore } from '../../stores/dialogs';
import { mapState } from 'pinia';
export default defineComponent({
name: 'ConfirmationDialog',
computed: {
isShowing: {
get() {
return this.confirmationDialog.isOpen;
},
set(value: boolean) {
if (value === false) {
useDialogStore().closeConfirmationDialog();
}
}
},
...mapState(useDialogStore, ["confirmationDialog"])
}
})
</script>
39 changes: 11 additions & 28 deletions src/components/SidebarComponent.vue
Original file line number Diff line number Diff line change
Expand Up @@ -36,36 +36,10 @@
:subtitle="appVersion"
append-icon="mdi-power"
append-color="red"
@append-click="showExitDialog = true"
@append-click="confirmExit"
/>
</v-list>
</v-navigation-drawer>
<v-dialog
v-model="showExitDialog"
persistent
>
<v-card>
<v-card-title class="headline">
Exit Application
</v-card-title>
<v-card-text>Are you sure you want to exit the application?</v-card-text>
<v-card-actions>
<v-spacer />
<v-btn
rounded
@click="showExitDialog = false"
>
Cancel
</v-btn>
<v-btn
rounded
@click="exit(0)"
>
Exit
</v-btn>
</v-card-actions>
</v-card>
</v-dialog>
</template>

<script lang="ts">
Expand All @@ -76,6 +50,7 @@ import { defineComponent } from "vue";
import { PrependVariant } from "../enums/prependVariant";
import { useAppStore } from "../stores/app";
import SidebarItem from "./Sidebar/SidebarItem.vue";
import { useDialogStore } from "../stores/dialogs";
export default defineComponent({
name: "SidebarComponent",
Expand Down Expand Up @@ -122,7 +97,15 @@ export default defineComponent({
console.error(e);
}
},
exit
confirmExit() {
useDialogStore().openConfirmationDialog({
title: "Exit",
message: "Are you sure you want to exit?",
onConfirm: () => {
exit();
},
});
}
}
});
</script>
11 changes: 10 additions & 1 deletion src/stores/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
33 changes: 33 additions & 0 deletions src/stores/dialogs.ts
Original file line number Diff line number Diff line change
@@ -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;
}
}
});

0 comments on commit c2ea61d

Please sign in to comment.