diff --git a/src/renderer/store/TimelineSpace/Contents/SideBar/AccountProfile.ts b/src/renderer/store/TimelineSpace/Contents/SideBar/AccountProfile.ts index 6d405cf2..308bd668 100644 --- a/src/renderer/store/TimelineSpace/Contents/SideBar/AccountProfile.ts +++ b/src/renderer/store/TimelineSpace/Contents/SideBar/AccountProfile.ts @@ -1,7 +1,7 @@ import Mastodon, { Account, Relationship, Response, Results } from 'megalodon' import Timeline from './AccountProfile/Timeline' import Follows from './AccountProfile/Follows' -import Followers from './AccountProfile/Followers' +import Followers, { FollowersState } from './AccountProfile/Followers' import { Module, MutationTree, ActionTree } from 'vuex' import { RootState } from '@/store' @@ -11,7 +11,9 @@ export interface AccountProfileState { loading: boolean } -export interface AccountProfileModuleState extends AccountProfileState {} +export interface AccountProfileModuleState extends AccountProfileState { + Followers: FollowersState +} const state = (): AccountProfileState => ({ account: null, diff --git a/src/renderer/store/TimelineSpace/Contents/SideBar/AccountProfile/Followers.js b/src/renderer/store/TimelineSpace/Contents/SideBar/AccountProfile/Followers.js deleted file mode 100644 index 1a2152d5..00000000 --- a/src/renderer/store/TimelineSpace/Contents/SideBar/AccountProfile/Followers.js +++ /dev/null @@ -1,46 +0,0 @@ -import Mastodon from 'megalodon' - -const Followers = { - namespaced: true, - state: { - followers: [], - relationships: [] - }, - mutations: { - updateFollowers (state, users) { - state.followers = users - }, - updateRelationships (state, relations) { - state.relationships = relations - } - }, - actions: { - fetchFollowers ({ commit, rootState }, account) { - const client = new Mastodon( - rootState.TimelineSpace.account.accessToken, - rootState.TimelineSpace.account.baseURL + '/api/v1' - ) - return client.get(`/accounts/${account.id}/followers`, { limit: 80 }) - .then(res => { - commit('updateFollowers', res.data) - return res.data - }) - }, - fetchRelationships ({ commit, rootState }, accounts) { - const ids = accounts.map(a => a.id) - const client = new Mastodon( - rootState.TimelineSpace.account.accessToken, - rootState.TimelineSpace.account.baseURL + '/api/v1' - ) - return client.get(`/accounts/relationships`, { - id: ids - }) - .then(res => { - commit('updateRelationships', res.data) - return res.data - }) - } - } -} - -export default Followers diff --git a/src/renderer/store/TimelineSpace/Contents/SideBar/AccountProfile/Followers.ts b/src/renderer/store/TimelineSpace/Contents/SideBar/AccountProfile/Followers.ts new file mode 100644 index 00000000..693be910 --- /dev/null +++ b/src/renderer/store/TimelineSpace/Contents/SideBar/AccountProfile/Followers.ts @@ -0,0 +1,60 @@ +import Mastodon, { Account, Relationship, Response } from 'megalodon' +import { Module, MutationTree, ActionTree } from 'vuex' +import { RootState } from '@/store' + +export interface FollowersState { + followers: Array, + relationships: Array +} + +const state = (): FollowersState => ({ + followers: [], + relationships: [] +}) + +export const MUTATION_TYPES = { + UPDATE_FOLLOWERS: 'updateFollowers', + UPDATE_RELATIONSHIPS: 'updateRelationships' +} + +const mutations: MutationTree = { + [MUTATION_TYPES.UPDATE_FOLLOWERS]: (state, users: Array) => { + state.followers = users + }, + [MUTATION_TYPES.UPDATE_RELATIONSHIPS]: (state, relations: Array) => { + state.relationships = relations + } +} + +const actions: ActionTree = { + fetchFollowers: async ({ commit, rootState }, account: Account) => { + const client = new Mastodon( + rootState.TimelineSpace.account.accessToken!, + rootState.TimelineSpace.account.baseURL + '/api/v1' + ) + const res: Response> = await client.get>(`/accounts/${account.id}/followers`, { limit: 80 }) + commit(MUTATION_TYPES.UPDATE_FOLLOWERS, res.data) + return res.data + }, + fetchRelationships: async ({ commit, rootState }, accounts: Array) => { + const ids = accounts.map(a => a.id) + const client = new Mastodon( + rootState.TimelineSpace.account.accessToken!, + rootState.TimelineSpace.account.baseURL + '/api/v1' + ) + const res: Response> = await client.get>(`/accounts/relationships`, { + id: ids + }) + commit(MUTATION_TYPES.UPDATE_RELATIONSHIPS, res.data) + return res.data + } +} + +const Followers: Module = { + namespaced: true, + state: state, + mutations: mutations, + actions: actions +} + +export default Followers