akkoma-fe/src/modules/reports.js

39 lines
1.1 KiB
JavaScript
Raw Normal View History

2019-03-19 08:53:11 +00:00
import filter from 'lodash/filter'
const reports = {
state: {
userId: null,
statuses: [],
preTickedIds: [],
2019-03-19 08:53:11 +00:00
modalActivated: false
},
mutations: {
openUserReportingModal (state, { userId, statuses, preTickedIds }) {
2019-03-19 08:53:11 +00:00
state.userId = userId
state.statuses = statuses
state.preTickedIds = preTickedIds
2019-03-19 08:53:11 +00:00
state.modalActivated = true
},
closeUserReportingModal (state) {
state.modalActivated = false
}
},
actions: {
openUserReportingModal ({ rootState, commit }, { userId, statusIds = [] }) {
const preTickedStatuses = statusIds.map(id => rootState.statuses.allStatusesObject[id])
const preTickedIds = statusIds
const statuses = preTickedStatuses.concat(
filter(rootState.statuses.allStatuses,
status => status.user.id === userId && !preTickedIds.includes(status.id)
)
)
commit('openUserReportingModal', { userId, statuses, preTickedIds })
2019-03-19 08:53:11 +00:00
},
closeUserReportingModal ({ commit }) {
commit('closeUserReportingModal')
}
}
}
export default reports