From e56f39a15829f5568b00466e2661346c89662a1d Mon Sep 17 00:00:00 2001 From: Robert Kleinschuster Date: Fri, 13 Dec 2024 17:58:42 +0100 Subject: [PATCH] Separate tabs for pending and downloaded in media history (#508) * Separate tabs for pending and downloaded in media history - closes #504 * correct query for pending state and remove unecessary assign * correct pending where --------- Co-authored-by: robs --- .../pages/page_html/history_table_live.ex | 15 +++++++++++---- .../pages/page_html/home.html.heex | 19 ++++++++++++++++--- 2 files changed, 27 insertions(+), 7 deletions(-) diff --git a/lib/pinchflat_web/controllers/pages/page_html/history_table_live.ex b/lib/pinchflat_web/controllers/pages/page_html/history_table_live.ex index 737357f5..d2cab174 100644 --- a/lib/pinchflat_web/controllers/pages/page_html/history_table_live.ex +++ b/lib/pinchflat_web/controllers/pages/page_html/history_table_live.ex @@ -56,9 +56,9 @@ defmodule Pinchflat.Pages.HistoryTableLive do """ end - def mount(_params, _session, socket) do + def mount(_params, session, socket) do page = 1 - base_query = generate_base_query() + base_query = generate_base_query(session["media_state"]) pagination_attrs = fetch_pagination_attributes(base_query, page) {:ok, assign(socket, Map.merge(pagination_attrs, %{base_query: base_query}))} @@ -97,10 +97,17 @@ defmodule Pinchflat.Pages.HistoryTableLive do |> Repo.preload(:source) end - defp generate_base_query do + defp generate_base_query("pending") do MediaQuery.new() |> MediaQuery.require_assoc(:media_profile) - |> where(^dynamic(^MediaQuery.downloaded() or ^MediaQuery.pending())) + |> where(^dynamic(^MediaQuery.pending())) + |> order_by(desc: :id) + end + + defp generate_base_query("downloaded") do + MediaQuery.new() + |> MediaQuery.require_assoc(:media_profile) + |> where(^dynamic(^MediaQuery.downloaded())) |> order_by(desc: :id) end diff --git a/lib/pinchflat_web/controllers/pages/page_html/home.html.heex b/lib/pinchflat_web/controllers/pages/page_html/home.html.heex index bd744468..a70eb28a 100644 --- a/lib/pinchflat_web/controllers/pages/page_html/home.html.heex +++ b/lib/pinchflat_web/controllers/pages/page_html/home.html.heex @@ -41,9 +41,22 @@
Media History -
- {live_render(@conn, Pinchflat.Pages.HistoryTableLive)} -
+ <.tabbed_layout> + <:tab title="Downloaded" id="downloaded"> + {live_render( + @conn, + Pinchflat.Pages.HistoryTableLive, + session: %{"media_state" => "downloaded"} + )} + + <:tab title="Pending" id="pending"> + {live_render( + @conn, + Pinchflat.Pages.HistoryTableLive, + session: %{"media_state" => "pending"} + )} + +