refs #850 Replace Toots in Search with typescript
This commit is contained in:
parent
15a0719844
commit
b66790a9aa
|
@ -24,7 +24,7 @@ export const MUTATION_TYPES = {
|
||||||
UPDATE_TIMELINE: 'updateTimeline',
|
UPDATE_TIMELINE: 'updateTimeline',
|
||||||
MERGE_TIMELINE: 'mergeTimeline',
|
MERGE_TIMELINE: 'mergeTimeline',
|
||||||
INSERT_TIMELINE: 'insertTimeline',
|
INSERT_TIMELINE: 'insertTimeline',
|
||||||
ARCHIVE_TIMELINE: 'archiveTimeine',
|
ARCHIVE_TIMELINE: 'archiveTimeline',
|
||||||
CLEAR_TIMELINE: 'clearTimeline',
|
CLEAR_TIMELINE: 'clearTimeline',
|
||||||
UPDATE_TOOT: 'updateToot',
|
UPDATE_TOOT: 'updateToot',
|
||||||
DELETE_TOOT: 'deleteToot',
|
DELETE_TOOT: 'deleteToot',
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import Account, { AccountState } from './Search/Account'
|
import Account, { AccountState } from './Search/Account'
|
||||||
import Tag, { TagState } from './Search/Tag'
|
import Tag, { TagState } from './Search/Tag'
|
||||||
import Toots from './Search/Toots'
|
import Toots, { TootsState } from './Search/Toots'
|
||||||
import { Module, MutationTree } from 'vuex'
|
import { Module, MutationTree } from 'vuex'
|
||||||
import { RootState } from '@/store'
|
import { RootState } from '@/store'
|
||||||
|
|
||||||
|
@ -10,7 +10,8 @@ export interface SearchState {
|
||||||
|
|
||||||
export interface SearchModuleState extends SearchState {
|
export interface SearchModuleState extends SearchState {
|
||||||
Account: AccountState,
|
Account: AccountState,
|
||||||
Tag: TagState
|
Tag: TagState,
|
||||||
|
Toots: TootsState
|
||||||
}
|
}
|
||||||
|
|
||||||
const state = (): SearchState => ({
|
const state = (): SearchState => ({
|
||||||
|
|
|
@ -2,7 +2,6 @@ import Mastodon, { Tag, Results } from 'megalodon'
|
||||||
import { Module, MutationTree, ActionTree } from 'vuex'
|
import { Module, MutationTree, ActionTree } from 'vuex'
|
||||||
import { RootState } from '@/store'
|
import { RootState } from '@/store'
|
||||||
|
|
||||||
|
|
||||||
export interface TagState {
|
export interface TagState {
|
||||||
results: Array<Tag>
|
results: Array<Tag>
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,32 +0,0 @@
|
||||||
import Mastodon from 'megalodon'
|
|
||||||
|
|
||||||
const Toots = {
|
|
||||||
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.statuses)
|
|
||||||
return res.data
|
|
||||||
})
|
|
||||||
.finally(() => {
|
|
||||||
commit('TimelineSpace/Contents/Search/changeLoading', false, { root: true })
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export default Toots
|
|
|
@ -0,0 +1,48 @@
|
||||||
|
import Mastodon, { Status, Results } from 'megalodon'
|
||||||
|
import { Module, MutationTree, ActionTree } from 'vuex'
|
||||||
|
import { RootState } from '@/store'
|
||||||
|
|
||||||
|
export interface TootsState {
|
||||||
|
results: Array<Status>
|
||||||
|
}
|
||||||
|
|
||||||
|
const state = (): TootsState => ({
|
||||||
|
results: []
|
||||||
|
})
|
||||||
|
|
||||||
|
export const MUTATION_TYPES = {
|
||||||
|
UPDATE_RESULTS: 'updateResults'
|
||||||
|
}
|
||||||
|
|
||||||
|
const mutations: MutationTree<TootsState> = {
|
||||||
|
[MUTATION_TYPES.UPDATE_RESULTS]: (state, results: Array<Status>) => {
|
||||||
|
state.results = results
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const actions: ActionTree<TootsState, RootState> = {
|
||||||
|
search: ({ commit, rootState }, query: string): Promise<Array<Status>> => {
|
||||||
|
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<Results>('/search', { q: query, resolve: true })
|
||||||
|
.then(res => {
|
||||||
|
commit(MUTATION_TYPES.UPDATE_RESULTS, res.data.statuses)
|
||||||
|
return res.data.statuses
|
||||||
|
})
|
||||||
|
.finally(() => {
|
||||||
|
commit('TimelineSpace/Contents/Search/changeLoading', false, { root: true })
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const Toots: Module<TootsState, RootState> = {
|
||||||
|
namespaced: true,
|
||||||
|
state: state,
|
||||||
|
mutations: mutations,
|
||||||
|
actions: actions
|
||||||
|
}
|
||||||
|
|
||||||
|
export default Toots
|
Loading…
Reference in New Issue