mirror of
https://github.com/nolanlawson/pinafore
synced 2024-12-13 10:48:19 +01:00
8dbc1b0503
* chore(package): update standard to version 12.0.0 * package lock update * fix eslint
24 lines
764 B
JavaScript
24 lines
764 B
JavaScript
import { store } from '../_store/store'
|
|
import { toast } from '../_utils/toast'
|
|
import { search } from '../_api/search'
|
|
|
|
export async function doSearch () {
|
|
let { currentInstance, accessToken, queryInSearch } = store.get()
|
|
store.set({ searchLoading: true })
|
|
try {
|
|
let results = await search(currentInstance, accessToken, queryInSearch)
|
|
let { queryInSearch: newQueryInSearch } = store.get() // avoid race conditions
|
|
if (newQueryInSearch === queryInSearch) {
|
|
store.set({
|
|
searchResultsForQuery: queryInSearch,
|
|
searchResults: results
|
|
})
|
|
}
|
|
} catch (e) {
|
|
toast.say('Error during search: ' + (e.name || '') + ' ' + (e.message || ''))
|
|
console.error(e)
|
|
} finally {
|
|
store.set({ searchLoading: false })
|
|
}
|
|
}
|