diff --git a/assets/js/hooks/floater.js b/assets/js/hooks/floater.js index 25730c39..33bb2e68 100644 --- a/assets/js/hooks/floater.js +++ b/assets/js/hooks/floater.js @@ -111,7 +111,7 @@ function isElementOutOfViewport(el, offsets = {top: 0, bottom:0, left: 0, right: if (!el) { console.log("[floater] el is null", el) - } + } else { const rect = el.getBoundingClientRect(); const { top, bottom, left, right } = offsets; @@ -122,6 +122,8 @@ function isElementOutOfViewport(el, offsets = {top: 0, bottom:0, left: 0, right: rect.bottom + bottom > (window.innerHeight || document.documentElement.clientHeight) || rect.right + right > (window.innerWidth || document.documentElement.clientWidth) ); + + } } export default Floater; diff --git a/assets/js/utils/time_utils.js b/assets/js/utils/time_utils.js index 32ef0c83..17ac0e99 100644 --- a/assets/js/utils/time_utils.js +++ b/assets/js/utils/time_utils.js @@ -7,7 +7,14 @@ * hh:mm:ss e.g. 00:12:05 * */ export const formatDisplayTime = (seconds) => { - return new Date(1000 * seconds).toISOString().substring(11, 19) + let formatted = null + try { + formatted = new Date(1000 * seconds).toISOString().substring(11, 19) + } catch (e) { + console.warn("Errored out when doing time conversions.", e) + } finally { + return formatted + } } export const nowSeconds = () => Math.round(Date.now() / 1000) diff --git a/config/dev.exs b/config/dev.exs index 8e6141ce..a9f55e26 100644 --- a/config/dev.exs +++ b/config/dev.exs @@ -30,7 +30,8 @@ config :ex_aws, :retries, config :vyasa, VyasaWeb.Endpoint, # Binding to loopback ipv4 address prevents access from other machines. # Change to `ip: {0, 0, 0, 0}` to allow access from other machines. - http: [ip: {127, 0, 0, 1}, port: System.get_env("PORT") || 4000], + # http: [ip: {127, 0, 0, 1}, port: System.get_env("PORT") || 4000], + http: [ip: {0, 0, 0, 0}, port: System.get_env("PORT") || 4000], check_origin: false, code_reloader: true, debug_errors: true, diff --git a/lib/utils/string.ex b/lib/utils/string.ex new file mode 100644 index 00000000..c3213e9c --- /dev/null +++ b/lib/utils/string.ex @@ -0,0 +1,11 @@ +defmodule Utils.String do + @moduledoc """ + Contains functions useful for string operations, that need not be + web or server-specific. + """ + @doc """ + Inflexor logic that humanises snake_case string then converts to title case. + """ + def to_title_case(value) when is_binary(value), + do: Recase.to_title(value) +end diff --git a/lib/vyasa_web.ex b/lib/vyasa_web.ex index ebecf936..4bb4bdcb 100644 --- a/lib/vyasa_web.ex +++ b/lib/vyasa_web.ex @@ -108,7 +108,8 @@ defmodule VyasaWeb do # Core UI components and translation import VyasaWeb.CoreComponents import VyasaWeb.Gettext - + #String Formating for Display + import Utils.String, only: [to_title_case: 1] # Shortcut for generating JS commands alias Phoenix.LiveView.JS diff --git a/lib/vyasa_web/live/source_live/chapter/index.ex b/lib/vyasa_web/live/source_live/chapter/index.ex index 005cee87..5c59a750 100644 --- a/lib/vyasa_web/live/source_live/chapter/index.ex +++ b/lib/vyasa_web/live/source_live/chapter/index.ex @@ -99,9 +99,9 @@ defmodule VyasaWeb.SourceLive.Chapter.Index do defp assign_meta(socket) do socket - |> assign(:page_title, "#{socket.assigns.source_title} Chapter #{socket.assigns.chap.no} | #{socket.assigns.chap.title}") + |> assign(:page_title, "#{to_title_case(socket.assigns.source_title)} Chapter #{socket.assigns.chap.no} | #{socket.assigns.chap.title}") |> assign(:meta, %{ - title: "#{socket.assigns.source_title} Chapter #{socket.assigns.chap.no} | #{socket.assigns.chap.title}", + title: "#{to_title_case(socket.assigns.source_title)} Chapter #{socket.assigns.chap.no} | #{socket.assigns.chap.title}", description: socket.assigns.chap.body, type: "website", image: url(~p"/images/the_vyasa_project_1.png"), diff --git a/lib/vyasa_web/live/source_live/chapter/index.html.heex b/lib/vyasa_web/live/source_live/chapter/index.html.heex index 31e17b8b..805d95f5 100644 --- a/lib/vyasa_web/live/source_live/chapter/index.html.heex +++ b/lib/vyasa_web/live/source_live/chapter/index.html.heex @@ -40,5 +40,5 @@ - <.back navigate={~p"/explore/#{@source_title}"}>Back to <%= @source_title %> Chapters + <.back navigate={~p"/explore/#{@source_title}"}>Back to <%= to_title_case(@source_title)%> Chapters diff --git a/lib/vyasa_web/live/source_live/index.ex b/lib/vyasa_web/live/source_live/index.ex index 229745c9..10c2c737 100644 --- a/lib/vyasa_web/live/source_live/index.ex +++ b/lib/vyasa_web/live/source_live/index.ex @@ -17,7 +17,6 @@ defmodule VyasaWeb.SourceLive.Index do socket |> assign(:page_title, "Sources") |> assign_meta() - end defp assign_meta(socket) do diff --git a/lib/vyasa_web/live/source_live/index.html.heex b/lib/vyasa_web/live/source_live/index.html.heex index af9acb69..96a1559d 100644 --- a/lib/vyasa_web/live/source_live/index.html.heex +++ b/lib/vyasa_web/live/source_live/index.html.heex @@ -12,7 +12,7 @@ > <:col :let={{_id, source}} label="">