Added reload button to live tables (#223)
This commit is contained in:
@@ -11,17 +11,33 @@ defmodule Pinchflat.Sources.MediaItemTableLive do
|
|||||||
|
|
||||||
def render(%{records: []} = assigns) do
|
def render(%{records: []} = assigns) do
|
||||||
~H"""
|
~H"""
|
||||||
<p class="text-black dark:text-white">Nothing Here!</p>
|
<div class="mb-4 flex items-center">
|
||||||
|
<button
|
||||||
|
class="flex justify-center items-center rounded-lg bg-form-input border-2 border-strokedark h-10 w-10"
|
||||||
|
phx-click="reload_page"
|
||||||
|
type="button"
|
||||||
|
>
|
||||||
|
<.icon name="hero-arrow-path" class="text-stroke" />
|
||||||
|
</button>
|
||||||
|
<p class="ml-2">Nothing Here!</p>
|
||||||
|
</div>
|
||||||
"""
|
"""
|
||||||
end
|
end
|
||||||
|
|
||||||
def render(assigns) do
|
def render(assigns) do
|
||||||
~H"""
|
~H"""
|
||||||
<div>
|
<div>
|
||||||
<span class="mb-4 inline-block">
|
<span class="mb-4 flex items-center">
|
||||||
Showing <%= length(@records) %> of <%= @total_record_count %>
|
<button
|
||||||
|
class="flex justify-center items-center rounded-lg bg-form-input border-2 border-strokedark h-10 w-10"
|
||||||
|
phx-click="reload_page"
|
||||||
|
type="button"
|
||||||
|
>
|
||||||
|
<.icon name="hero-arrow-path" class="text-stroke" />
|
||||||
|
</button>
|
||||||
|
<span class="ml-2">Showing <%= length(@records) %> of <%= @total_record_count %></span>
|
||||||
</span>
|
</span>
|
||||||
<.table rows={@records} table_class="text-black dark:text-white">
|
<.table rows={@records} table_class="text-white">
|
||||||
<:col :let={media_item} label="Title">
|
<:col :let={media_item} label="Title">
|
||||||
<.subtle_link href={~p"/sources/#{@source.id}/media/#{media_item.id}"}>
|
<.subtle_link href={~p"/sources/#{@source.id}/media/#{media_item.id}"}>
|
||||||
<%= StringUtils.truncate(media_item.title, 50) %>
|
<%= StringUtils.truncate(media_item.title, 50) %>
|
||||||
@@ -57,6 +73,12 @@ defmodule Pinchflat.Sources.MediaItemTableLive do
|
|||||||
{:noreply, assign(socket, new_assigns)}
|
{:noreply, assign(socket, new_assigns)}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def handle_event("reload_page", _params, %{assigns: assigns} = socket) do
|
||||||
|
new_assigns = fetch_pagination_attributes(assigns.base_query, assigns.page)
|
||||||
|
|
||||||
|
{:noreply, assign(socket, new_assigns)}
|
||||||
|
end
|
||||||
|
|
||||||
defp fetch_pagination_attributes(base_query, page) do
|
defp fetch_pagination_attributes(base_query, page) do
|
||||||
total_record_count = Repo.aggregate(base_query, :count, :id)
|
total_record_count = Repo.aggregate(base_query, :count, :id)
|
||||||
total_pages = max(ceil(total_record_count / @limit), 1)
|
total_pages = max(ceil(total_record_count / @limit), 1)
|
||||||
|
|||||||
@@ -64,7 +64,7 @@
|
|||||||
</:col>
|
</:col>
|
||||||
</.table>
|
</.table>
|
||||||
<% else %>
|
<% else %>
|
||||||
<p class="text-black dark:text-white">Nothing Here!</p>
|
<p>Nothing Here!</p>
|
||||||
<% end %>
|
<% end %>
|
||||||
</:tab>
|
</:tab>
|
||||||
</.tabbed_layout>
|
</.tabbed_layout>
|
||||||
|
|||||||
Reference in New Issue
Block a user