You've already forked AstralRinth
forked from didirus/AstralRinth
Throttle search to not spam requests (#4893)
* Throttle search to not spam requests * lint
This commit is contained in:
@@ -27,6 +27,7 @@ import {
|
|||||||
useSearch,
|
useSearch,
|
||||||
} from '@modrinth/ui'
|
} from '@modrinth/ui'
|
||||||
import { capitalizeString, cycleValue, type Mod as InstallableMod } from '@modrinth/utils'
|
import { capitalizeString, cycleValue, type Mod as InstallableMod } from '@modrinth/utils'
|
||||||
|
import { useThrottleFn } from '@vueuse/core'
|
||||||
import { computed, type Reactive } from 'vue'
|
import { computed, type Reactive } from 'vue'
|
||||||
|
|
||||||
import LogoAnimated from '~/components/brand/LogoAnimated.vue'
|
import LogoAnimated from '~/components/brand/LogoAnimated.vue'
|
||||||
@@ -274,6 +275,7 @@ const {
|
|||||||
return `${base}search${requestParams.value}`
|
return `${base}search${requestParams.value}`
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
watch: false,
|
||||||
transform: (hits) => {
|
transform: (hits) => {
|
||||||
noLoad.value = false
|
noLoad.value = false
|
||||||
return hits as Labrinth.Search.v2.SearchResults
|
return hits as Labrinth.Search.v2.SearchResults
|
||||||
@@ -331,6 +333,8 @@ watch([currentFilters], () => {
|
|||||||
updateSearchResults(1, false)
|
updateSearchResults(1, false)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const throttledSearch = useThrottleFn(() => updateSearchResults(), 500, true)
|
||||||
|
|
||||||
function cycleSearchDisplayMode() {
|
function cycleSearchDisplayMode() {
|
||||||
if (!resultsDisplayLocation.value) {
|
if (!resultsDisplayLocation.value) {
|
||||||
// if no display location, abort
|
// if no display location, abort
|
||||||
@@ -517,9 +521,18 @@ useSeoMeta({
|
|||||||
spellcheck="false"
|
spellcheck="false"
|
||||||
type="text"
|
type="text"
|
||||||
:placeholder="`Search ${projectType.display}s...`"
|
:placeholder="`Search ${projectType.display}s...`"
|
||||||
@input="updateSearchResults()"
|
@input="throttledSearch()"
|
||||||
/>
|
/>
|
||||||
<Button v-if="query" class="r-btn" @click="() => (query = '')">
|
<Button
|
||||||
|
v-if="query"
|
||||||
|
class="r-btn"
|
||||||
|
@click="
|
||||||
|
() => {
|
||||||
|
query = ''
|
||||||
|
updateSearchResults()
|
||||||
|
}
|
||||||
|
"
|
||||||
|
>
|
||||||
<XIcon />
|
<XIcon />
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user