Move reports module to store
This commit is contained in:
parent
f9254e5fb7
commit
ad7d47f440
8 changed files with 64 additions and 74 deletions
|
|
@ -1,65 +0,0 @@
|
|||
import filter from 'lodash/filter'
|
||||
import { useInterfaceStore } from '../stores/interface'
|
||||
|
||||
const reports = {
|
||||
state: {
|
||||
reportModal: {
|
||||
userId: null,
|
||||
statuses: [],
|
||||
preTickedIds: [],
|
||||
activated: false
|
||||
},
|
||||
reports: {}
|
||||
},
|
||||
mutations: {
|
||||
openUserReportingModal (state, { userId, statuses, preTickedIds }) {
|
||||
state.reportModal.userId = userId
|
||||
state.reportModal.statuses = statuses
|
||||
state.reportModal.preTickedIds = preTickedIds
|
||||
state.reportModal.activated = true
|
||||
},
|
||||
closeUserReportingModal (state) {
|
||||
state.reportModal.activated = false
|
||||
},
|
||||
setReportState (reportsState, { id, state }) {
|
||||
reportsState.reports[id].state = state
|
||||
},
|
||||
addReport (state, report) {
|
||||
state.reports[report.id] = report
|
||||
}
|
||||
},
|
||||
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 })
|
||||
},
|
||||
closeUserReportingModal ({ commit }) {
|
||||
commit('closeUserReportingModal')
|
||||
},
|
||||
setReportState ({ commit, dispatch, rootState }, { id, state }) {
|
||||
const oldState = rootState.reports.reports[id].state
|
||||
commit('setReportState', { id, state })
|
||||
rootState.api.backendInteractor.setReportState({ id, state }).catch(e => {
|
||||
console.error('Failed to set report state', e)
|
||||
useInterfaceStore().pushGlobalNotice({
|
||||
level: 'error',
|
||||
messageKey: 'general.generic_error_message',
|
||||
messageArgs: [e.message],
|
||||
timeout: 5000
|
||||
})
|
||||
commit('setReportState', { id, state: oldState })
|
||||
})
|
||||
},
|
||||
addReport ({ commit }, report) {
|
||||
commit('addReport', report)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export default reports
|
||||
|
|
@ -18,6 +18,7 @@ import {
|
|||
maybeShowNotification
|
||||
} from '../services/notification_utils/notification_utils.js'
|
||||
import apiService from '../services/api/api.service.js'
|
||||
import { useReportsStore } from '../stores/reports.js'
|
||||
|
||||
const emptyTl = (userId = 0) => ({
|
||||
statuses: [],
|
||||
|
|
@ -341,7 +342,7 @@ const addNewNotifications = (state, { dispatch, notifications, older, visibleNot
|
|||
}
|
||||
|
||||
if (notification.type === 'pleroma:report') {
|
||||
dispatch('addReport', notification.report)
|
||||
useReportsStore().addReport(notification.report)
|
||||
}
|
||||
|
||||
if (notification.type === 'pleroma:emoji_reaction') {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue