diff --git a/assets/js/hooks/countdown.js b/assets/js/hooks/countdown.js index d56eca0e..515af443 100644 --- a/assets/js/hooks/countdown.js +++ b/assets/js/hooks/countdown.js @@ -26,27 +26,28 @@ export const Countdown = { } function formatTimeRemaining(seconds) { - // Calculate days, hours, minutes, and seconds - const days = Math.floor(seconds / (24 * 60 * 60)); // Calculate total days - seconds %= 24 * 60 * 60; // Get remaining seconds after extracting days - const hours = Math.floor(seconds / 3600); // Calculate hours - seconds %= 3600; // Get remaining seconds after extracting hours - const minutes = Math.floor(seconds / 60); // Calculate minutes - const remainingSeconds = seconds % 60; // Remaining seconds - - // Format hours, minutes, and seconds to always be two digits - const formattedHours = String(hours).padStart(2, '0'); - const formattedMinutes = String(minutes).padStart(2, '0'); - const formattedSeconds = String(remainingSeconds).padStart(2, '0'); - - if(days > 0) - return `${days} days, ${formattedHours}:${formattedMinutes}:${formattedSeconds}`; - - if(hours > 0) - return `${formattedHours}:${formattedMinutes}:${formattedSeconds}`; - - if(minutes > 0) - return `${formattedMinutes}:${formattedSeconds}`; - - return `${seconds}`; + const timeUnits = { + days: Math.floor(seconds / (24 * 60 * 60)), + hours: Math.floor((seconds % (24 * 60 * 60)) / 3600), + minutes: Math.floor((seconds % 3600) / 60), + seconds: seconds % 60 + }; + + // Format units to two digits except for days + const formattedTime = { + hours: String(timeUnits.hours).padStart(2, '0'), + minutes: String(timeUnits.minutes).padStart(2, '0'), + seconds: String(timeUnits.seconds).padStart(2, '0') + }; + + if (timeUnits.days > 0) { + return `${timeUnits.days} days, ${formattedTime.hours}:${formattedTime.minutes}:${formattedTime.seconds}`; + } + if (timeUnits.hours > 0) { + return `${formattedTime.hours}:${formattedTime.minutes}:${formattedTime.seconds}`; + } + if (timeUnits.minutes > 0) { + return `${formattedTime.minutes}:${formattedTime.seconds}`; + } + return `${timeUnits.seconds}`; } \ No newline at end of file diff --git a/lib/safira_web.ex b/lib/safira_web.ex index cf3d9822..8dc7bec1 100644 --- a/lib/safira_web.ex +++ b/lib/safira_web.ex @@ -43,7 +43,7 @@ defmodule SafiraWeb do layouts: [html: SafiraWeb.Layouts] import Plug.Conn - import SafiraWeb.Gettext + use Gettext, backend: SafiraWeb.Gettext unquote(verified_routes()) end @@ -117,7 +117,7 @@ defmodule SafiraWeb do # Core UI components and translation import SafiraWeb.CoreComponents import SafiraWeb.Components.Page - import SafiraWeb.Gettext + use Gettext, backend: SafiraWeb.Gettext import SafiraWeb.Helpers diff --git a/lib/safira_web/components/core_components.ex b/lib/safira_web/components/core_components.ex index 061ebd5d..804d1318 100644 --- a/lib/safira_web/components/core_components.ex +++ b/lib/safira_web/components/core_components.ex @@ -19,7 +19,7 @@ defmodule SafiraWeb.CoreComponents do alias Phoenix.HTML.Form alias Phoenix.LiveView.JS - import SafiraWeb.Gettext + use Gettext, backend: SafiraWeb.Gettext @doc """ Renders a modal. diff --git a/lib/safira_web/components/table.ex b/lib/safira_web/components/table.ex index 12514824..ce5e7c81 100644 --- a/lib/safira_web/components/table.ex +++ b/lib/safira_web/components/table.ex @@ -5,7 +5,7 @@ defmodule SafiraWeb.Components.Table do use Phoenix.Component alias Plug.Conn.Query - import SafiraWeb.Gettext + use Gettext, backend: SafiraWeb.Gettexttext import SafiraWeb.CoreComponents attr :id, :string, required: true diff --git a/lib/safira_web/components/table_search.ex b/lib/safira_web/components/table_search.ex index 31ccbe4e..edd76079 100644 --- a/lib/safira_web/components/table_search.ex +++ b/lib/safira_web/components/table_search.ex @@ -3,7 +3,7 @@ defmodule SafiraWeb.Components.TableSearch do Reusable table search component. """ use Phoenix.Component - import SafiraWeb.Gettext + use Gettext, backend: SafiraWeb.Gettext attr :id, :string, required: true attr :params, :map, required: true diff --git a/lib/safira_web/gettext.ex b/lib/safira_web/gettext.ex index 70031be0..c15caef8 100644 --- a/lib/safira_web/gettext.ex +++ b/lib/safira_web/gettext.ex @@ -5,7 +5,7 @@ defmodule SafiraWeb.Gettext do By using [Gettext](https://hexdocs.pm/gettext), your module gains a set of macros for translations, for example: - import SafiraWeb.Gettext + use Gettext, backend: SafiraWeb.Gettext # Simple translation gettext("Here is the string to translate") @@ -20,5 +20,5 @@ defmodule SafiraWeb.Gettext do See the [Gettext Docs](https://hexdocs.pm/gettext) for detailed usage. """ - use Gettext, otp_app: :safira + use Gettext.Backend, otp_app: :safira end diff --git a/lib/safira_web/helpers.ex b/lib/safira_web/helpers.ex index 7868b867..f22e3bc1 100644 --- a/lib/safira_web/helpers.ex +++ b/lib/safira_web/helpers.ex @@ -2,8 +2,8 @@ defmodule SafiraWeb.Helpers do @moduledoc """ Helper functions for web views. """ - alias Timex.Format.DateTime.Formatters.Relative alias Safira.Constants + alias Timex.Format.DateTime.Formatters.Relative require Timex.Translator diff --git a/lib/safira_web/plugs/user_roles.ex b/lib/safira_web/plugs/user_roles.ex index ac99f6de..960426b1 100644 --- a/lib/safira_web/plugs/user_roles.ex +++ b/lib/safira_web/plugs/user_roles.ex @@ -19,7 +19,8 @@ defmodule SafiraWeb.UserRoles do :error, "You haven't assigned a credential to your account. You need one to participate in SEI" ) - |> redirect(to: ~p"/app/") #TODO: Add proper route when implemented + # TODO: Add proper route when implemented + |> redirect(to: ~p"/app/") |> halt() end end diff --git a/mix.exs b/mix.exs index 97eef8e4..e59ee5a7 100644 --- a/mix.exs +++ b/mix.exs @@ -111,7 +111,7 @@ defmodule Safira.MixProject do "esbuild safira --minify", "phx.digest" ], - lint: ["credo -C default"] + lint: ["credo --all --strict"] ] end end