refs #985 Move account suggest logic to vuex
This commit is contained in:
parent
b337526e5a
commit
2c50d0f744
|
@ -162,11 +162,7 @@ export default {
|
||||||
},
|
},
|
||||||
async suggestAccount(start, word) {
|
async suggestAccount(start, word) {
|
||||||
try {
|
try {
|
||||||
await this.$store.dispatch('TimelineSpace/Modals/NewToot/Status/searchAccount', word)
|
await this.$store.dispatch('TimelineSpace/Modals/NewToot/Status/suggestAccount', { word: word, start: start })
|
||||||
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')
|
|
||||||
return true
|
return true
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.log(err)
|
console.log(err)
|
||||||
|
|
|
@ -94,11 +94,18 @@ type WordStart = {
|
||||||
}
|
}
|
||||||
|
|
||||||
const actions: ActionTree<StatusState, RootState> = {
|
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 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 })
|
const res: Response<Results> = await client.get<Results>('/search', { q: word, resolve: false })
|
||||||
commit(MUTATION_TYPES.UPDATE_FILTERED_ACCOUNTS, res.data.accounts)
|
commit(MUTATION_TYPES.UPDATE_FILTERED_ACCOUNTS, res.data.accounts)
|
||||||
if (res.data.accounts.length === 0) throw new Error('Empty')
|
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
|
return res.data.accounts
|
||||||
},
|
},
|
||||||
suggestHashtag: async ({ commit, rootState }, wordStart: WordStart) => {
|
suggestHashtag: async ({ commit, rootState }, wordStart: WordStart) => {
|
||||||
|
|
Loading…
Reference in New Issue