From 6a1b7b016035bf575adb730736437e0a923e1900 Mon Sep 17 00:00:00 2001 From: Kieran Date: Thu, 24 Oct 2024 12:47:48 -0700 Subject: [PATCH] [Enhancement] Misc. UI updates (#434) * Format 'Scheduled At' in task table according to user's TZ * Changed video preview layout to 1 column on all displays * Made links in descriptions clickable * Updated Copy JSON button to properly escape newline characters --- .../custom_components/text_components.ex | 21 ++++++++++++------- .../actions_dropdown.html.heex | 2 +- .../media_item_html/media_preview.heex | 2 +- .../media_item_html/show.html.heex | 9 ++++---- .../actions_dropdown.html.heex | 2 +- .../source_html/actions_dropdown.html.heex | 2 +- .../sources/source_html/show.html.heex | 2 +- 7 files changed, 24 insertions(+), 16 deletions(-) diff --git a/lib/pinchflat_web/components/custom_components/text_components.ex b/lib/pinchflat_web/components/custom_components/text_components.ex index e5cc4eb..9319c55 100644 --- a/lib/pinchflat_web/components/custom_components/text_components.ex +++ b/lib/pinchflat_web/components/custom_components/text_components.ex @@ -62,17 +62,24 @@ defmodule PinchflatWeb.CustomComponents.TextComponents do end @doc """ - Renders a block of text with each line broken into a separate span. + Renders a block of text with each line broken into a separate span and links highlighted. """ attr :text, :string, required: true - def break_on_newline(assigns) do - broken_text = - assigns.text - |> String.split("\n", trim: false) - |> Enum.intersperse(Phoenix.HTML.Tag.tag(:span, class: "inline-block mt-2")) + def render_description(assigns) do + formatted_text = + Regex.split(~r{https?://\S+}, assigns.text, include_captures: true) + |> Enum.map(fn + "http" <> _ = url -> + Phoenix.HTML.Tag.content_tag(:a, url, class: "text-blue-500 hover:text-blue-300", href: url, target: "_blank") - assigns = Map.put(assigns, :text, broken_text) + text -> + text + |> String.split("\n", trim: false) + |> Enum.intersperse(Phoenix.HTML.Tag.tag(:span, class: "inline-block mt-2")) + end) + + assigns = Map.put(assigns, :text, formatted_text) ~H""" <%= @text %> diff --git a/lib/pinchflat_web/controllers/media_items/media_item_html/actions_dropdown.html.heex b/lib/pinchflat_web/controllers/media_items/media_item_html/actions_dropdown.html.heex index fcd4589..cd40fb7 100644 --- a/lib/pinchflat_web/controllers/media_items/media_item_html/actions_dropdown.html.heex +++ b/lib/pinchflat_web/controllers/media_items/media_item_html/actions_dropdown.html.heex @@ -2,7 +2,7 @@ <:option> copied = true, () => copied = false ) diff --git a/lib/pinchflat_web/controllers/media_items/media_item_html/media_preview.heex b/lib/pinchflat_web/controllers/media_items/media_item_html/media_preview.heex index 5ad0533..d5d43be 100644 --- a/lib/pinchflat_web/controllers/media_items/media_item_html/media_preview.heex +++ b/lib/pinchflat_web/controllers/media_items/media_item_html/media_preview.heex @@ -1,5 +1,5 @@ <%= if media_type(@media_item) == :video do %> -