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) this.$store.dispatch('addNewUsers', users)
return map(users, 'id') 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"> <BlockList :refresh="true" :getKey="item => item">
<template slot="header" slot-scope="p"> <template slot="header" slot-scope="p">
<div class="bulk-actions-wrapper"> <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') }} {{ $t('user_card.block') }}
<template slot="progress"> <template slot="progress">
{{ $t('user_card.block_progress') }} {{ $t('user_card.block_progress') }}
</template> </template>
</ProgressButton> </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') }} {{ $t('user_card.unblock') }}
<template slot="progress"> <template slot="progress">
{{ $t('user_card.unblock_progress') }} {{ $t('user_card.unblock_progress') }}

View file

@ -32,6 +32,22 @@ const getNotificationPermission = () => {
return Promise.resolve(Notification.permission) 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 = { export const mutations = {
setMuted (state, { user: { id }, muted }) { setMuted (state, { user: { id }, muted }) {
const user = state.usersObject[id] const user = state.usersObject[id]
@ -207,18 +223,16 @@ const users = {
}) })
}, },
blockUser (store, userId) { blockUser (store, userId) {
return store.rootState.api.backendInteractor.blockUser(userId) return blockUser(store, 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 })
})
}, },
unblockUser (store, id) { unblockUser (store, userId) {
return store.rootState.api.backendInteractor.unblockUser(id) return unblockUser(store, userId)
.then((relationship) => store.commit('updateUserRelationship', [relationship])) },
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) { fetchMutes (store) {
return store.rootState.api.backendInteractor.fetchMutes() return store.rootState.api.backendInteractor.fetchMutes()