wire up bulk action buttons to vuex

This commit is contained in:
taehoon 2019-04-04 13:54:52 -04:00
parent 7e74a13fcf
commit 13c8f10f4b
3 changed files with 33 additions and 13 deletions

View file

@ -355,6 +355,12 @@ const UserSettings = {
this.$store.dispatch('addNewUsers', users)
return map(users, 'id')
})
},
blockUsers (ids) {
return this.$store.dispatch('blockUsers', ids)
},
unblockUsers (ids) {
return this.$store.dispatch('unblockUsers', ids)
}
}
}

View file

@ -203,13 +203,13 @@
<BlockList :refresh="true" :getKey="item => item">
<template slot="header" slot-scope="p">
<div class="bulk-actions-wrapper">
<ProgressButton class="btn btn-default" v-if="p.selected.length > 0">
<ProgressButton class="btn btn-default" v-if="p.selected.length > 0" :click="() => blockUsers(p.selected)">
{{ $t('user_card.block') }}
<template slot="progress">
{{ $t('user_card.block_progress') }}
</template>
</ProgressButton>
<ProgressButton class="btn btn-default" v-if="p.selected.length > 0">
<ProgressButton class="btn btn-default" v-if="p.selected.length > 0" :click="() => unblockUsers(p.selected)">
{{ $t('user_card.unblock') }}
<template slot="progress">
{{ $t('user_card.unblock_progress') }}

View file

@ -32,6 +32,22 @@ const getNotificationPermission = () => {
return Promise.resolve(Notification.permission)
}
const blockUser = (store, userId) => {
return store.rootState.api.backendInteractor.blockUser(userId)
.then((relationship) => {
store.commit('updateUserRelationship', [relationship])
store.commit('addBlockId', userId)
store.commit('removeStatus', { timeline: 'friends', userId })
store.commit('removeStatus', { timeline: 'public', userId })
store.commit('removeStatus', { timeline: 'publicAndExternal', userId })
})
}
const unblockUser = (store, userId) => {
return store.rootState.api.backendInteractor.unblockUser(userId)
.then((relationship) => store.commit('updateUserRelationship', [relationship]))
}
export const mutations = {
setMuted (state, { user: { id }, muted }) {
const user = state.usersObject[id]
@ -207,18 +223,16 @@ const users = {
})
},
blockUser (store, userId) {
return store.rootState.api.backendInteractor.blockUser(userId)
.then((relationship) => {
store.commit('updateUserRelationship', [relationship])
store.commit('addBlockId', userId)
store.commit('removeStatus', { timeline: 'friends', userId })
store.commit('removeStatus', { timeline: 'public', userId })
store.commit('removeStatus', { timeline: 'publicAndExternal', userId })
})
return blockUser(store, userId)
},
unblockUser (store, id) {
return store.rootState.api.backendInteractor.unblockUser(id)
.then((relationship) => store.commit('updateUserRelationship', [relationship]))
unblockUser (store, userId) {
return unblockUser(store, userId)
},
blockUsers (store, userIds = []) {
return Promise.all(userIds.map(userId => blockUser(store, userId)))
},
unblockUsers (store, userIds = []) {
return Promise.all(userIds.map(userId => unblockUser(store, userId)))
},
fetchMutes (store) {
return store.rootState.api.backendInteractor.fetchMutes()