From 033e0fb0a081d86d97456680987763bbf8b2ba87 Mon Sep 17 00:00:00 2001 From: robs Date: Wed, 11 Dec 2024 21:38:05 +0100 Subject: [PATCH 1/3] Separate tabs for pending and downloaded in media history - closes #504 --- .../pages/page_html/history_table_live.ex | 16 ++++++++++++---- .../pages/page_html/home.html.heex | 19 ++++++++++++++++--- 2 files changed, 28 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 ae4748be..6d57116c 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,12 +56,13 @@ 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() + media_state = session["media_state"] + base_query = generate_base_query(media_state) pagination_attrs = fetch_pagination_attributes(base_query, page) - {:ok, assign(socket, Map.merge(pagination_attrs, %{base_query: base_query}))} + {:ok, assign(socket, Map.merge(pagination_attrs, %{base_query: base_query, media_state: media_state}))} end def handle_event("page_change", %{"direction" => direction}, %{assigns: assigns} = socket) do @@ -97,13 +98,20 @@ 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())) |> 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 + defp format_datetime(nil), do: "" defp format_datetime(datetime) do 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"} + )} + +
From 9228448e2dbb41eddf100afd61562b161aef7a91 Mon Sep 17 00:00:00 2001 From: Robert Kleinschuster Date: Fri, 13 Dec 2024 11:34:01 +0000 Subject: [PATCH 2/3] correct query for pending state and remove unecessary assign --- .../controllers/pages/page_html/history_table_live.ex | 7 +++---- 1 file changed, 3 insertions(+), 4 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 6d57116c..e01ae86f 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 @@ -58,11 +58,10 @@ defmodule Pinchflat.Pages.HistoryTableLive do def mount(_params, session, socket) do page = 1 - media_state = session["media_state"] - base_query = generate_base_query(media_state) + 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, media_state: media_state}))} + {:ok, assign(socket, Map.merge(pagination_attrs, %{base_query: base_query}))} end def handle_event("page_change", %{"direction" => direction}, %{assigns: assigns} = socket) do @@ -101,7 +100,7 @@ defmodule Pinchflat.Pages.HistoryTableLive do defp generate_base_query("pending") do MediaQuery.new() |> MediaQuery.require_assoc(:media_profile) - |> where(^dynamic(^MediaQuery.downloaded() or ^MediaQuery.pending())) + |> where(^dynamic(^MediaQuery.downloaded())) |> order_by(desc: :id) end From ab3e2552fbf21c4ab5df13df2df3b3aa66db09ce Mon Sep 17 00:00:00 2001 From: Robert Kleinschuster Date: Fri, 13 Dec 2024 11:35:21 +0000 Subject: [PATCH 3/3] correct pending where --- .../controllers/pages/page_html/history_table_live.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 e01ae86f..eb25d473 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 @@ -100,7 +100,7 @@ defmodule Pinchflat.Pages.HistoryTableLive do defp generate_base_query("pending") do MediaQuery.new() |> MediaQuery.require_assoc(:media_profile) - |> where(^dynamic(^MediaQuery.downloaded())) + |> where(^dynamic(^MediaQuery.pending())) |> order_by(desc: :id) end