Sha256: 29251dce1dbed6366573653f5a71d798e297bfb655931404305a47ec83e95e94

Contents?: true

Size: 775 Bytes

Versions: 10

Compression:

Stored size: 775 Bytes

Contents

import { Controller } from "@hotwired/stimulus";
import { Turbo } from "@hotwired/turbo-rails";

export default class TurboCollectionController extends Controller {
  static values = {
    query: String,
    sort: String,
  };

  queryValueChanged(query) {
    Turbo.navigator.history.replace(this.#url(query));
  }

  sortValueChanged(sort) {
    document.querySelectorAll(this.#sortSelector).forEach((input) => {
      if (input) input.value = sort;
    });
  }

  get #sortSelector() {
    return "input[name='sort']";
  }

  #url(query) {
    const frame = this.element.closest("turbo-frame");
    let url;

    if (frame) {
      url = new URL(frame.baseURI);
    } else {
      url = new URL(window.location.href);
    }

    url.search = query;

    return url;
  }
}

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
katalyst-tables-3.0.0.beta1 app/javascript/tables/turbo/collection_controller.js
katalyst-tables-2.6.0 app/javascript/tables/turbo/collection_controller.js
katalyst-tables-2.6.0.beta app/javascript/tables/turbo/collection_controller.js
katalyst-tables-2.5.0 app/javascript/tables/turbo/collection_controller.js
katalyst-tables-2.4.0 app/javascript/tables/turbo/collection_controller.js
katalyst-tables-2.3.1 app/javascript/tables/turbo/collection_controller.js
katalyst-tables-2.3.0 app/javascript/tables/turbo/turbo_collection_controller.js
katalyst-tables-2.2.12 app/assets/javascripts/controllers/tables/turbo_collection_controller.js
katalyst-tables-2.2.11 app/assets/javascripts/controllers/tables/turbo_collection_controller.js
katalyst-tables-2.2.10 app/assets/javascripts/controllers/tables/turbo_collection_controller.js