From 11125abeeba1e945461ac5d1708e89cac7bf0714 Mon Sep 17 00:00:00 2001 From: Jiayi Zheng Date: Sun, 13 Nov 2016 17:09:16 +0100 Subject: [PATCH] Implement retweet action --- src/components/retweet_button/retweet_button.js | 3 +++ src/components/retweet_button/retweet_button.vue | 2 +- src/modules/statuses.js | 9 +++++++++ 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/components/retweet_button/retweet_button.js b/src/components/retweet_button/retweet_button.js index 42da2531ff..e7318dc5f7 100644 --- a/src/components/retweet_button/retweet_button.js +++ b/src/components/retweet_button/retweet_button.js @@ -2,6 +2,9 @@ const RetweetButton = { props: [ 'status' ], methods: { retweet () { + if (!this.status.repeated) { + this.$store.dispatch('retweet', {id: this.status.id}) + } } }, computed: { diff --git a/src/components/retweet_button/retweet_button.vue b/src/components/retweet_button/retweet_button.vue index ed5cb93549..ec94356acf 100644 --- a/src/components/retweet_button/retweet_button.vue +++ b/src/components/retweet_button/retweet_button.vue @@ -1,6 +1,6 @@ diff --git a/src/modules/statuses.js b/src/modules/statuses.js index cc5e296cba..8238644d41 100644 --- a/src/modules/statuses.js +++ b/src/modules/statuses.js @@ -146,6 +146,10 @@ export const mutations = { const newStatus = find(state.allStatuses, status) newStatus.favorited = value }, + setRetweeted (state, { status, value }) { + const newStatus = find(state.allStatuses, status) + newStatus.repeated = value + }, setLoading (state, { timeline, value }) { state.timelines[timeline].loading = value }, @@ -167,6 +171,11 @@ const statuses = { // Optimistic favoriting... commit('setFavorited', { status, value: false }) 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