import generator , { Entity } from 'megalodon' ; import { Module , MutationTree , ActionTree } from 'vuex' ; import { RootState } from '@/store' ; import { RemoveAccountFromList } from '@/types/removeAccountFromList' ; export type EditState = { members : Array < Entity . Account > ; } ; const state = ( ) : EditState => ( { members : [ ] } ) ; export const MUTATION_TYPES = { CHANGE_MEMBERS : 'changeMembers' } ; const mutations = { [ MUTATION_TYPES . CHANGE_MEMBERS ] : ( state , members ) => { state . members = members ; } } ; const actions = { fetchMembers : async ( { commit , rootState } , listId ) : Promise < Array < Entity . Account > > => { const client = generator ( rootState . TimelineSpace . sns , rootState . TimelineSpace . account . baseURL , rootState . TimelineSpace . account . accessToken , rootState . App . userAgent ) ; const res = await client . getAccountsInList ( listId , { limit : 0 } ) ; commit ( MUTATION_TYPES . CHANGE_MEMBERS , res . data ) ; return res . data ; } , removeAccount : async ( { rootState } , remove ) : Promise < { } > => { const client = generator ( rootState . TimelineSpace . sns , rootState . TimelineSpace . account . baseURL , rootState . TimelineSpace . account . accessToken , rootState . App . userAgent ) ; return client . deleteAccountsFromList ( remove . listId , [ remove . account . id ] ) ; } } ; export default { namespaced : true , state : state , mutations : mutations , actions : actions } as Module < EditState , RootState > ;