improve error handling logic

This commit is contained in:
taehoon 2019-04-27 09:36:10 -04:00
parent 12f8269f01
commit 2af088969a
3 changed files with 11 additions and 5 deletions

View file

@ -25,11 +25,14 @@ const ExtraButtons = {
pinStatus () { pinStatus () {
this.refreshPopper() this.refreshPopper()
this.$store.dispatch('pinStatus', this.status.id) this.$store.dispatch('pinStatus', this.status.id)
.then(() => this.$emit('onSuccess'))
.catch(err => this.$emit('onError', err.error.error)) .catch(err => this.$emit('onError', err.error.error))
}, },
unpinStatus () { unpinStatus () {
this.refreshPopper() this.refreshPopper()
this.$store.dispatch('unpinStatus', this.status.id) this.$store.dispatch('unpinStatus', this.status.id)
.then(() => this.$emit('onSuccess'))
.catch(err => this.$emit('onError', err.error.error))
}, },
refreshPopper () { refreshPopper () {
this.showPopper = false this.showPopper = false

View file

@ -302,9 +302,9 @@ const Status = {
}, },
showError (error) { showError (error) {
this.error = error this.error = error
setTimeout(() => { },
this.error = null clearError () {
}, 5000) this.error = undefined
}, },
linkClicked (event) { linkClicked (event) {
let { target } = event let { target } = event

View file

@ -1,6 +1,9 @@
<template> <template>
<div class="status-el" v-if="!hideStatus" :class="[{ 'status-el_focused': isFocused }, { 'status-conversation': inlineExpanded }]"> <div class="status-el" v-if="!hideStatus" :class="[{ 'status-el_focused': isFocused }, { 'status-conversation': inlineExpanded }]">
<div v-if="error" class="alert error">{{error}}</div> <div v-if="error" class="alert error">
{{error}}
<i class="button-icon icon-cancel" @click="clearError"></i>
</div>
<template v-if="muted && !isPreview"> <template v-if="muted && !isPreview">
<div class="media status container muted"> <div class="media status container muted">
<small> <small>
@ -169,7 +172,7 @@
</div> </div>
<retweet-button :visibility='status.visibility' :loggedIn='loggedIn' :status='status'></retweet-button> <retweet-button :visibility='status.visibility' :loggedIn='loggedIn' :status='status'></retweet-button>
<favorite-button :loggedIn='loggedIn' :status='status'></favorite-button> <favorite-button :loggedIn='loggedIn' :status='status'></favorite-button>
<extra-buttons :status="status" @onError="showError"></extra-buttons> <extra-buttons :status="status" @onError="showError" @onSuccess="clearError"></extra-buttons>
</div> </div>
</div> </div>
</div> </div>