From 38d0af8ec0860293c59741e55507d57fcc18aa9d Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Bellet Date: Fri, 30 Jun 2023 11:17:42 +0200 Subject: [PATCH] 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 --- app/views/admin/products_v3/_sort.html.haml | 2 +- .../controllers/products_controller.js | 30 ++----------------- 2 files changed, 4 insertions(+), 28 deletions(-) diff --git a/app/views/admin/products_v3/_sort.html.haml b/app/views/admin/products_v3/_sort.html.haml index c20f696851..04ca72236e 100644 --- a/app/views/admin/products_v3/_sort.html.haml +++ b/app/views/admin/products_v3/_sort.html.haml @@ -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" } diff --git a/app/webpacker/controllers/products_controller.js b/app/webpacker/controllers/products_controller.js index 1d831ce50f..b79caee14e 100644 --- a/app/webpacker/controllers/products_controller.js +++ b/app/webpacker/controllers/products_controller.js @@ -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(); }