@@ -8,7 +8,6 @@ export default new Vuex.Store({
88 state : {
99 serialPorts : [ ] ,
1010 active : false ,
11- successSetMessage : null ,
1211 changedTab : null ,
1312 static : { } ,
1413 config : { } ,
@@ -18,6 +17,12 @@ export default new Vuex.Store({
1817 rec_speed : { } ,
1918 rec_elements : { } ,
2019 } ,
20+ snackbar : {
21+ isVisible : false ,
22+ message : "" ,
23+ color : "success" ,
24+ timeout : 3000 ,
25+ } ,
2126 } ,
2227 mutations : {
2328 SET_SERIAL_PORTS ( state , ports ) {
@@ -56,8 +61,18 @@ export default new Vuex.Store({
5661 REMOVE_EVENT_ACTION ( state , { key, index } ) {
5762 state . events [ key ] . actions . splice ( index , 1 ) ;
5863 } ,
59- SET_SUCCESS_MESSAGE ( state , value ) {
60- state . successSetMessage = value ;
64+ SET_SNACKBAR_PROPS ( state , payload ) {
65+ state . snackbar = { ...state . snackbar , ...payload } ;
66+ } ,
67+ SHOW_SNACKBAR ( state , { message, color = "success" , timeout = 3000 } ) {
68+ state . snackbar . isVisible = true ;
69+ state . snackbar . message = message ;
70+ state . snackbar . color = color ;
71+ state . snackbar . timeout = timeout ;
72+ } ,
73+ HIDE_SNACKBAR ( state ) {
74+ state . snackbar . isVisible = false ;
75+ state . snackbar . message = "" ;
6176 } ,
6277 } ,
6378 actions : {
@@ -74,8 +89,8 @@ export default new Vuex.Store({
7489 if ( ! payload . key ) return ;
7590
7691 payload . name = CONFIG_SETTINGS [ payload . key ]
77- ? CONFIG_SETTINGS [ payload . key ] . name
78- : null ;
92+ ? CONFIG_SETTINGS [ payload . key ] . name
93+ : null ;
7994
8095 payload . unit = CONFIG_SETTINGS [ payload . key ]
8196 ? CONFIG_SETTINGS [ payload . key ] . unit
@@ -120,9 +135,11 @@ export default new Vuex.Store({
120135 removeEventAction ( { commit } , payload ) {
121136 commit ( "REMOVE_EVENT_ACTION" , payload ) ;
122137 } ,
123- setSuccessMessage ( { commit } , value ) {
124- commit ( "SET_SUCCESS_MESSAGE" , value ) ;
125- setTimeout ( ( ) => commit ( "SET_SUCCESS_MESSAGE" , null ) , 5000 ) ;
138+ showSuccessSnackbar ( { commit } , message ) {
139+ commit ( "SHOW_SNACKBAR" , { message, color : "success" } ) ;
140+ } ,
141+ hideSnackbar ( { commit } ) {
142+ commit ( "HIDE_SNACKBAR" ) ;
126143 } ,
127144 } ,
128145 getters : {
@@ -144,5 +161,8 @@ export default new Vuex.Store({
144161
145162 return changed ;
146163 } ,
164+ snackbarState ( state ) {
165+ return state . snackbar ;
166+ } ,
147167 } ,
148168} ) ;
0 commit comments