mirror of
https://github.com/maybe-finance/maybe.git
synced 2025-07-27 17:19:39 +02:00
Preserve pagination on entry updates (#1563)
* Preserve pagination on entry updates * Test fix
This commit is contained in:
parent
7be6a372bf
commit
a4d10097d5
5 changed files with 41 additions and 15 deletions
|
@ -166,4 +166,24 @@ module ApplicationHelper
|
||||||
|
|
||||||
cookies[:admin] == "true"
|
cookies[:admin] == "true"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def custom_pagy_url_for(pagy, page, current_path: nil)
|
||||||
|
if current_path.blank?
|
||||||
|
pagy_url_for(pagy, page)
|
||||||
|
else
|
||||||
|
uri = URI.parse(current_path)
|
||||||
|
params = URI.decode_www_form(uri.query || "").to_h
|
||||||
|
|
||||||
|
# Delete existing page param if it exists
|
||||||
|
params.delete("page")
|
||||||
|
# Add new page param unless it's page 1
|
||||||
|
params["page"] = page unless page == 1
|
||||||
|
|
||||||
|
if params.empty?
|
||||||
|
uri.path
|
||||||
|
else
|
||||||
|
"#{uri.path}?#{URI.encode_www_form(params)}"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -23,11 +23,9 @@ module Providable
|
||||||
end
|
end
|
||||||
|
|
||||||
def synth_provider
|
def synth_provider
|
||||||
@synth_provider ||= begin
|
|
||||||
api_key = self_hosted? ? Setting.synth_api_key : ENV["SYNTH_API_KEY"]
|
api_key = self_hosted? ? Setting.synth_api_key : ENV["SYNTH_API_KEY"]
|
||||||
api_key.present? ? Provider::Synth.new(api_key) : nil
|
api_key.present? ? Provider::Synth.new(api_key) : nil
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
private
|
private
|
||||||
def self_hosted?
|
def self_hosted?
|
||||||
|
|
|
@ -84,7 +84,7 @@
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="p-4 bg-white rounded-bl-lg rounded-br-lg">
|
<div class="p-4 bg-white rounded-bl-lg rounded-br-lg">
|
||||||
<%= render "pagination", pagy: @pagy %>
|
<%= render "pagination", pagy: @pagy, current_path: account_path(@account, page: params[:page]) %>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
<%# locals: (account:) %>
|
<%# locals: (account:) %>
|
||||||
|
|
||||||
<%= turbo_frame_tag dom_id(account, :entries), src: account_entries_path(account_id: account.id) do %>
|
<%= turbo_frame_tag dom_id(account, :entries), src: account_entries_path(account_id: account.id, page: params[:page]) do %>
|
||||||
<%= render "account/entries/loading" %>
|
<%= render "account/entries/loading" %>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
|
@ -1,9 +1,11 @@
|
||||||
<%# locals: (pagy:) %>
|
<%# locals: (pagy:, current_path: nil) %>
|
||||||
<nav class="flex w-full items-center justify-between">
|
<nav class="flex w-full items-center justify-between">
|
||||||
<div class="flex items-center gap-1">
|
<div class="flex items-center gap-1">
|
||||||
<div>
|
<div>
|
||||||
<% if pagy.prev %>
|
<% if pagy.prev %>
|
||||||
<%= link_to pagy_url_for(pagy, pagy.prev), class: "inline-flex items-center p-2 text-sm font-medium text-gray-500 hover:border-gray-300 hover:text-gray-700" do %>
|
<%= link_to custom_pagy_url_for(pagy, pagy.prev, current_path: current_path),
|
||||||
|
class: "inline-flex items-center p-2 text-sm font-medium text-gray-500 hover:border-gray-300 hover:text-gray-700",
|
||||||
|
data: (current_path ? { turbo_frame: "_top" } : {}) do %>
|
||||||
<%= lucide_icon("chevron-left", class: "w-5 h-5 text-gray-500") %>
|
<%= lucide_icon("chevron-left", class: "w-5 h-5 text-gray-500") %>
|
||||||
<% end %>
|
<% end %>
|
||||||
<% else %>
|
<% else %>
|
||||||
|
@ -15,11 +17,15 @@
|
||||||
<div class="rounded-xl p-1 bg-gray-25">
|
<div class="rounded-xl p-1 bg-gray-25">
|
||||||
<% pagy.series.each do |series_item| %>
|
<% pagy.series.each do |series_item| %>
|
||||||
<% if series_item.is_a?(Integer) %>
|
<% if series_item.is_a?(Integer) %>
|
||||||
<%= link_to pagy_url_for(pagy, series_item), class: "rounded-md px-2 py-1 inline-flex items-center text-sm font-medium text-gray-500 hover:border-gray-300 hover:text-gray-700" do %>
|
<%= link_to custom_pagy_url_for(pagy, series_item, current_path: current_path),
|
||||||
|
class: "rounded-md px-2 py-1 inline-flex items-center text-sm font-medium text-gray-500 hover:border-gray-300 hover:text-gray-700",
|
||||||
|
data: (current_path ? { turbo_frame: "_top" } : {}) do %>
|
||||||
<%= series_item %>
|
<%= series_item %>
|
||||||
<% end %>
|
<% end %>
|
||||||
<% elsif series_item.is_a?(String) %>
|
<% elsif series_item.is_a?(String) %>
|
||||||
<%= link_to pagy_url_for(pagy, series_item), class: "rounded-md px-2 py-1 bg-white border border-alpha-black-25 shadow-xs inline-flex items-center text-sm font-medium text-gray-900" do %>
|
<%= link_to custom_pagy_url_for(pagy, series_item, current_path: current_path),
|
||||||
|
class: "rounded-md px-2 py-1 bg-white border border-alpha-black-25 shadow-xs inline-flex items-center text-sm font-medium text-gray-900",
|
||||||
|
data: (current_path ? { turbo_frame: "_top" } : {}) do %>
|
||||||
<%= series_item %>
|
<%= series_item %>
|
||||||
<% end %>
|
<% end %>
|
||||||
<% elsif series_item == :gap %>
|
<% elsif series_item == :gap %>
|
||||||
|
@ -29,7 +35,9 @@
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<% if pagy.next %>
|
<% if pagy.next %>
|
||||||
<%= link_to pagy_url_for(pagy, pagy.next), class: "inline-flex items-center p-2 text-sm font-medium text-gray-500 hover:border-gray-300 hover:text-gray-700" do %>
|
<%= link_to custom_pagy_url_for(pagy, pagy.next, current_path: current_path),
|
||||||
|
class: "inline-flex items-center p-2 text-sm font-medium text-gray-500 hover:border-gray-300 hover:text-gray-700",
|
||||||
|
data: (current_path ? { turbo_frame: "_top" } : {}) do %>
|
||||||
<%= lucide_icon("chevron-right", class: "w-5 h-5 text-gray-500") %>
|
<%= lucide_icon("chevron-right", class: "w-5 h-5 text-gray-500") %>
|
||||||
<% end %>
|
<% end %>
|
||||||
<% else %>
|
<% else %>
|
||||||
|
@ -40,7 +48,7 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="flex items-center gap-4">
|
<div class="flex items-center gap-4">
|
||||||
<%= form_with url: url_for,
|
<%= form_with url: custom_pagy_url_for(pagy, pagy.page, current_path: current_path),
|
||||||
method: :get,
|
method: :get,
|
||||||
class: "flex items-center gap-4",
|
class: "flex items-center gap-4",
|
||||||
data: { controller: "auto-submit-form" } do |f| %>
|
data: { controller: "auto-submit-form" } do |f| %>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue