yandere_fe/src/modules/reports.js

65 lines
2.0 KiB
JavaScript
Raw Normal View History

2019-03-19 01:53:11 -07:00
import filter from 'lodash/filter'
const reports = {
state: {
2021-01-18 05:26:08 -08:00
reportModal: {
userId: null,
statuses: [],
preTickedIds: [],
activated: false
},
reports: {}
2019-03-19 01:53:11 -07:00
},
mutations: {
openUserReportingModal (state, { userId, statuses, preTickedIds }) {
2021-01-18 05:26:08 -08:00
state.reportModal.userId = userId
state.reportModal.statuses = statuses
state.reportModal.preTickedIds = preTickedIds
state.reportModal.activated = true
2019-03-19 01:53:11 -07:00
},
closeUserReportingModal (state) {
state.reportModal.activated = false
2021-01-18 05:26:08 -08:00
},
setReportState (reportsState, { id, state }) {
reportsState.reports[id].state = state
},
addReport (state, report) {
state.reports[report.id] = report
2019-03-19 01:53:11 -07:00
}
},
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 01:53:11 -07:00
},
closeUserReportingModal ({ commit }) {
commit('closeUserReportingModal')
2021-01-18 05:26:08 -08:00
},
setReportState ({ commit, dispatch, rootState }, { id, state }) {
2021-01-18 05:26:08 -08:00
const oldState = rootState.reports.reports[id].state
commit('setReportState', { id, state })
rootState.api.backendInteractor.setReportState({ id, state }).catch(e => {
2021-01-18 05:26:08 -08:00
console.error('Failed to set report state', e)
dispatch('pushGlobalNotice', {
level: 'error',
messageKey: 'general.generic_error_message',
messageArgs: [e.message],
timeout: 5000
})
2021-01-27 03:13:10 -08:00
commit('setReportState', { id, state: oldState })
2021-01-18 05:26:08 -08:00
})
},
addReport ({ commit }, report) {
commit('addReport', report)
2019-03-19 01:53:11 -07:00
}
}
}
export default reports