diff --git a/lib/pinchflat_web/components/custom_components/table_components.ex b/lib/pinchflat_web/components/custom_components/table_components.ex index 166a313..464de2e 100644 --- a/lib/pinchflat_web/components/custom_components/table_components.ex +++ b/lib/pinchflat_web/components/custom_components/table_components.ex @@ -2,7 +2,8 @@ defmodule PinchflatWeb.CustomComponents.TableComponents do @moduledoc false use Phoenix.Component - alias PinchflatWeb.CoreComponents + import PinchflatWeb.CoreComponents + import PinchflatWeb.CustomComponents.TextComponents @doc """ Renders a table component with the given rows and columns. @@ -76,11 +77,13 @@ defmodule PinchflatWeb.CustomComponents.TableComponents do phx-click={@page_number != 1 && "page_change"} phx-value-direction="dec" > - + <.icon name="hero-chevron-left" />
  • - Page <%= @page_number %> of <%= @total_pages %> + + Page <.localized_number number={@page_number} /> of <.localized_number number={@total_pages} /> +
  • - + <.icon name="hero-chevron-right" />
  • diff --git a/lib/pinchflat_web/components/custom_components/text_components.ex b/lib/pinchflat_web/components/custom_components/text_components.ex index f3685d6..e5cc4eb 100644 --- a/lib/pinchflat_web/components/custom_components/text_components.ex +++ b/lib/pinchflat_web/components/custom_components/text_components.ex @@ -95,11 +95,27 @@ defmodule PinchflatWeb.CustomComponents.TextComponents do """ end + @doc """ + Renders a localized number using the Intl.NumberFormat API, falling back to the raw number if needed + """ attr :number, :any, required: true def localized_number(assigns) do ~H""" - <%= @number %> + <%= @number %> + """ + end + + @doc """ + Renders a word with a suffix if the count is not 1 + """ + attr :word, :string, required: true + attr :count, :integer, required: true + attr :suffix, :string, default: "s" + + def pluralize(assigns) do + ~H""" + <%= @word %><%= if @count == 1, do: "", else: @suffix %> """ end end 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 97d570a..13919ab 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 @@ -22,7 +22,9 @@ defmodule Pinchflat.Pages.HistoryTableLive do
    <.icon_button icon_name="hero-arrow-path" class="h-10 w-10" phx-click="reload_page" tooltip="Refresh" /> - Showing <%= length(@records) %> of <%= @total_record_count %> + + Showing <.localized_number number={length(@records)} /> of <.localized_number number={@total_record_count} /> +
    <.table rows={@records} table_class="text-white"> 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 05a2803..b24b104 100644 --- a/lib/pinchflat_web/controllers/pages/page_html/home.html.heex +++ b/lib/pinchflat_web/controllers/pages/page_html/home.html.heex @@ -2,7 +2,7 @@
    - Media <%= if @media_profile_count == 1, do: "Profile", else: "Profiles" %> + Media <.pluralize count={@media_profile_count} word="Profile" />

    <.localized_number number={@media_profile_count} /> @@ -12,7 +12,7 @@
    - <%= if @source_count == 1, do: "Source", else: "Sources" %> + <.pluralize count={@source_count} word="Source" />

    <.localized_number number={@source_count} /> @@ -22,7 +22,7 @@
    - <%= if @media_item_count == 1, do: "Download", else: "Downloads" %> + <.pluralize count={@media_item_count} word="Download" />

    <.localized_number number={@media_item_count} /> diff --git a/lib/pinchflat_web/controllers/sources/source_html/index.html.heex b/lib/pinchflat_web/controllers/sources/source_html/index.html.heex index a064d53..5913d30 100644 --- a/lib/pinchflat_web/controllers/sources/source_html/index.html.heex +++ b/lib/pinchflat_web/controllers/sources/source_html/index.html.heex @@ -19,11 +19,12 @@ <:col :let={source} label="Type"><%= source.collection_type %> - <:col :let={source} label="Pending"><%= source.pending_count %> - <:col :let={source} label="Downloaded"><%= source.downloaded_count %> + <:col :let={source} label="Pending"><.localized_number number={source.pending_count} /> + <:col :let={source} label="Downloaded"><.localized_number number={source.downloaded_count} /> <:col :let={source} label="Retention"> <%= if source.retention_period_days && source.retention_period_days > 0 do %> - <%= source.retention_period_days %> day(s) + <.localized_number number={source.retention_period_days} /> + <.pluralize count={source.retention_period_days} word="day" /> <% else %> <% end %> 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 a0a1a3a..fd14a3a 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 @@ -23,7 +23,9 @@ defmodule Pinchflat.Sources.MediaItemTableLive do
    <.icon_button icon_name="hero-arrow-path" class="h-10 w-10" phx-click="reload_page" tooltip="Refresh" /> - Showing <%= length(@records) %> of <%= @filtered_record_count %> + + Showing <.localized_number number={length(@records)} /> of <.localized_number number={@filtered_record_count} /> +
    @@ -49,12 +51,12 @@ defmodule Pinchflat.Sources.MediaItemTableLive do <%= StringUtils.truncate(media_item.title, 50) %> - <:col :let={media_item} label="Upload Date"> - <%= DateTime.to_date(media_item.uploaded_at) %> - <: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"} /> + <:col :let={media_item} label="Upload Date"> + <%= DateTime.to_date(media_item.uploaded_at) %> + <:col :let={media_item} label="" class="flex justify-end"> <.icon_link href={~p"/sources/#{@source.id}/media/#{media_item.id}/edit"} icon="hero-pencil-square" class="mr-4" /> diff --git a/lib/pinchflat_web/controllers/sources/source_html/source_form.html.heex b/lib/pinchflat_web/controllers/sources/source_html/source_form.html.heex index 6a53a3a..88b584d 100644 --- a/lib/pinchflat_web/controllers/sources/source_html/source_form.html.heex +++ b/lib/pinchflat_web/controllers/sources/source_html/source_form.html.heex @@ -95,7 +95,8 @@ type="number" label="Retention Period (days)" min="0" - help="Days between when media is *downloaded* and when it's deleted. Leave blank to keep media indefinitely" + help="Days between when media is downloaded and when it's deleted. Leave blank to keep media indefinitely" + html_help={true} />
    diff --git a/test/pinchflat_web/controllers/sources/media_item_table_live_test.exs b/test/pinchflat_web/controllers/sources/media_item_table_live_test.exs index f584377..772e305 100644 --- a/test/pinchflat_web/controllers/sources/media_item_table_live_test.exs +++ b/test/pinchflat_web/controllers/sources/media_item_table_live_test.exs @@ -27,7 +27,7 @@ defmodule PinchflatWeb.Sources.MediaItemTableLiveTest do {:ok, _view, html} = live_isolated(conn, MediaItemTableLive, session: create_session(source)) - assert html =~ "Showing 1 of 1" + assert html =~ "Showing" assert html =~ "Title" assert html =~ media_item.title end