Skip to content

Commit 66d7445

Browse files
committed
Merge branch 'unsaved-dialog'
2 parents 9b4e172 + 362c0e3 commit 66d7445

File tree

3 files changed

+130
-16
lines changed

3 files changed

+130
-16
lines changed

client/src/components/UnsavedForm.vue

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
<template>
2+
<transition>
3+
<div v-if="isActive" class="dialog modal is-active">
4+
<div class="modal-background" @click="cancel('outside')" />
5+
<div class="modal-card animation-content">
6+
<header class="modal-card-head">
7+
<p class="modal-card-title">Unsaved Content</p>
8+
</header>
9+
10+
<section class="modal-card-body is-flex">
11+
<div class="media">
12+
<div class="media-left">
13+
<b-icon
14+
icon="alert"
15+
type="is-warning"
16+
:both="true"
17+
size="is-large"
18+
/>
19+
</div>
20+
<div class="media-content">
21+
<p>
22+
<template>
23+
<div>
24+
You have unsaved changes changes. What would you like to do?
25+
</div>
26+
</template>
27+
</p>
28+
</div>
29+
</div>
30+
</section>
31+
32+
<footer class="modal-card-foot">
33+
<b-button ref="cancelButton" @click="cancel('button')"
34+
>Cancel</b-button
35+
>
36+
<b-button type="is-warning" ref="discardButton" @click="discard"
37+
>Discard</b-button
38+
>
39+
<b-button
40+
type="is-primary"
41+
ref="saveButton"
42+
class="is-focused"
43+
@click="save"
44+
>Save &amp; Continue</b-button
45+
>
46+
</footer>
47+
</div>
48+
</div>
49+
</transition>
50+
</template>
51+
52+
<script lang="ts">
53+
import Vue from "vue";
54+
import Component from "vue-class-component";
55+
56+
@Component
57+
export default class UnsavedForm extends Vue {
58+
public isActive: boolean = false;
59+
60+
mounted() {
61+
this.isActive = true;
62+
if (typeof window !== "undefined") {
63+
document.addEventListener("keyup", this.keyPress);
64+
}
65+
}
66+
67+
beforeDestroy() {
68+
if (typeof window !== "undefined") {
69+
document.removeEventListener("keyup", this.keyPress);
70+
}
71+
}
72+
73+
keyPress({ key }) {
74+
if (key == "Enter") {
75+
this.save();
76+
}
77+
}
78+
79+
cancel() {
80+
this.$emit("cancel");
81+
this.$emit("close");
82+
}
83+
84+
discard() {
85+
this.$emit("close");
86+
this.$emit("discard");
87+
}
88+
89+
save() {
90+
this.$emit("close");
91+
this.$emit("save");
92+
}
93+
}
94+
</script>

client/src/views/Day.vue

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import {INote} from '../interfaces';
2525
2626
import Editor from '@/components/Editor.vue';
2727
import Header from '@/components/Header.vue';
28+
import UnsavedForm from '@/components/UnsavedForm.vue';
2829
2930
import {IHeaderOptions} from '../interfaces';
3031
@@ -254,14 +255,23 @@ export default class Day extends Vue {
254255
}
255256
256257
async unsavedDialog(next: Function) {
257-
this.$buefy.dialog.confirm({
258-
title: "Unsaved Content",
259-
message: "Are you sure you want to discard the unsaved content?",
260-
confirmText: "Discard",
261-
type: "is-warning",
262-
hasIcon: true,
263-
onConfirm: () => next(),
264-
onCancel: () => next(false)
258+
this.$buefy.modal.open({
259+
parent: this,
260+
component: UnsavedForm,
261+
hasModalCard: true,
262+
trapFocus: true,
263+
events: {
264+
cancel: () => {
265+
next(false);
266+
},
267+
discard: () => {
268+
next();
269+
},
270+
save: () => {
271+
this.saveDay();
272+
next();
273+
}
274+
}
265275
});
266276
}
267277
}

client/src/views/NewNote.vue

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import {INote} from '../interfaces';
1818
1919
import Editor from '@/components/Editor.vue';
2020
import Header from '@/components/Header.vue';
21+
import UnsavedForm from '@/components/UnsavedForm.vue';
2122
2223
import {IHeaderOptions} from '../interfaces';
2324
@@ -90,14 +91,23 @@ export default class NewNote extends Vue {
9091
9192
beforeRouteLeave(to: Route, from: Route, next: Function) {
9293
if (this.unsavedChanges) {
93-
this.$buefy.dialog.confirm({
94-
title: "Unsaved Content",
95-
message: "Are you sure you want to discard the unsaved content?",
96-
confirmText: "Discard",
97-
type: "is-warning",
98-
hasIcon: true,
99-
onConfirm: () => next(),
100-
onCancel: () => next(false)
94+
this.$buefy.modal.open({
95+
parent: this,
96+
component: UnsavedForm,
97+
hasModalCard: true,
98+
trapFocus: true,
99+
events: {
100+
cancel: () => {
101+
next(false);
102+
},
103+
discard: () => {
104+
next();
105+
},
106+
save: () => {
107+
this.saveNote();
108+
next();
109+
}
110+
}
101111
});
102112
} else {
103113
next();

0 commit comments

Comments
 (0)