From dd2361e821313ffcfb8e4cf81ab7b68dacbce6e0 Mon Sep 17 00:00:00 2001
From: AkiraFukushima
Date: Sun, 14 Apr 2019 17:44:20 +0900
Subject: [PATCH] refs #850 Replace Account in Search with typescript
---
src/renderer/store/TimelineSpace/Contents.ts | 5 +-
.../store/TimelineSpace/Contents/Search.ts | 3 +-
.../TimelineSpace/Contents/Search/Account.js | 32 -------------
.../TimelineSpace/Contents/Search/Account.ts | 46 +++++++++++++++++++
4 files changed, 51 insertions(+), 35 deletions(-)
delete mode 100644 src/renderer/store/TimelineSpace/Contents/Search/Account.js
create mode 100644 src/renderer/store/TimelineSpace/Contents/Search/Account.ts
diff --git a/src/renderer/store/TimelineSpace/Contents.ts b/src/renderer/store/TimelineSpace/Contents.ts
index c4985894..d0890abc 100644
--- a/src/renderer/store/TimelineSpace/Contents.ts
+++ b/src/renderer/store/TimelineSpace/Contents.ts
@@ -4,7 +4,7 @@ import Notifications, { NotificationsState } from './Contents/Notifications'
import Favourites from './Contents/Favourites'
import Local, { LocalState } from './Contents/Local'
import Public, { PublicState } from './Contents/Public'
-import Search from './Contents/Search'
+import Search, { SearchModuleState } from './Contents/Search'
import Lists from './Contents/Lists'
import Hashtag from './Contents/Hashtag'
import DirectMessages, { DirectMessagesState } from './Contents/DirectMessages'
@@ -21,7 +21,8 @@ export interface ContentsModuleState extends ContentsState {
Mentions: MentionsState,
DirectMessages: DirectMessagesState,
Local: LocalState,
- Public: PublicState
+ Public: PublicState,
+ Search: SearchModuleState,
}
const state = (): ContentsState => ({})
diff --git a/src/renderer/store/TimelineSpace/Contents/Search.ts b/src/renderer/store/TimelineSpace/Contents/Search.ts
index 228f5da0..52acf19b 100644
--- a/src/renderer/store/TimelineSpace/Contents/Search.ts
+++ b/src/renderer/store/TimelineSpace/Contents/Search.ts
@@ -1,4 +1,4 @@
-import Account from './Search/Account'
+import Account, { AccountState } from './Search/Account'
import Tag from './Search/Tag'
import Toots from './Search/Toots'
import { Module, MutationTree } from 'vuex'
@@ -9,6 +9,7 @@ export interface SearchState {
}
export interface SearchModuleState extends SearchState {
+ Account: AccountState
}
const state = (): SearchState => ({
diff --git a/src/renderer/store/TimelineSpace/Contents/Search/Account.js b/src/renderer/store/TimelineSpace/Contents/Search/Account.js
deleted file mode 100644
index 3b2e9096..00000000
--- a/src/renderer/store/TimelineSpace/Contents/Search/Account.js
+++ /dev/null
@@ -1,32 +0,0 @@
-import Mastodon from 'megalodon'
-
-const Account = {
- namespaced: true,
- state: {
- results: []
- },
- mutations: {
- updateResults (state, results) {
- state.results = results
- }
- },
- actions: {
- search ({ commit, rootState }, query) {
- commit('TimelineSpace/Contents/Search/changeLoading', true, { root: true })
- const client = new Mastodon(
- rootState.TimelineSpace.account.accessToken,
- rootState.TimelineSpace.account.baseURL + '/api/v1'
- )
- return client.get('/search', { q: query, resolve: true })
- .then(res => {
- commit('updateResults', res.data.accounts)
- return res.data
- })
- .finally(() => {
- commit('TimelineSpace/Contents/Search/changeLoading', false, { root: true })
- })
- }
- }
-}
-
-export default Account
diff --git a/src/renderer/store/TimelineSpace/Contents/Search/Account.ts b/src/renderer/store/TimelineSpace/Contents/Search/Account.ts
new file mode 100644
index 00000000..c7dc7c2a
--- /dev/null
+++ b/src/renderer/store/TimelineSpace/Contents/Search/Account.ts
@@ -0,0 +1,46 @@
+import Mastodon, { Account, Results } from 'megalodon'
+import { Module, MutationTree, ActionTree } from 'vuex'
+import { RootState } from '@/store'
+
+export interface AccountState {
+ results: Array
+}
+
+const state = (): AccountState => ({
+ results: []
+})
+
+export const MUTATION_TYPES = {
+ UPDATE_RESULTS: 'updateResults'
+}
+
+const mutations: MutationTree = {
+ [MUTATION_TYPES.UPDATE_RESULTS]: (state, results: Array) => {
+ state.results = results
+ }
+}
+
+const actions: ActionTree = {
+ search: async ({ commit, rootState }, query: string): Promise> => {
+ commit('TimelineSpace/Contents/Search/changeLoading', true, { root: true })
+ const client = new Mastodon(
+ rootState.TimelineSpace.account.accessToken!,
+ rootState.TimelineSpace.account.baseURL + '/api/v1'
+ )
+ return client.get('/search', { q: query, resolve: true })
+ .then(res => {
+ commit(MUTATION_TYPES.UPDATE_RESULTS, res.data.accounts)
+ return res.data.accounts
+ })
+ .finally(() => {
+ commit('TimelineSpace/Contents/Search/changeLoading', false, { root: true })
+ })
+ }
+}
+
+export default {
+ namespaced: true,
+ state: state,
+ mutations: mutations,
+ actions: actions
+} as Module