diff --git a/assets/controllers/puzzle_search_controller.js b/assets/controllers/puzzle_search_controller.js deleted file mode 100644 index 32f6ab42..00000000 --- a/assets/controllers/puzzle_search_controller.js +++ /dev/null @@ -1,74 +0,0 @@ -import { Controller } from '@hotwired/stimulus'; - -export default class extends Controller { - static targets = ["form", "spinner"]; - - initialize() { - this._onConnect = this._onConnect.bind(this); - } - - connect() { - this.addEventListeners(); - this.element.addEventListener('autocomplete:connect', this._onConnect); - } - - disconnect() { - this.element.removeEventListener('autocomplete:connect', this._onConnect); - } - - _onConnect(event) { - event.detail.tomSelect.on('change', () => this.submitForm()); - } - - addEventListeners() { - document.addEventListener('turbo:frame-load', () => this.hideSpinner()) - - document.addEventListener('turbo:frame-load', (event) => { - const frame = event.target; - const form = this.formTarget; - - // Check if the frame load event is a result of the form submission - if (frame.id === 'search-results') { - const newUrl = new URL(form.action); - const formData = new FormData(form); - formData.forEach((value, key) => newUrl.searchParams.append(key, value)); - } - }); - - // Add listeners for general input and change events - this.formTarget.addEventListener('input', event => { - if (!event.target.matches('[role="combobox"], input[type="radio"], input[type="checkbox"], .tomselected')) { - this.debounceSubmitForm(); - } - }); - - // Immediate submission for radio buttons - this.formTarget.querySelectorAll('input[type=radio], input[type=checkbox]').forEach(input => { - input.addEventListener('change', () => this.submitForm()); - }); - } - - debounceSubmitForm() { - if (this.timeout) { - clearTimeout(this.timeout); - } - - this.timeout = setTimeout(() => { - this.showSpinner(); - this.formTarget.requestSubmit(); - }, 250); - } - - submitForm() { - this.showSpinner(); - this.formTarget.requestSubmit(); - } - - showSpinner() { - this.spinnerTarget.classList.remove('invisible'); - } - - hideSpinner() { - this.spinnerTarget.classList.add('invisible'); - } -} diff --git a/assets/controllers/tomselect_sync_controller.js b/assets/controllers/tomselect_sync_controller.js new file mode 100644 index 00000000..0a40d893 --- /dev/null +++ b/assets/controllers/tomselect_sync_controller.js @@ -0,0 +1,38 @@ +import { Controller } from '@hotwired/stimulus'; +import TomSelect from 'tom-select'; + +/** + * Bridges Tom Select with LiveComponent. + * + * Usage: + *
-
-
- {{ 'loading'|trans }}
-
-
- {{ 'load_more'|trans }}
-
-
-
- {{ 'remaining'|trans({'%puzzle%': remaining }) }}
-
- {{ 'back_to_top'|trans }}
-
{{ 'puzzle_overview.missing_puzzle_info'|trans }}
- {% endif %} - -{{ 'puzzle_overview.missing_puzzle_info'|trans }}
+
+
+
+ {{ 'remaining'|trans({'%puzzle%': this.remainingCount }) }}
+
+ {{ 'back_to_top'|trans }}
+