File tree Expand file tree Collapse file tree 3 files changed +130
-16
lines changed Expand file tree Collapse file tree 3 files changed +130
-16
lines changed Original file line number Diff line number Diff line change
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 & ; 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 >
Original file line number Diff line number Diff line change @@ -25,6 +25,7 @@ import {INote} from '../interfaces';
25
25
26
26
import Editor from ' @/components/Editor.vue' ;
27
27
import Header from ' @/components/Header.vue' ;
28
+ import UnsavedForm from ' @/components/UnsavedForm.vue' ;
28
29
29
30
import {IHeaderOptions } from ' ../interfaces' ;
30
31
@@ -254,14 +255,23 @@ export default class Day extends Vue {
254
255
}
255
256
256
257
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
+ }
265
275
});
266
276
}
267
277
}
Original file line number Diff line number Diff line change @@ -18,6 +18,7 @@ import {INote} from '../interfaces';
18
18
19
19
import Editor from ' @/components/Editor.vue' ;
20
20
import Header from ' @/components/Header.vue' ;
21
+ import UnsavedForm from ' @/components/UnsavedForm.vue' ;
21
22
22
23
import {IHeaderOptions } from ' ../interfaces' ;
23
24
@@ -90,14 +91,23 @@ export default class NewNote extends Vue {
90
91
91
92
beforeRouteLeave(to : Route , from : Route , next : Function ) {
92
93
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
+ }
101
111
});
102
112
} else {
103
113
next ();
You can’t perform that action at this time.
0 commit comments