Skip to content

Commit

Permalink
feat: improve onLocationSearch debounce behavior (#1315)
Browse files Browse the repository at this point in the history
- Adjust debounce delay from 1000ms to 500ms for faster response.
- Add `leading: true` option to trigger immediate execution on the first call.
  • Loading branch information
tabiodun authored Dec 13, 2024
1 parent 984b460 commit bf96c7d
Showing 1 changed file with 21 additions and 15 deletions.
36 changes: 21 additions & 15 deletions src/pages/Work.vue
Original file line number Diff line number Diff line change
Expand Up @@ -1983,22 +1983,28 @@ export default defineComponent({
filterLabels.value = labels;
}
const onLocationSearch = _.debounce(async (value: string) => {
const params = {
type__key__in:
'boundary_political_home_local_division,boundary_political_home_postal_code,boundary_political_home_city',
incident_area: currentIncidentId.value,
limit: 10,
search: value,
sort: 'name',
fields: 'id,name,type',
};
const { data } = await axios.get(`/locations`, {
params,
});
const onLocationSearch = _.debounce(
async (value: string) => {
const params = {
type__key__in:
'boundary_political_home_local_division,boundary_political_home_postal_code,boundary_political_home_city',
incident_area: currentIncidentId.value,
limit: 10,
search: value,
sort: 'name',
fields: 'id,name,type',
};
const { data } = await axios.get(`/locations`, {
params,
});
return data.results;
}, 1000); // Every 300ms
return data.results;
},
500,
{
leading: true,
},
); // Every 300ms
watch(
() => worksiteQuery.value,
Expand Down

0 comments on commit bf96c7d

Please sign in to comment.