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 42da2531..e7318dc5 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 ed5cb935..ec94356a 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 cc5e296c..8238644d 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