Skip to content

Commit

Permalink
Merge pull request #135 from dwyl/get-person-id-#134
Browse files Browse the repository at this point in the history
Update syntax for get_person_id function
  • Loading branch information
nelsonic authored Aug 15, 2022
2 parents 1f87fa6 + f339023 commit 7e94e47
Showing 1 changed file with 7 additions and 13 deletions.
20 changes: 7 additions & 13 deletions lib/app_web/live/app_live.ex
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,7 @@ defmodule AppWeb.AppLive do

@topic "live"

defp get_person_id(assigns) do
if Map.has_key?(assigns, :person) do
assigns.person.id
else
0
end
end
defp get_person_id(assigns), do: assigns[:person][:id] || 0

@impl true
def mount(_params, _session, socket) do
Expand Down Expand Up @@ -131,7 +125,7 @@ defmodule AppWeb.AppLive do
end

# Elixir implementation of `timer_text/2`
def leftPad(val) do
def left_pad(val) do
if val < 10, do: "0#{to_string(val)}", else: val
end

Expand All @@ -146,17 +140,17 @@ defmodule AppWeb.AppLive do
if diff > 1000 do
s = (diff / 1000) |> trunc()
s = if s > 60, do: Integer.mod(s, 60), else: s
leftPad(s)
left_pad(s)
else
"00"
end

# minutes
m =
if diff > 60000 do
m = (diff / 60000) |> trunc()
if diff > 60_000 do
m = (diff / 60_000) |> trunc()
m = if m > 60, do: Integer.mod(m, 60), else: m
leftPad(m)
left_pad(m)
else
"00"
end
Expand All @@ -165,7 +159,7 @@ defmodule AppWeb.AppLive do
h =
if diff > 3_600_000 do
h = (diff / 3_600_000) |> trunc()
leftPad(h)
left_pad(h)
else
"00"
end
Expand Down

0 comments on commit 7e94e47

Please sign in to comment.