refs #850 Replace MuteConfirm with typescript
This commit is contained in:
parent
921d3f07e3
commit
20f3dcba22
@ -1,9 +1,9 @@
|
|||||||
import NewToot from './Modals/NewToot'
|
import NewToot from './Modals/NewToot'
|
||||||
import ImageViewer, { ImageViewerState } from './Modals/ImageViewer'
|
import ImageViewer, { ImageViewerState } from './Modals/ImageViewer'
|
||||||
import Jump, { JumpState } from './Modals/Jump'
|
import Jump, { JumpState } from './Modals/Jump'
|
||||||
import ListMembership from './Modals/ListMembership'
|
import ListMembership, { ListMembershipState } from './Modals/ListMembership'
|
||||||
import AddListMember, { AddListMemberState } from './Modals/AddListMember'
|
import AddListMember, { AddListMemberState } from './Modals/AddListMember'
|
||||||
import MuteConfirm from './Modals/MuteConfirm'
|
import MuteConfirm, { MuteConfirmState } from './Modals/MuteConfirm'
|
||||||
import Shortcut from './Modals/Shortcut'
|
import Shortcut from './Modals/Shortcut'
|
||||||
import Report from './Modals/Report'
|
import Report from './Modals/Report'
|
||||||
import { Module, GetterTree } from 'vuex'
|
import { Module, GetterTree } from 'vuex'
|
||||||
@ -14,7 +14,9 @@ export interface ModalsState {}
|
|||||||
export interface ModalsModuleState extends ModalsState {
|
export interface ModalsModuleState extends ModalsState {
|
||||||
Jump: JumpState,
|
Jump: JumpState,
|
||||||
AddListMember: AddListMemberState,
|
AddListMember: AddListMemberState,
|
||||||
ImageViewer: ImageViewerState
|
ImageViewer: ImageViewerState,
|
||||||
|
ListMembership: ListMembershipState,
|
||||||
|
MuteConfirm: MuteConfirmState
|
||||||
}
|
}
|
||||||
|
|
||||||
const state = (): ModalsState => ({})
|
const state = (): ModalsState => ({})
|
||||||
|
@ -1,39 +0,0 @@
|
|||||||
import Mastodon from 'megalodon'
|
|
||||||
|
|
||||||
export default {
|
|
||||||
namespaced: true,
|
|
||||||
state: {
|
|
||||||
modalOpen: false,
|
|
||||||
account: {}
|
|
||||||
},
|
|
||||||
mutations: {
|
|
||||||
changeModal (state, value) {
|
|
||||||
state.modalOpen = value
|
|
||||||
},
|
|
||||||
changeAccount (state, account) {
|
|
||||||
state.account = account
|
|
||||||
}
|
|
||||||
},
|
|
||||||
actions: {
|
|
||||||
changeModal ({ commit }, value) {
|
|
||||||
commit('changeModal', value)
|
|
||||||
},
|
|
||||||
changeAccount ({ commit }, account) {
|
|
||||||
commit('changeAccount', account)
|
|
||||||
},
|
|
||||||
async submit ({ state, rootState, dispatch }, notify) {
|
|
||||||
const client = new Mastodon(
|
|
||||||
rootState.TimelineSpace.account.accessToken,
|
|
||||||
rootState.TimelineSpace.account.baseURL + '/api/v1'
|
|
||||||
)
|
|
||||||
return client.post(`/accounts/${state.account.id}/mute`, {
|
|
||||||
notifications: notify
|
|
||||||
})
|
|
||||||
.then(res => {
|
|
||||||
// Reload relationship
|
|
||||||
dispatch('TimelineSpace/Contents/SideBar/AccountProfile/fetchRelationship', state.account, { root: true })
|
|
||||||
return res.data
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
57
src/renderer/store/TimelineSpace/Modals/MuteConfirm.ts
Normal file
57
src/renderer/store/TimelineSpace/Modals/MuteConfirm.ts
Normal file
@ -0,0 +1,57 @@
|
|||||||
|
import Mastodon, { Account, Response, Relationship } from 'megalodon'
|
||||||
|
import { Module, MutationTree, ActionTree } from 'vuex'
|
||||||
|
import { RootState } from '@/store'
|
||||||
|
|
||||||
|
export interface MuteConfirmState {
|
||||||
|
modalOpen: boolean,
|
||||||
|
account: Account | null
|
||||||
|
}
|
||||||
|
|
||||||
|
const state = (): MuteConfirmState => ({
|
||||||
|
modalOpen: false,
|
||||||
|
account: null
|
||||||
|
})
|
||||||
|
|
||||||
|
export const MUTATION_TYPES = {
|
||||||
|
CHANGE_MODAL: 'changeModal',
|
||||||
|
CHANGE_ACCOUNT: 'changeAccount'
|
||||||
|
}
|
||||||
|
|
||||||
|
const mutations: MutationTree<MuteConfirmState> = {
|
||||||
|
[MUTATION_TYPES.CHANGE_MODAL]: (state, value: boolean) => {
|
||||||
|
state.modalOpen = value
|
||||||
|
},
|
||||||
|
[MUTATION_TYPES.CHANGE_ACCOUNT]: (state, account: Account) => {
|
||||||
|
state.account = account
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const actions: ActionTree<MuteConfirmState, RootState> = {
|
||||||
|
changeModal: ({ commit }, value: boolean) => {
|
||||||
|
commit(MUTATION_TYPES.CHANGE_MODAL, value)
|
||||||
|
},
|
||||||
|
changeAccount: ({ commit }, account: Account) => {
|
||||||
|
commit(MUTATION_TYPES.CHANGE_ACCOUNT, account)
|
||||||
|
},
|
||||||
|
submit: async ({ state, rootState, dispatch }, notify: boolean) => {
|
||||||
|
const client = new Mastodon(
|
||||||
|
rootState.TimelineSpace.account.accessToken!,
|
||||||
|
rootState.TimelineSpace.account.baseURL + '/api/v1'
|
||||||
|
)
|
||||||
|
const res: Response<Relationship> = await client.post<Relationship>(`/accounts/${state.account!.id}/mute`, {
|
||||||
|
notifications: notify
|
||||||
|
})
|
||||||
|
// Reload relationship
|
||||||
|
dispatch('TimelineSpace/Contents/SideBar/AccountProfile/fetchRelationship', state.account, { root: true })
|
||||||
|
return res.data
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const MuteConfirm: Module<MuteConfirmState, RootState> = {
|
||||||
|
namespaced: true,
|
||||||
|
state: state,
|
||||||
|
mutations: mutations,
|
||||||
|
actions: actions
|
||||||
|
}
|
||||||
|
|
||||||
|
export default MuteConfirm
|
Loading…
x
Reference in New Issue
Block a user