Implement retweet action

This commit is contained in:
Jiayi Zheng 2016-11-13 17:09:16 +01:00
parent 242ae8e91b
commit 11125abeeb
3 changed files with 13 additions and 1 deletions

View file

@ -2,6 +2,9 @@ const RetweetButton = {
props: [ 'status' ], props: [ 'status' ],
methods: { methods: {
retweet () { retweet () {
if (!this.status.repeated) {
this.$store.dispatch('retweet', {id: this.status.id})
}
} }
}, },
computed: { computed: {

View file

@ -1,6 +1,6 @@
<template> <template>
<div> <div>
<i :class='classes' class='icon-retweet fa' v-on:click.prevent=''></i> <i :class='classes' class='icon-retweet fa' v-on:click.prevent='retweet()'></i>
<span v-if='status.repeat_num > 0'>{{status.repeat_num}}</span> <span v-if='status.repeat_num > 0'>{{status.repeat_num}}</span>
</div> </div>
</template> </template>

View file

@ -146,6 +146,10 @@ export const mutations = {
const newStatus = find(state.allStatuses, status) const newStatus = find(state.allStatuses, status)
newStatus.favorited = value newStatus.favorited = value
}, },
setRetweeted (state, { status, value }) {
const newStatus = find(state.allStatuses, status)
newStatus.repeated = value
},
setLoading (state, { timeline, value }) { setLoading (state, { timeline, value }) {
state.timelines[timeline].loading = value state.timelines[timeline].loading = value
}, },
@ -167,6 +171,11 @@ const statuses = {
// Optimistic favoriting... // Optimistic favoriting...
commit('setFavorited', { status, value: false }) commit('setFavorited', { status, value: false })
apiService.unfavorite({ id: status.id, credentials: rootState.users.currentUser.credentials }) apiService.unfavorite({ id: status.id, credentials: rootState.users.currentUser.credentials })
},
retweet ({ rootState, commit }, status) {
// Optimistic retweeting...
commit('setRetweeted', { status, value: true })
apiService.retweet({ id: status.id, credentials: rootState.users.currentUser.credentials })
} }
}, },
mutations mutations