refs #850 Replace Tag in Search with typescript
This commit is contained in:
parent
dd2361e821
commit
15a0719844
|
@ -1,5 +1,5 @@
|
|||
import Account, { AccountState } from './Search/Account'
|
||||
import Tag from './Search/Tag'
|
||||
import Tag, { TagState } from './Search/Tag'
|
||||
import Toots from './Search/Toots'
|
||||
import { Module, MutationTree } from 'vuex'
|
||||
import { RootState } from '@/store'
|
||||
|
@ -9,7 +9,8 @@ export interface SearchState {
|
|||
}
|
||||
|
||||
export interface SearchModuleState extends SearchState {
|
||||
Account: AccountState
|
||||
Account: AccountState,
|
||||
Tag: TagState
|
||||
}
|
||||
|
||||
const state = (): SearchState => ({
|
||||
|
|
|
@ -1,30 +0,0 @@
|
|||
import Mastodon from 'megalodon'
|
||||
|
||||
export default {
|
||||
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/v2'
|
||||
)
|
||||
return client.get('/search', { q: query, resolve: true })
|
||||
.then(res => {
|
||||
commit('updateResults', res.data.hashtags)
|
||||
return res.data
|
||||
})
|
||||
.finally(() => {
|
||||
commit('TimelineSpace/Contents/Search/changeLoading', false, { root: true })
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,47 @@
|
|||
import Mastodon, { Tag, Results } from 'megalodon'
|
||||
import { Module, MutationTree, ActionTree } from 'vuex'
|
||||
import { RootState } from '@/store'
|
||||
|
||||
|
||||
export interface TagState {
|
||||
results: Array<Tag>
|
||||
}
|
||||
|
||||
const state = (): TagState => ({
|
||||
results: []
|
||||
})
|
||||
|
||||
export const MUTATION_TYPES = {
|
||||
UPDATE_RESULTS: 'updateResults'
|
||||
}
|
||||
|
||||
const mutations: MutationTree<TagState> = {
|
||||
[MUTATION_TYPES.UPDATE_RESULTS]: (state, results: Array<Tag>) => {
|
||||
state.results = results
|
||||
}
|
||||
}
|
||||
|
||||
const actions: ActionTree<TagState, RootState> = {
|
||||
search: ({ commit, rootState }, query: string): Promise<Array<Tag>> => {
|
||||
commit('TimelineSpace/Contents/Search/changeLoading', true, { root: true })
|
||||
const client = new Mastodon(
|
||||
rootState.TimelineSpace.account.accessToken!,
|
||||
rootState.TimelineSpace.account.baseURL + '/api/v2'
|
||||
)
|
||||
return client.get<Results>('/search', { q: query, resolve: true })
|
||||
.then(res => {
|
||||
commit(MUTATION_TYPES.UPDATE_RESULTS, res.data.hashtags)
|
||||
return res.data.hashtags
|
||||
})
|
||||
.finally(() => {
|
||||
commit('TimelineSpace/Contents/Search/changeLoading', false, { root: true })
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
export default {
|
||||
namespaced: true,
|
||||
state: state,
|
||||
mutations: mutations,
|
||||
actions: actions
|
||||
} as Module<TagState, RootState>
|
Loading…
Reference in New Issue