import generator, { Entity } from 'megalodon' import { Module, MutationTree, ActionTree } from 'vuex' import { RootState } from '@/store' export type MuteConfirmState = { modalOpen: boolean account: Entity.Account | null } const state = (): MuteConfirmState => ({ modalOpen: false, account: null }) export const MUTATION_TYPES = { CHANGE_MODAL: 'changeModal', CHANGE_ACCOUNT: 'changeAccount' } const mutations: MutationTree = { [MUTATION_TYPES.CHANGE_MODAL]: (state, value: boolean) => { state.modalOpen = value }, [MUTATION_TYPES.CHANGE_ACCOUNT]: (state, account: Entity.Account) => { state.account = account } } export const ACTION_TYPES = { CHANGE_MODAL: 'changeModal', CHANGE_ACCOUNT: 'changeAccount', SUBMIT: 'submit' } const actions: ActionTree = { [ACTION_TYPES.CHANGE_MODAL]: ({ commit }, value: boolean) => { commit(MUTATION_TYPES.CHANGE_MODAL, value) }, [ACTION_TYPES.CHANGE_ACCOUNT]: ({ commit }, account: Entity.Account) => { commit(MUTATION_TYPES.CHANGE_ACCOUNT, account) }, [ACTION_TYPES.SUBMIT]: async ({ state, rootState, dispatch }, notify: boolean) => { const client = generator( rootState.TimelineSpace.sns, rootState.TimelineSpace.account.baseURL, rootState.TimelineSpace.account.accessToken, rootState.App.userAgent ) const res = await client.muteAccount(state.account!.id, notify) // Reload relationship dispatch('TimelineSpace/Contents/SideBar/AccountProfile/fetchRelationship', state.account, { root: true }) return res.data } } const MuteConfirm: Module = { namespaced: true, state: state, mutations: mutations, actions: actions } export default MuteConfirm