You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
23 lines
609 B
23 lines
609 B
import { Controller } from "@hotwired/stimulus";
|
|
|
|
// Connects to data-controller="hot-search"
|
|
export default class extends Controller {
|
|
connect() {
|
|
this.debouncedSearch = debounce(this.debouncedSearch.bind(this), 400)
|
|
}
|
|
|
|
debouncedSearch() {
|
|
Turbo.visit('/scores?q[name_cont]=' + this.element.value, { frame: 'scores', turbo: true, acceptsStreamResponse: true })
|
|
}
|
|
}
|
|
|
|
function debounce(callback, delay) {
|
|
let timeoutId;
|
|
return (...args) => {
|
|
if (timeoutId) { clearTimeout(timeoutId) }
|
|
timeoutId = setTimeout(() => {
|
|
callback(...args)
|
|
timeoutId = null
|
|
}, delay)
|
|
}
|
|
}
|