import generator , { Entity } from 'megalodon' ; import { Module , MutationTree , ActionTree } from 'vuex' ; import { RootState } from '@/store' ; export type AddListMemberState = { modalOpen : boolean ; accounts : Array < Entity . Account > ; targetListId : string | null ; } ; const state = ( ) : AddListMemberState => ( { modalOpen : false , accounts : [ ] , targetListId : null } ) ; export const MUTATION_TYPES = { CHANGE_MODAL : 'changeModal' , UPDATE_ACCOUNTS : 'updateAccounts' , SET_LIST_ID : 'setListId' } ; const mutations = { [ MUTATION_TYPES . CHANGE_MODAL ] : ( state , value ) => { state . modalOpen = value ; } , [ MUTATION_TYPES . UPDATE_ACCOUNTS ] : ( state , accounts ) => { state . accounts = accounts ; } , [ MUTATION_TYPES . SET_LIST_ID ] : ( state , id ) => { state . targetListId = id ; } } ; const actions = { changeModal : ( { commit } , value ) => { commit ( MUTATION_TYPES . CHANGE_MODAL , value ) ; } , search : async ( { commit , rootState } , name ) : 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 . searchAccount ( name , { following : true } ) ; commit ( MUTATION_TYPES . UPDATE_ACCOUNTS , res . data ) ; return res . data ; } , add : async ( { state , rootState } , account ) : Promise < { } > => { const client = generator ( rootState . TimelineSpace . sns , rootState . TimelineSpace . account . baseURL , rootState . TimelineSpace . account . accessToken , rootState . App . userAgent ) ; const res = await client . addAccountsToList ( state . targetListId ! , [ account . id ] ) ; return res . data ; } } ; const AddListMember = { namespaced : true , state : state , mutations : mutations , actions : actions } ; export default AddListMember ;