Show error from searching

This commit is contained in:
Peter Stuifzand 2021-08-11 12:38:38 +02:00
parent c73efe8610
commit fd876591ab
2 changed files with 17 additions and 3 deletions

View File

@ -10,6 +10,7 @@
<div class="field has-addons"> <div class="field has-addons">
<div class="control is-expanded"> <div class="control is-expanded">
<input type="text" class="input is-expanded" id="query" placeholder="Search for items" v-model="query" ref="query" @keypress.enter="search"/> <input type="text" class="input is-expanded" id="query" placeholder="Search for items" v-model="query" ref="query" @keypress.enter="search"/>
<span class="error" v-text="error"></span>
</div> </div>
<div class="control"> <div class="control">
<button :class="searchClasses" @click="search">Search</button> <button :class="searchClasses" @click="search">Search</button>
@ -36,7 +37,8 @@ export default {
data() { data() {
return { return {
query: '', query: '',
loading: false loading: false,
error: ''
} }
}, },
mounted () { mounted () {
@ -62,9 +64,15 @@ export default {
methods: { methods: {
search () { search () {
this.loading = true this.loading = true
this.error = ''
this.$store.dispatch('startQuery', this.query) this.$store.dispatch('startQuery', this.query)
.then(() => { .then(result => {
this.loading = false this.loading = false
if (result.error) {
this.error = result.error
} else {
this.error = ''
}
}) })
}, },
close () { close () {

View File

@ -273,7 +273,13 @@ export default new Vuex.Store({
}) })
.then(response => response.json()) .then(response => response.json())
.then(response => { .then(response => {
commit('newSearchResults', response.items) if (response.items) {
commit('newSearchResults', response.items)
return { error: false }
} else {
commit('newSearchResults', [])
return { error: response.error }
}
}) })
}, },
createChannel(x, name) { createChannel(x, name) {