From f2c9c10437c6696b7444dd93942cd4ad1f8e0689 Mon Sep 17 00:00:00 2001 From: Kieran Date: Thu, 2 May 2024 12:09:55 -0700 Subject: [PATCH] Added reload button to live tables (#223) --- .../source_html/media_item_table_live.ex | 30 ++++++++++++++++--- .../sources/source_html/show.html.heex | 2 +- 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/lib/pinchflat_web/controllers/sources/source_html/media_item_table_live.ex b/lib/pinchflat_web/controllers/sources/source_html/media_item_table_live.ex index bc2705c..8c56d97 100644 --- a/lib/pinchflat_web/controllers/sources/source_html/media_item_table_live.ex +++ b/lib/pinchflat_web/controllers/sources/source_html/media_item_table_live.ex @@ -11,17 +11,33 @@ defmodule Pinchflat.Sources.MediaItemTableLive do def render(%{records: []} = assigns) do ~H""" -

Nothing Here!

+
+ +

Nothing Here!

+
""" end def render(assigns) do ~H"""
- - Showing <%= length(@records) %> of <%= @total_record_count %> + + + Showing <%= length(@records) %> of <%= @total_record_count %> - <.table rows={@records} table_class="text-black dark:text-white"> + <.table rows={@records} table_class="text-white"> <:col :let={media_item} label="Title"> <.subtle_link href={~p"/sources/#{@source.id}/media/#{media_item.id}"}> <%= StringUtils.truncate(media_item.title, 50) %> @@ -57,6 +73,12 @@ defmodule Pinchflat.Sources.MediaItemTableLive do {:noreply, assign(socket, new_assigns)} 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 total_record_count = Repo.aggregate(base_query, :count, :id) total_pages = max(ceil(total_record_count / @limit), 1) diff --git a/lib/pinchflat_web/controllers/sources/source_html/show.html.heex b/lib/pinchflat_web/controllers/sources/source_html/show.html.heex index 2d110c4..0f8869d 100644 --- a/lib/pinchflat_web/controllers/sources/source_html/show.html.heex +++ b/lib/pinchflat_web/controllers/sources/source_html/show.html.heex @@ -64,7 +64,7 @@ <% else %> -

Nothing Here!

+

Nothing Here!

<% end %>