forked from AkkomaGang/akkoma-fe
follow requests: refactor to properly leverage vuex
This commit is contained in:
parent
fd25f68741
commit
7389f07115
3 changed files with 23 additions and 8 deletions
|
@ -1,17 +1,22 @@
|
||||||
import UserCard from '../user_card/user_card.vue'
|
import UserCard from '../user_card/user_card.vue'
|
||||||
|
|
||||||
const FollowRequests = {
|
const FollowRequests = {
|
||||||
data () {
|
|
||||||
return {
|
|
||||||
requests: []
|
|
||||||
}
|
|
||||||
},
|
|
||||||
components: {
|
components: {
|
||||||
UserCard
|
UserCard
|
||||||
},
|
},
|
||||||
created () {
|
created () {
|
||||||
this.$store.state.api.backendInteractor.fetchFollowRequests()
|
this.updateRequests()
|
||||||
.then((requests) => { this.requests = requests })
|
},
|
||||||
|
computed: {
|
||||||
|
requests () {
|
||||||
|
return this.$store.state.api.followRequests
|
||||||
|
}
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
updateRequests () {
|
||||||
|
this.$store.state.api.backendInteractor.fetchFollowRequests()
|
||||||
|
.then((requests) => { this.$store.commit('setFollowRequests', requests) })
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -20,9 +20,11 @@ const UserCard = {
|
||||||
},
|
},
|
||||||
approveUser () {
|
approveUser () {
|
||||||
this.$store.state.api.backendInteractor.approveUser(this.user.id)
|
this.$store.state.api.backendInteractor.approveUser(this.user.id)
|
||||||
|
this.$store.dispatch('removeFollowRequest', this.user)
|
||||||
},
|
},
|
||||||
denyUser () {
|
denyUser () {
|
||||||
this.$store.state.api.backendInteractor.denyUser(this.user.id)
|
this.$store.state.api.backendInteractor.denyUser(this.user.id)
|
||||||
|
this.$store.dispatch('removeFollowRequest', this.user)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,8 @@ const api = {
|
||||||
backendInteractor: backendInteractorService(),
|
backendInteractor: backendInteractorService(),
|
||||||
fetchers: {},
|
fetchers: {},
|
||||||
socket: null,
|
socket: null,
|
||||||
chatDisabled: false
|
chatDisabled: false,
|
||||||
|
followRequests: []
|
||||||
},
|
},
|
||||||
mutations: {
|
mutations: {
|
||||||
setBackendInteractor (state, backendInteractor) {
|
setBackendInteractor (state, backendInteractor) {
|
||||||
|
@ -24,6 +25,9 @@ const api = {
|
||||||
},
|
},
|
||||||
setChatDisabled (state, value) {
|
setChatDisabled (state, value) {
|
||||||
state.chatDisabled = value
|
state.chatDisabled = value
|
||||||
|
},
|
||||||
|
setFollowRequests (state, value) {
|
||||||
|
state.followRequests = value
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
actions: {
|
actions: {
|
||||||
|
@ -57,6 +61,10 @@ const api = {
|
||||||
},
|
},
|
||||||
disableChat (store) {
|
disableChat (store) {
|
||||||
store.commit('setChatDisabled', true)
|
store.commit('setChatDisabled', true)
|
||||||
|
},
|
||||||
|
removeFollowRequest (store, request) {
|
||||||
|
let requests = store.state.followRequests.filter((it) => it !== request)
|
||||||
|
store.commit('setFollowRequests', requests)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue