2020-03-15 09:47:56 +01:00
|
|
|
import generator, { Entity } from 'megalodon'
|
2019-04-10 17:15:12 +02:00
|
|
|
import { Module, MutationTree, ActionTree } from 'vuex'
|
|
|
|
import { RootState } from '@/store'
|
|
|
|
|
2019-06-06 16:44:50 +02:00
|
|
|
export type ReportState = {
|
|
|
|
modalOpen: boolean
|
2020-03-15 09:47:56 +01:00
|
|
|
message: Entity.Status | null
|
2019-04-10 17:15:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
const state = (): ReportState => ({
|
|
|
|
modalOpen: false,
|
|
|
|
message: null
|
|
|
|
})
|
|
|
|
|
|
|
|
export const MUTATION_TYPES = {
|
|
|
|
CHANGE_MODAL_OPEN: 'changeModalOpen',
|
|
|
|
CHANGE_MESSAGE: 'changeMessage'
|
|
|
|
}
|
|
|
|
|
|
|
|
const mutations: MutationTree<ReportState> = {
|
|
|
|
[MUTATION_TYPES.CHANGE_MODAL_OPEN]: (state, value: boolean) => {
|
|
|
|
state.modalOpen = value
|
|
|
|
},
|
2020-03-15 09:47:56 +01:00
|
|
|
[MUTATION_TYPES.CHANGE_MESSAGE]: (state, message: Entity.Status) => {
|
2019-04-10 17:15:12 +02:00
|
|
|
state.message = message
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-28 14:30:37 +02:00
|
|
|
export const ACTION_TYPES = {
|
|
|
|
OPEN_REPORT: 'openReport',
|
|
|
|
SUBMIT: 'submit'
|
|
|
|
}
|
|
|
|
|
2019-04-10 17:15:12 +02:00
|
|
|
const actions: ActionTree<ReportState, RootState> = {
|
2022-04-28 14:30:37 +02:00
|
|
|
[ACTION_TYPES.OPEN_REPORT]: ({ commit }, message: Entity.Status) => {
|
2019-04-10 17:15:12 +02:00
|
|
|
commit(MUTATION_TYPES.CHANGE_MESSAGE, message)
|
|
|
|
commit(MUTATION_TYPES.CHANGE_MODAL_OPEN, true)
|
|
|
|
},
|
2022-04-28 14:30:37 +02:00
|
|
|
[ACTION_TYPES.SUBMIT]: async ({ rootState }, { account_id, status_id, comment }) => {
|
2020-03-15 09:47:56 +01:00
|
|
|
const client = generator(
|
|
|
|
rootState.TimelineSpace.sns,
|
|
|
|
rootState.TimelineSpace.account.baseURL,
|
|
|
|
rootState.TimelineSpace.account.accessToken,
|
2020-06-30 17:07:55 +02:00
|
|
|
rootState.App.userAgent
|
2019-10-27 06:41:03 +01:00
|
|
|
)
|
2020-03-15 09:47:56 +01:00
|
|
|
return client.report(account_id, comment, { status_ids: [status_id] })
|
2019-04-10 17:15:12 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default {
|
|
|
|
namespaced: true,
|
|
|
|
state: state,
|
|
|
|
mutations: mutations,
|
|
|
|
actions: actions
|
|
|
|
} as Module<ReportState, RootState>
|