Simplify: don't need to pass through the js controller

Use the reflex itself

+ Don't need to create a method that will be called only in the connect

+ Simply code by adding only two lifecycle methods

Actually it seems that all reflex related to products controller should show/hide loading
This commit is contained in:
Jean-Baptiste Bellet
2023-06-30 11:17:42 +02:00
parent 9d52f0b20a
commit 38d0af8ec0
2 changed files with 4 additions and 28 deletions

View File

@@ -3,4 +3,4 @@
= t(".pagination.total_html", total: pagy.count, from: pagy.from, to: pagy.to)
%div.with-dropdown
= t(".pagination.per_page.show")
= select_tag :per_page, options_for_select([15, 25, 50, 100].collect{|i| [t('.pagination.per_page.per_page', num: i), i]}, pagy.items), data: { action: "change->products#changePerPage" }
= select_tag :per_page, options_for_select([15, 25, 50, 100].collect{|i| [t('.pagination.per_page.per_page', num: i), i]}, pagy.items), data: { reflex: "change->products#change_per_page" }

View File

@@ -4,38 +4,14 @@ export default class extends ApplicationController {
connect() {
super.connect();
// Fetch the products on page load
this.fetch();
}
fetch = () => {
this.stimulate("Products#fetch");
};
}
changePerPage = (event) => {
this.stimulate("Products#change_per_page", event.target);
};
beforeFilter() {
beforeReflex() {
this.showLoading();
}
afterFilter() {
this.hideLoading();
}
beforeChangePerPage() {
this.showLoading();
}
afterChangePerPage() {
this.hideLoading();
}
beforeFetch() {
this.showLoading();
}
afterFetch() {
afterReflex() {
this.hideLoading();
}