From e68002ea8302d43925211a3728b7da853cbe2cc5 Mon Sep 17 00:00:00 2001
From: AkiraFukushima
Date: Sun, 14 Apr 2019 20:32:48 +0900
Subject: [PATCH] refs #850 Replace Edit in Lists with typescript
---
.../store/TimelineSpace/Contents/Lists.ts | 5 +-
.../TimelineSpace/Contents/Lists/Edit.js | 36 -------------
.../TimelineSpace/Contents/Lists/Edit.ts | 52 +++++++++++++++++++
src/types/remove_account_from_list.ts | 6 +++
4 files changed, 61 insertions(+), 38 deletions(-)
delete mode 100644 src/renderer/store/TimelineSpace/Contents/Lists/Edit.js
create mode 100644 src/renderer/store/TimelineSpace/Contents/Lists/Edit.ts
create mode 100644 src/types/remove_account_from_list.ts
diff --git a/src/renderer/store/TimelineSpace/Contents/Lists.ts b/src/renderer/store/TimelineSpace/Contents/Lists.ts
index 190d5b76..e2589b3c 100644
--- a/src/renderer/store/TimelineSpace/Contents/Lists.ts
+++ b/src/renderer/store/TimelineSpace/Contents/Lists.ts
@@ -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 => ({})
diff --git a/src/renderer/store/TimelineSpace/Contents/Lists/Edit.js b/src/renderer/store/TimelineSpace/Contents/Lists/Edit.js
deleted file mode 100644
index b4d27565..00000000
--- a/src/renderer/store/TimelineSpace/Contents/Lists/Edit.js
+++ /dev/null
@@ -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]
- })
- }
- }
-}
diff --git a/src/renderer/store/TimelineSpace/Contents/Lists/Edit.ts b/src/renderer/store/TimelineSpace/Contents/Lists/Edit.ts
new file mode 100644
index 00000000..10101871
--- /dev/null
+++ b/src/renderer/store/TimelineSpace/Contents/Lists/Edit.ts
@@ -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
+}
+
+const state = (): EditState => ({
+ members: []
+})
+
+export const MUTATION_TYPES = {
+ CHANGE_MEMBERS: 'changeMembers'
+}
+
+const mutations: MutationTree = {
+ [MUTATION_TYPES.CHANGE_MEMBERS]: (state, members: Array) => {
+ state.members = members
+ }
+}
+
+const actions: ActionTree = {
+ fetchMembers: async ({ commit, rootState }, listId: number): Promise> => {
+ const client = new Mastodon(
+ rootState.TimelineSpace.account.accessToken!,
+ rootState.TimelineSpace.account.baseURL + '/api/v1'
+ )
+ const res: Response> = await client.get>(`/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
diff --git a/src/types/remove_account_from_list.ts b/src/types/remove_account_from_list.ts
new file mode 100644
index 00000000..108da874
--- /dev/null
+++ b/src/types/remove_account_from_list.ts
@@ -0,0 +1,6 @@
+import { Account } from 'megalodon'
+
+export interface RemoveAccountFromList {
+ account: Account,
+ listId: number
+}