refs #850 Replace Edit in Lists with typescript

This commit is contained in:
AkiraFukushima 2019-04-14 20:32:48 +09:00
parent 77d0268257
commit e68002ea83
4 changed files with 61 additions and 38 deletions

View File

@ -1,6 +1,6 @@
import Index, { IndexState } from './Lists/Index'
import Show, { ShowState } from './Lists/Show'
import Edit from './Lists/Edit'
import Edit, { EditState } from './Lists/Edit'
import { Module } from 'vuex'
import { RootState } from '@/store'
@ -8,7 +8,8 @@ export interface ListsState {}
export interface ListsModuleState extends ListsState {
Index: IndexState,
Show: ShowState
Show: ShowState,
Edit: EditState
}
const state = (): ListsState => ({})

View File

@ -1,36 +0,0 @@
import Mastodon from 'megalodon'
export default {
namespaced: true,
state: {
members: []
},
mutations: {
changeMembers (state, members) {
state.members = members
}
},
actions: {
fetchMembers ({ commit, rootState }, listId) {
const client = new Mastodon(
rootState.TimelineSpace.account.accessToken,
rootState.TimelineSpace.account.baseURL + '/api/v1'
)
return client.get(`/lists/${listId}/accounts`, {
limit: 0
})
.then((res) => {
commit('changeMembers', res.data)
})
},
removeAccount ({ rootState }, obj) {
const client = new Mastodon(
rootState.TimelineSpace.account.accessToken,
rootState.TimelineSpace.account.baseURL + '/api/v1'
)
return client.del(`/lists/${obj.listId}/accounts`, {
account_ids: [obj.account.id]
})
}
}
}

View File

@ -0,0 +1,52 @@
import Mastodon, { Account, Response } from 'megalodon'
import { Module, MutationTree, ActionTree } from 'vuex'
import { RootState } from '@/store'
import { RemoveAccountFromList } from '~/src/types/remove_account_from_list'
export interface EditState {
members: Array<Account>
}
const state = (): EditState => ({
members: []
})
export const MUTATION_TYPES = {
CHANGE_MEMBERS: 'changeMembers'
}
const mutations: MutationTree<EditState> = {
[MUTATION_TYPES.CHANGE_MEMBERS]: (state, members: Array<Account>) => {
state.members = members
}
}
const actions: ActionTree<EditState, RootState> = {
fetchMembers: async ({ commit, rootState }, listId: number): Promise<Array<Account>> => {
const client = new Mastodon(
rootState.TimelineSpace.account.accessToken!,
rootState.TimelineSpace.account.baseURL + '/api/v1'
)
const res: Response<Array<Account>> = await client.get<Array<Account>>(`/lists/${listId}/accounts`, {
limit: 0
})
commit(MUTATION_TYPES.CHANGE_MEMBERS, res.data)
return res.data
},
removeAccount: async ({ rootState }, remove: RemoveAccountFromList): Promise<{}> => {
const client = new Mastodon(
rootState.TimelineSpace.account.accessToken!,
rootState.TimelineSpace.account.baseURL + '/api/v1'
)
return client.del<{}>(`/lists/${remove.listId}/accounts`, {
account_ids: [remove.account.id]
})
}
}
export default {
namespaced: true,
state: state,
mutations: mutations,
actions: actions
} as Module<EditState, RootState>

View File

@ -0,0 +1,6 @@
import { Account } from 'megalodon'
export interface RemoveAccountFromList {
account: Account,
listId: number
}