From ecd9d0e96f8b37d36bd39591f640d2068fb5abc1 Mon Sep 17 00:00:00 2001 From: Kieran Eglin Date: Tue, 11 Feb 2025 12:58:10 -0800 Subject: [PATCH] Added help tooltip to source content view --- .../custom_components/button_components.ex | 16 ++---- .../custom_components/text_components.ex | 52 +++++++++++++++++++ .../media_profile_html/show.html.heex | 4 +- .../source_html/media_item_table_live.ex | 22 ++++++-- 4 files changed, 74 insertions(+), 20 deletions(-) diff --git a/lib/pinchflat_web/components/custom_components/button_components.ex b/lib/pinchflat_web/components/custom_components/button_components.ex index f1f3470..95f16cf 100644 --- a/lib/pinchflat_web/components/custom_components/button_components.ex +++ b/lib/pinchflat_web/components/custom_components/button_components.ex @@ -3,6 +3,7 @@ defmodule PinchflatWeb.CustomComponents.ButtonComponents do use Phoenix.Component, global_prefixes: ~w(x-) alias PinchflatWeb.CoreComponents + alias PinchflatWeb.CustomComponents.TextComponents @doc """ Render a button @@ -104,7 +105,7 @@ defmodule PinchflatWeb.CustomComponents.ButtonComponents do def icon_button(assigns) do ~H""" -
+ -
- - - {@tooltip} -
-
+ """ end end diff --git a/lib/pinchflat_web/components/custom_components/text_components.ex b/lib/pinchflat_web/components/custom_components/text_components.ex index 2145bae..8293b51 100644 --- a/lib/pinchflat_web/components/custom_components/text_components.ex +++ b/lib/pinchflat_web/components/custom_components/text_components.ex @@ -146,4 +146,56 @@ defmodule PinchflatWeb.CustomComponents.TextComponents do <.localized_number number={@num} /> {@suffix} """ end + + attr :tooltip, :string, required: true + attr :position, :string, default: "" + attr :tooltip_class, :any, default: "" + attr :tooltip_arrow_class, :any, default: "" + slot :inner_block + + def tooltip(%{position: "bottom-right"} = assigns) do + ~H""" + <.tooltip tooltip={@tooltip} tooltip_class={@tooltip_class} tooltip_arrow_class={["-top-1", @tooltip_arrow_class]}> + {render_slot(@inner_block)} + + """ + end + + def tooltip(%{position: "bottom"} = assigns) do + ~H""" + <.tooltip + tooltip={@tooltip} + tooltip_class={["left-1/2 -translate-x-1/2", @tooltip_class]} + tooltip_arrow_class={["-top-1 left-1/2 -translate-x-1/2", @tooltip_arrow_class]} + > + {render_slot(@inner_block)} + + """ + end + + def tooltip(assigns) do + ~H""" +
+
+ {render_slot(@inner_block)} +
+
+ + +
{@tooltip}
+
+
+ """ + end end diff --git a/lib/pinchflat_web/controllers/media_profiles/media_profile_html/show.html.heex b/lib/pinchflat_web/controllers/media_profiles/media_profile_html/show.html.heex index 9f1a220..641296e 100644 --- a/lib/pinchflat_web/controllers/media_profiles/media_profile_html/show.html.heex +++ b/lib/pinchflat_web/controllers/media_profiles/media_profile_html/show.html.heex @@ -26,8 +26,8 @@ <:tab title="Media Profile" id="media-profile">
-

Raw Attributes

- <.list_items_from_map map={Map.from_struct(@media_profile)} /> +

Raw Attributes

+ <.list_items_from_map map={Map.from_struct(@media_profile)} />
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 bbcf681..604ee49 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 @@ -46,10 +46,22 @@ defmodule PinchflatWeb.Sources.MediaItemTableLive do <.table rows={@records} table_class="text-white"> - <:col :let={media_item} label="Title" class="truncate max-w-xs"> - <.subtle_link href={~p"/sources/#{@source.id}/media/#{media_item.id}"}> - {media_item.title} - + <:col :let={media_item} label="Title" class="max-w-xs"> +
+ <.tooltip + :if={media_item.last_error} + tooltip={media_item.last_error} + position="bottom-right" + tooltip_class="w-64" + > + <.icon name="hero-exclamation-circle-solid" class="text-red-500" /> + + + <.subtle_link href={~p"/sources/#{@source.id}/media/#{media_item.id}"}> + {media_item.title} + + +
<:col :let={media_item} :if={@media_state == "other"} label="Manually Ignored?"> <.icon name={if media_item.prevent_download, do: "hero-check", else: "hero-x-mark"} /> @@ -205,6 +217,6 @@ defmodule PinchflatWeb.Sources.MediaItemTableLive do # Selecting only what we need GREATLY speeds up queries on large tables defp select_fields do - [:id, :title, :uploaded_at, :prevent_download] + [:id, :title, :uploaded_at, :prevent_download, :last_error] end end