From 7389f071151d271187b3236a4f56ebfdc018c289 Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Thu, 7 Jun 2018 01:24:31 +0000 Subject: [PATCH] follow requests: refactor to properly leverage vuex --- .../follow_requests/follow_requests.js | 19 ++++++++++++------- src/components/user_card/user_card.js | 2 ++ src/modules/api.js | 10 +++++++++- 3 files changed, 23 insertions(+), 8 deletions(-) diff --git a/src/components/follow_requests/follow_requests.js b/src/components/follow_requests/follow_requests.js index 9fe4a57e..11a228aa 100644 --- a/src/components/follow_requests/follow_requests.js +++ b/src/components/follow_requests/follow_requests.js @@ -1,17 +1,22 @@ import UserCard from '../user_card/user_card.vue' const FollowRequests = { - data () { - return { - requests: [] - } - }, components: { UserCard }, created () { - this.$store.state.api.backendInteractor.fetchFollowRequests() - .then((requests) => { this.requests = requests }) + this.updateRequests() + }, + computed: { + requests () { + return this.$store.state.api.followRequests + } + }, + methods: { + updateRequests () { + this.$store.state.api.backendInteractor.fetchFollowRequests() + .then((requests) => { this.$store.commit('setFollowRequests', requests) }) + } } } diff --git a/src/components/user_card/user_card.js b/src/components/user_card/user_card.js index f47df0eb..a019627a 100644 --- a/src/components/user_card/user_card.js +++ b/src/components/user_card/user_card.js @@ -20,9 +20,11 @@ const UserCard = { }, approveUser () { this.$store.state.api.backendInteractor.approveUser(this.user.id) + this.$store.dispatch('removeFollowRequest', this.user) }, denyUser () { this.$store.state.api.backendInteractor.denyUser(this.user.id) + this.$store.dispatch('removeFollowRequest', this.user) } } } diff --git a/src/modules/api.js b/src/modules/api.js index c91fb97b..a61340c2 100644 --- a/src/modules/api.js +++ b/src/modules/api.js @@ -7,7 +7,8 @@ const api = { backendInteractor: backendInteractorService(), fetchers: {}, socket: null, - chatDisabled: false + chatDisabled: false, + followRequests: [] }, mutations: { setBackendInteractor (state, backendInteractor) { @@ -24,6 +25,9 @@ const api = { }, setChatDisabled (state, value) { state.chatDisabled = value + }, + setFollowRequests (state, value) { + state.followRequests = value } }, actions: { @@ -57,6 +61,10 @@ const api = { }, disableChat (store) { store.commit('setChatDisabled', true) + }, + removeFollowRequest (store, request) { + let requests = store.state.followRequests.filter((it) => it !== request) + store.commit('setFollowRequests', requests) } } }