|
|
|
|
@ -12,24 +12,12 @@ defmodule PlausibleWeb.Live.Components.Pagination do
|
|
|
|
|
>
|
|
|
|
|
<div class="hidden sm:block">
|
|
|
|
|
<p class="text-sm text-gray-700 dark:text-gray-300">
|
|
|
|
|
Showing <span class="font-medium"><%= Enum.count(@page.entries) + @extra_count %></span>
|
|
|
|
|
of <span class="font-medium"><%= @page.metadata.total_count + @extra_count %></span>
|
|
|
|
|
<%= @subject %> total
|
|
|
|
|
<%= render_slot(@inner_block) %>
|
|
|
|
|
</p>
|
|
|
|
|
</div>
|
|
|
|
|
<div class="flex-1 flex justify-between sm:justify-end">
|
|
|
|
|
<.pagination_link
|
|
|
|
|
:if={@page.metadata.before != nil}
|
|
|
|
|
uri={@uri}
|
|
|
|
|
cursor={{"before", @page.metadata.before}}
|
|
|
|
|
label="← Previous"
|
|
|
|
|
/>
|
|
|
|
|
<.pagination_link
|
|
|
|
|
:if={@page.metadata.after != nil}
|
|
|
|
|
uri={@uri}
|
|
|
|
|
cursor={{"after", @page.metadata.after}}
|
|
|
|
|
label="Next →"
|
|
|
|
|
/>
|
|
|
|
|
<.pagination_link uri={@uri} cursor={{"before", @page.metadata.before}} label="← Previous" />
|
|
|
|
|
<.pagination_link uri={@uri} cursor={{"after", @page.metadata.after}} label="Next →" />
|
|
|
|
|
</div>
|
|
|
|
|
</nav>
|
|
|
|
|
"""
|
|
|
|
|
@ -37,15 +25,23 @@ defmodule PlausibleWeb.Live.Components.Pagination do
|
|
|
|
|
|
|
|
|
|
defp pagination_link(assigns) do
|
|
|
|
|
{field, cursor} = assigns.cursor
|
|
|
|
|
active? = not is_nil(cursor)
|
|
|
|
|
params = URI.decode_query(assigns.uri.query, %{field => cursor})
|
|
|
|
|
uri = %{assigns.uri | query: URI.encode_query(params)}
|
|
|
|
|
|
|
|
|
|
assigns = assign(assigns, :uri, uri)
|
|
|
|
|
assigns = assign(assigns, uri: active? && uri, active?: active?)
|
|
|
|
|
|
|
|
|
|
~H"""
|
|
|
|
|
<a
|
|
|
|
|
href={@uri}
|
|
|
|
|
class="pagination-link relative inline-flex items-center px-4 py-2 border border-gray-300 text-sm font-medium rounded-md text-gray-700 bg-white dark:bg-gray-100 hover:bg-gray-50"
|
|
|
|
|
class={[
|
|
|
|
|
"pagination-link relative inline-flex items-center px-4 py-2 border text-sm font-medium rounded-md bg-white dark:bg-gray-100",
|
|
|
|
|
if @active? do
|
|
|
|
|
"border-gray-300 text-gray-700 hover:bg-gray-50"
|
|
|
|
|
else
|
|
|
|
|
"border-gray-300 text-gray-300 dark:bg-gray-600 hover:shadow-none hover:bg-gray-300 cursor-not-allowed"
|
|
|
|
|
end
|
|
|
|
|
]}
|
|
|
|
|
>
|
|
|
|
|
<%= @label %>
|
|
|
|
|
</a>
|
|
|
|
|
|