Skip to content

Commit d682985

Browse files
committed
Add Snackbar component and use it to display success messages
1 parent e754a7a commit d682985

File tree

7 files changed

+90
-32
lines changed

7 files changed

+90
-32
lines changed

.gitignore

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ pnpm-debug.log*
2222
*.sln
2323
*.sw?
2424

25-
#Electron-builder output
25+
# Electron-builder output
2626
/dist_electron
27-
/builds
27+
/builds
28+
29+
# Exports
30+
flight-log-export
31+
plots.html

src/App.vue

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
<v-app>
33
<AppBar />
44
<NavPanel :items="navItems" />
5+
<Snackbar />
56
<Footer />
67

78
<v-main>
@@ -11,16 +12,18 @@
1112
</template>
1213

1314
<script>
14-
import { mapState, mapActions } from "vuex";
15+
import { mapActions } from "vuex";
1516
import AppBar from "@/components/AppBar";
1617
import NavPanel from "@/components/NavigationPanel";
18+
import Snackbar from "@/components/Snackbar";
1719
import Footer from "@/components/Footer";
1820
1921
export default {
2022
name: "App",
2123
components: {
2224
AppBar,
2325
NavPanel,
26+
Snackbar,
2427
Footer,
2528
},
2629
data() {
@@ -34,11 +37,6 @@ export default {
3437
],
3538
};
3639
},
37-
computed: {
38-
...mapState({
39-
successSetMessage: (state) => state.successSetMessage,
40-
}),
41-
},
4240
mounted() {
4341
if (this.$route.path !== "/") this.$router.push("/");
4442
@@ -59,8 +57,7 @@ export default {
5957
else this.setConfig(config);
6058
});
6159
window.renderer.on("SET_CONFIG_RESPONSE", () => {
62-
if (this.successSetMessage) return;
63-
this.setSuccessMessage("Values saved successfully!");
60+
this.showSuccessSnackbar("Values saved successfully!");
6461
});
6562
},
6663
methods: {
@@ -71,7 +68,7 @@ export default {
7168
"setEvent",
7269
"setTimer",
7370
"setLog",
74-
"setSuccessMessage",
71+
"showSuccessSnackbar",
7572
]),
7673
},
7774
};

src/components/ActionsBar.vue

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
<template>
22
<v-app-bar flat dense absolute bottom>
3-
<div v-if="message">
4-
<v-icon color="success" class="mr-2">mdi-check-circle-outline</v-icon>
5-
<span v-text="message" class="success--text caption" />
6-
</div>
73
<v-spacer></v-spacer>
84
<div>
95
<v-btn class="mr-2" @click="$emit('refresh')"> Refresh </v-btn>
@@ -13,15 +9,8 @@
139
</template>
1410

1511
<script>
16-
import { mapState } from "vuex";
17-
1812
export default {
1913
name: "ActionsBar",
20-
computed: {
21-
...mapState({
22-
message: (state) => state.successSetMessage,
23-
}),
24-
},
2514
};
2615
</script>
2716

src/components/Snackbar.vue

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<template>
2+
<v-snackbar
3+
v-model="snackbarState.isVisible"
4+
:color="snackbarState.color"
5+
:timeout="snackbarState.timeout"
6+
@input="handleSnackbarInput"
7+
bottom
8+
>
9+
{{ snackbarState.message }}
10+
11+
<template v-slot:action="{ attrs }">
12+
<v-btn
13+
text
14+
v-bind="attrs"
15+
@click="hideSnackbar"
16+
>
17+
<v-icon>mdi-close</v-icon>
18+
</v-btn>
19+
</template>
20+
</v-snackbar>
21+
</template>
22+
23+
<script>
24+
import { mapGetters, mapActions } from "vuex";
25+
26+
export default {
27+
name: "Snackbar",
28+
computed: {
29+
...mapGetters([ "snackbarState" ]),
30+
},
31+
methods: {
32+
...mapActions([ "hideSnackbar" ]),
33+
handleSnackbarInput(value) {
34+
if (!value) {
35+
this.hideSnackbar();
36+
}
37+
}
38+
}
39+
};
40+
</script>

src/store/index.js

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -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
});

src/views/Config.vue

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,10 @@ export default {
330330
},
331331
mounted() {
332332
this.init();
333-
window.renderer.on("BOARD:DUMP", () => (this.backupLoading = false));
333+
window.renderer.on("BOARD:DUMP", () => {
334+
this.backupLoading = false
335+
this.showSuccessSnackbar("Backup created!");
336+
});
334337
window.renderer.on("BOARD:RESTORE", () => {
335338
this.restoreLoading = false;
336339
setTimeout(this.init, 100);
@@ -346,7 +349,7 @@ export default {
346349
clearInterval(this.timer);
347350
},
348351
methods: {
349-
...mapActions(["setChangedTab"]),
352+
...mapActions(["setChangedTab", "showSuccessSnackbar"]),
350353
init() {
351354
getConfigs();
352355
this.getInfo();

src/views/Home.vue

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@
6969
</template>
7070

7171
<script>
72+
import { mapActions } from "vuex";
7273
import { makePlots } from '../modules/plots'
7374
7475
export default {
@@ -98,17 +99,21 @@ export default {
9899
}
99100
this.errorString = "";
100101
this.flightLog = flightLog;
102+
this.showSuccessSnackbar("Flight logs loaded successfully!");
101103
102104
if (el) makePlots(flightLog, el)
103105
});
104106
window.renderer.on("EXPORT_FLIGHTLOG_CSVS", (flightLog) => {
105107
this.exportButtonLoading = false;
108+
this.showSuccessSnackbar("Exported flight log CSVs!");
106109
});
107110
window.renderer.on("EXPORT_FLIGHTLOG_HTML", (flightLog) => {
108111
this.exportButtonLoading = false;
112+
this.showSuccessSnackbar("Exported flight log HTML charts!");
109113
});
110114
},
111115
methods: {
116+
...mapActions(["showSuccessSnackbar"]),
112117
loadFlightLog(file) {
113118
this.loadButtonLoading = true;
114119
this.flightLog = null

0 commit comments

Comments
 (0)