This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# html input | |
<input id="search-input" data-reflex="keyup->FilterReflex#results"> | |
# .rb Reflex | |
class FilterReflex < ApplicationReflex | |
def results | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<%= form_with(url: '/', data: { reflex: "submit->FilterReflex#results" }) do %> | |
<!-- | |
A bunch of <input> fields and <select> tags. | |
--> | |
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<%== pagy_nav(@pagy, link_extra: "data-reflex='click->FilterReflex#results") %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# FilterReflex#results | |
page = element.href&.split('=')&.last&.to_i || 1 | |
# And pass it to pagy collection | |
pagy, collection = pagy(active_record_collection, page: page) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def filtered_params | |
params.permit(…) | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def results | |
params_hash = element.dataset['params-hash'].present? ? JSON.parse(element.dataset['params-hash']) : filtered_params | |
pagy, collection = pagy(active_record_collection(filters), page: page) | |
# The HTML provided can be a partial or ViewComponent (as we use in our case) | |
cable_ready.morph( | |
children_only: true, | |
selector: '#id_of_a_dom_element', | |
html: render( | |
PaginationComponent.new( |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<%== pagy_nav(@pagy, link_extra: "data-reflex='click->FilterReflex#results data-params-hash='#{@params_hash}'") %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def results | |
params_hash = element.dataset['params-hash'].present? ? JSON.parse(element.dataset['params-hash']) : filtered_params | |
query = element.value.presence || params_hash['query'] | |
params_hash['query'] = query | |
… | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<input id="search-input" data-reflex="keyup->FilterReflex#results" data-from-search-input="true"> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def results | |
params_hash = element.dataset['params-hash'].present? ? JSON.parse(element.dataset['params-hash']) : filtered_params | |
query = (element.dataset.from_search_input ? element.value : element.value.presence) || params_hash['query'] | |
params_hash['query'] = query | |
… | |
end |
OlderNewer