Have a tiny url state management by using replace_state of cable_ready

This commit is contained in:
Jean-Baptiste Bellet
2023-06-29 17:34:43 +02:00
parent 0fd4d892d9
commit c786f300ca
3 changed files with 16 additions and 2 deletions

View File

@@ -2,6 +2,9 @@
module Admin
class ProductsV3Controller < Spree::Admin::BaseController
def index; end
def index
@page = params[:page] || 1
@per_page = params[:per_page] || 15
end
end
end

View File

@@ -28,6 +28,10 @@ class ProductsReflex < ApplicationReflex
locals: { products: @products, pagy: @pagy })
).broadcast
cable_ready.replace_state(
url: current_url,
).broadcast_later
morph :nothing
end
@@ -60,4 +64,11 @@ class ProductsReflex < ApplicationReflex
# ]
]
end
def current_url
url = URI(request.original_url)
url.query = url.query.present? ? "#{url.query}&" : ""
url.query += "page=#{@page}&per_page=#{@per_page}"
url.to_s
end
end

View File

@@ -10,7 +10,7 @@
= render partial: 'spree/admin/shared/product_sub_menu'
#products_v3_page{"data-controller": "products"}
#products_v3_page{"data-controller": "products", "data-page": @page , "data-perpage": @per_page}
#loading-spinner.spinner-container{ "data-controller": "loading" }
.spinner
= t('.loading')