refs #850 Replace Report with typescript
This commit is contained in:
parent
0208e7c22a
commit
ac21511236
|
@ -5,7 +5,7 @@ import ListMembership, { ListMembershipState } from './Modals/ListMembership'
|
|||
import AddListMember, { AddListMemberState } from './Modals/AddListMember'
|
||||
import MuteConfirm, { MuteConfirmState } from './Modals/MuteConfirm'
|
||||
import Shortcut from './Modals/Shortcut'
|
||||
import Report from './Modals/Report'
|
||||
import Report, { ReportState } from './Modals/Report'
|
||||
import { Module, GetterTree } from 'vuex'
|
||||
import { RootState } from '@/store/index'
|
||||
|
||||
|
@ -17,7 +17,8 @@ export interface ModalsModuleState extends ModalsState {
|
|||
ImageViewer: ImageViewerState,
|
||||
ListMembership: ListMembershipState,
|
||||
MuteConfirm: MuteConfirmState,
|
||||
NewToot: NewTootModuleState
|
||||
NewToot: NewTootModuleState,
|
||||
Report: ReportState
|
||||
}
|
||||
|
||||
const state = (): ModalsState => ({})
|
||||
|
|
|
@ -1,34 +0,0 @@
|
|||
import Mastodon from 'megalodon'
|
||||
|
||||
export default {
|
||||
namespaced: true,
|
||||
state: {
|
||||
modalOpen: false,
|
||||
message: {}
|
||||
},
|
||||
mutations: {
|
||||
changeModalOpen (state, value) {
|
||||
state.modalOpen = value
|
||||
},
|
||||
changeMessage (state, value) {
|
||||
state.message = value
|
||||
}
|
||||
},
|
||||
actions: {
|
||||
openReport ({ commit }, message) {
|
||||
commit('changeMessage', message)
|
||||
commit('changeModalOpen', true)
|
||||
},
|
||||
submit ({ rootState }, payload) {
|
||||
const client = new Mastodon(
|
||||
rootState.TimelineSpace.account.accessToken,
|
||||
rootState.TimelineSpace.account.baseURL + '/api/v1'
|
||||
)
|
||||
return client.post(`/reports`, {
|
||||
account_id: payload.account_id,
|
||||
status_ids: [payload.status_id],
|
||||
comment: payload.comment
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,52 @@
|
|||
import Mastodon, { Status } from 'megalodon'
|
||||
import { Module, MutationTree, ActionTree } from 'vuex'
|
||||
import { RootState } from '@/store'
|
||||
|
||||
export interface ReportState {
|
||||
modalOpen: boolean,
|
||||
message: Status | null
|
||||
}
|
||||
|
||||
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
|
||||
},
|
||||
[MUTATION_TYPES.CHANGE_MESSAGE]: (state, message: Status) => {
|
||||
state.message = message
|
||||
}
|
||||
}
|
||||
|
||||
const actions: ActionTree<ReportState, RootState> = {
|
||||
openReport: ({ commit }, message: Status) => {
|
||||
commit(MUTATION_TYPES.CHANGE_MESSAGE, message)
|
||||
commit(MUTATION_TYPES.CHANGE_MODAL_OPEN, true)
|
||||
},
|
||||
submit: async ({ rootState }, { account_id, status_id, comment }) => {
|
||||
const client = new Mastodon(
|
||||
rootState.TimelineSpace.account.accessToken!,
|
||||
rootState.TimelineSpace.account.baseURL + '/api/v1'
|
||||
)
|
||||
return client.post<{}>(`/reports`, {
|
||||
account_id: account_id,
|
||||
status_ids: [status_id],
|
||||
comment: comment
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
export default {
|
||||
namespaced: true,
|
||||
state: state,
|
||||
mutations: mutations,
|
||||
actions: actions
|
||||
} as Module<ReportState, RootState>
|
Loading…
Reference in New Issue