From 7b4eae0c132a6280f7cf375330a98f3a0da15f28 Mon Sep 17 00:00:00 2001 From: Kieran Eglin Date: Wed, 29 May 2024 11:46:11 -0700 Subject: [PATCH] Improved large number display on homepage --- .../custom_components/text_components.ex | 8 ++++++++ .../controllers/pages/page_html.ex | 16 ++++++++++++--- .../pages/page_html/home.html.heex | 20 ++++++++++++------- 3 files changed, 34 insertions(+), 10 deletions(-) diff --git a/lib/pinchflat_web/components/custom_components/text_components.ex b/lib/pinchflat_web/components/custom_components/text_components.ex index cba51ee..f3685d6 100644 --- a/lib/pinchflat_web/components/custom_components/text_components.ex +++ b/lib/pinchflat_web/components/custom_components/text_components.ex @@ -94,4 +94,12 @@ defmodule PinchflatWeb.CustomComponents.TextComponents do """ end + + attr :number, :any, required: true + + def localized_number(assigns) do + ~H""" + <%= @number %> + """ + end end diff --git a/lib/pinchflat_web/controllers/pages/page_html.ex b/lib/pinchflat_web/controllers/pages/page_html.ex index bdd0b10..c96a6c9 100644 --- a/lib/pinchflat_web/controllers/pages/page_html.ex +++ b/lib/pinchflat_web/controllers/pages/page_html.ex @@ -5,9 +5,19 @@ defmodule PinchflatWeb.Pages.PageHTML do embed_templates "page_html/*" - def readable_media_filesize(media_filesize) do - {num, suffix} = NumberUtils.human_byte_size(media_filesize, precision: 1) + attr :media_filesize, :integer, required: true - "#{Float.round(num)} #{suffix}" + def readable_media_filesize(assigns) do + {num, suffix} = NumberUtils.human_byte_size(assigns.media_filesize, precision: 2) + + assigns = + Map.merge(assigns, %{ + num: num, + suffix: suffix + }) + + ~H""" + <.localized_number number={@num} /> <%= @suffix %> + """ end 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 ea5b661..05a2803 100644 --- a/lib/pinchflat_web/controllers/pages/page_html/home.html.heex +++ b/lib/pinchflat_web/controllers/pages/page_html/home.html.heex @@ -1,25 +1,31 @@
- Downloaded Media + + <%= if @media_item_count == 1, do: "Download", else: "Downloads" %> +

- <%= @media_item_count %> + <.localized_number number={@media_item_count} />

@@ -27,7 +33,7 @@ Library Size

- <%= readable_media_filesize(@media_item_size) %> + <.readable_media_filesize media_filesize={@media_item_size} />