Skip to content

Commit

Permalink
Fix OracleChain pagination (#90)
Browse files Browse the repository at this point in the history
* Force the redirection of the page

* Return to the first page if the number of page requested don't exists

* Simplify the pagination

* Update version
  • Loading branch information
Samuel authored and Samuel committed Sep 21, 2021
1 parent fd60c0f commit 6402370
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 40 deletions.
29 changes: 17 additions & 12 deletions lib/archethic_web/live/chains/oracle_live.ex
Original file line number Diff line number Diff line change
Expand Up @@ -75,17 +75,22 @@ defmodule ArchEthicWeb.OracleChainLive do
def handle_params(%{"page" => page}, _uri, socket = %{assigns: %{dates: dates}}) do
case Integer.parse(page) do
{number, ""} when number > 0 ->
transactions =
dates
|> Enum.at(number - 1)
|> list_transactions_by_date()

new_assign =
socket
|> assign(:current_date_page, number)
|> assign(:transactions, transactions)

{:noreply, new_assign}
if number > length(dates) do
{:noreply,
push_redirect(socket, to: Routes.live_path(socket, __MODULE__, %{"page" => 1}))}
else
transactions =
dates
|> Enum.at(number - 1)
|> list_transactions_by_date()

new_assign =
socket
|> assign(:current_date_page, number)
|> assign(:transactions, transactions)

{:noreply, new_assign}
end

_ ->
{:noreply, socket}
Expand All @@ -97,7 +102,7 @@ defmodule ArchEthicWeb.OracleChainLive do
end

def handle_event("goto", %{"page" => page}, socket) do
{:noreply, push_patch(socket, to: Routes.live_path(socket, __MODULE__, %{"page" => page}))}
{:noreply, push_redirect(socket, to: Routes.live_path(socket, __MODULE__, %{"page" => page}))}
end

def handle_info(
Expand Down
30 changes: 3 additions & 27 deletions lib/archethic_web/templates/explorer/oracle_chain_index.html.leex
Original file line number Diff line number Diff line change
Expand Up @@ -29,33 +29,9 @@
<a class="pagination-next is-outlined has-text-white" phx-value-page="<%= @current_date_page + 1 %>" phx-click="goto">Next page</a>
<% end %>

<ul class="pagination-list">

<%= if @current_date_page > 1 do %>
<li><a class="pagination-link is-outlined has-text-white" aria-label="Goto page 1" phx-value-page="1", phx-click="goto">1</a></li>
<li><span class="pagination-ellipsis">&hellip;</span></li>
<% end %>

<%= if Enum.count(@dates) == @current_date_page and @current_date_page > 1 do %>
<li><a class="pagination-link is-outlined has-text-white" aria-label="Goto page <%= @current_date_page - 1 %>" phx-value-page="<%= @current_date_page - 1 %>" phx-click="goto"><%= @current_date_page - 1 %></a></li>
<li><a class="pagination-link has-background-white is-outlined has-text-black" aria-label="Page <%= @current_date_page %>" aria-current="page"><%= @current_date_page %></a></li>
<% else %>
<li><a class="pagination-link has-background-white is-outlined has-text-black" aria-label="Page <%= @current_date_page %>" aria-current="page"><%= @current_date_page %></a></li>

<% end %>

<%= cond do %>
<% @current_date_page + 2 <= Enum.count(@dates) -> %>
<li><a class="pagination-link is-outlined has-text-white" aria-label="Goto page <%= @current_date_page + 1 %>" phx-value-page="<%= @current_date_page + 1 %>" phx-click="goto"><%= @current_date_page + 1 %></a></li>
<li><span class="pagination-ellipsis">&hellip;</span></li>
<li><a class="pagination-link is-outlined has-text-white" aria-label="Goto page <%= Enum.count(@dates) %>" phx-value-page="<%= Enum.count(@dates)%>" phx-click="goto"><%= Enum.count(@dates)%></a></li>

<% @current_date_page + 1 == Enum.count(@dates) -> %>
<li><a class="pagination-link is-outlined has-text-white" aria-label="Goto page <%= Enum.count(@dates) %>" phx-value-page="<%= Enum.count(@dates)%>" phx-click="goto"><%= Enum.count(@dates)%></a></li>
<% true -> %>

<% end %>
</ul>
<p class="pagination-list has-text-white">
Page <%= @current_date_page %> on <%= Enum.count(@dates) %>
</p>
</nav>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ defmodule ArchEthic.MixProject do
def project do
[
app: :archethic,
version: "0.11.5",
version: "0.11.6",
build_path: "_build",
config_path: "config/config.exs",
deps_path: "deps",
Expand Down

0 comments on commit 6402370

Please sign in to comment.