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: frontend-watch:
cd frontend && yarn build --watch cd frontend && yarn build --watch
run: build run: *.go
./happy -develop ./happy -develop
.PHONY: run frontend frontend-watch .PHONY: run frontend frontend-watch

View File

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

View File

@ -10,7 +10,10 @@
}, },
methods: { methods: {
click: function(e) { 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:key="mood.key"
v-bind:index="index" v-bind:index="index"
:mood="mood" :mood="mood"
v-on:selected="doIt"
/> />
</div> </div>
</template> </template>
@ -20,15 +19,7 @@
}, },
computed: mapState({ computed: mapState({
moods: state => state.moods moods: state => state.moods
}), })
methods: {
doIt: function(e, mood) {
this.$store.dispatch("setMood", mood)
.catch(resp => {
this.$store.commit('setError', resp.message);
})
}
}
} }
</script> </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({ const store = new Vuex.Store({
state: { state: {
err: null, errs: [],
userInfo: null, userInfo: null,
moods: [], moods: [],
}, },
@ -36,10 +36,10 @@ const store = new Vuex.Store({
state.moods = moods; state.moods = moods;
}, },
clearError(state) { clearError(state) {
state.err = null state.errs = []
}, },
setError(state, err) { addError(state, err) {
state.err = err state.errs.push(err)
} }
} }
}); });