refs #985 Move account suggest logic to vuex

This commit is contained in:
AkiraFukushima 2019-08-07 22:14:37 +09:00
parent b337526e5a
commit 2c50d0f744
2 changed files with 9 additions and 6 deletions

View File

@ -162,11 +162,7 @@ export default {
},
async suggestAccount(start, word) {
try {
await this.$store.dispatch('TimelineSpace/Modals/NewToot/Status/searchAccount', word)
this.$store.commit('TimelineSpace/Modals/NewToot/Status/changeOpenSuggest', true)
this.$store.commit('TimelineSpace/Modals/NewToot/Status/changeStartIndex', start)
this.$store.commit('TimelineSpace/Modals/NewToot/Status/changeMatchWord', word)
this.$store.commit('TimelineSpace/Modasl/NewToot/Status/filteredSuggestionFromAccounts')
await this.$store.dispatch('TimelineSpace/Modals/NewToot/Status/suggestAccount', { word: word, start: start })
return true
} catch (err) {
console.log(err)

View File

@ -94,11 +94,18 @@ type WordStart = {
}
const actions: ActionTree<StatusState, RootState> = {
searchAccount: async ({ commit, rootState }, word: string) => {
suggestAccount: async ({ commit, rootState }, wordStart: WordStart) => {
commit(MUTATION_TYPES.CLEAR_FILTERED_ACCOUNTS)
commit(MUTATION_TYPES.FILTERED_SUGGESTION_FROM_ACCOUNTS)
const { word, start } = wordStart
const client = new Mastodon(rootState.TimelineSpace.account.accessToken!, rootState.TimelineSpace.account.baseURL + '/api/v1')
const res: Response<Results> = await client.get<Results>('/search', { q: word, resolve: false })
commit(MUTATION_TYPES.UPDATE_FILTERED_ACCOUNTS, res.data.accounts)
if (res.data.accounts.length === 0) throw new Error('Empty')
commit(MUTATION_TYPES.CHANGE_OPEN_SUGGEST, true)
commit(MUTATION_TYPES.CHANGE_START_INDEX, start)
commit(MUTATION_TYPES.CHANGE_MATCH_WORD, word)
commit(MUTATION_TYPES.FILTERED_SUGGESTION_FROM_ACCOUNTS)
return res.data.accounts
},
suggestHashtag: async ({ commit, rootState }, wordStart: WordStart) => {