errors: add dismissable error banners

This commit is contained in:
Chris Sexton 2019-10-28 07:56:13 -04:00
parent c790365a98
commit 011d1fb121
6 changed files with 41 additions and 24 deletions

View File

@ -7,7 +7,7 @@ frontend:
frontend-watch:
cd frontend && yarn build --watch
run: build
run: *.go
./happy -develop
.PHONY: run frontend frontend-watch

View File

@ -3,8 +3,8 @@
<b-navbar type="dark" variant="info">
<b-navbar-brand>Happy</b-navbar-brand>
</b-navbar>
<div v-show="err">{{err}}</div>
<user-info class="fixed-bottom userInfo"/>
<Error/>
<h1 class="question">How are you?</h1>
<Chooser class="chooser"/>
</div>
@ -13,18 +13,15 @@
<script>
import Chooser from './components/Chooser.vue'
import UserInfo from "./components/UserInfo";
import {mapState} from 'vuex';
import Error from "./components/Error";
export default {
name: 'app',
components: {
Chooser,
UserInfo
},
computed: mapState({
userInfo: state => state.userInfo,
err: state => state.err
}),
UserInfo,
Error
}
}
</script>

View File

@ -10,7 +10,10 @@
},
methods: {
click: function(e) {
this.$emit('selected', e, this.mood)
this.$emit('selected', e, this.$store.dispatch("setMood", this.mood)
.catch(resp => {
this.$store.commit('addError', resp.message);
}));
}
}
}

View File

@ -4,7 +4,6 @@
v-bind:key="mood.key"
v-bind:index="index"
:mood="mood"
v-on:selected="doIt"
/>
</div>
</template>
@ -20,15 +19,7 @@
},
computed: mapState({
moods: state => state.moods
}),
methods: {
doIt: function(e, mood) {
this.$store.dispatch("setMood", mood)
.catch(resp => {
this.$store.commit('setError', resp.message);
})
}
}
})
}
</script>

View File

@ -0,0 +1,26 @@
<template>
<div>
<b-alert
v-for="(e, i) in errs"
v-bind:key="i"
variant="danger"
dismissible
show="true"
v-show="errs.length > 0">{{e}}</b-alert>
</div>
</template>
<script>
import {mapState} from 'vuex';
export default {
name: "Error",
computed: mapState({
userInfo: state => state.userInfo,
errs: state => state.errs
}),
}
</script>
<style scoped>
</style>

View File

@ -7,7 +7,7 @@ Vue.use(Vuex);
const store = new Vuex.Store({
state: {
err: null,
errs: [],
userInfo: null,
moods: [],
},
@ -36,10 +36,10 @@ const store = new Vuex.Store({
state.moods = moods;
},
clearError(state) {
state.err = null
state.errs = []
},
setError(state, err) {
state.err = err
addError(state, err) {
state.errs.push(err)
}
}
});