some improved code via credo, sobelow

This commit is contained in:
Adam Piontek 2021-03-29 07:31:52 -04:00
commit 1f99611b56
8 changed files with 40 additions and 36 deletions
lib/shift73k_web/live
shift_assign_live
shift_live

View file

@ -181,6 +181,14 @@ defmodule Shift73kWeb.ShiftAssignLive.Index do
|> assign_known_shifts()
end
defp new_nav_cursor("now", _cursor_date), do: Date.utc_today()
defp new_nav_cursor(nav, cursor_date) do
cursor_date
|> Date.add((nav == "prev" && -30) || 30)
|> cursor_date()
end
@impl true
def handle_event("validate-shift-template", %{"shift_template" => params}, socket) do
params = prep_template_params(params, socket.assigns.current_user)
@ -214,16 +222,7 @@ defmodule Shift73kWeb.ShiftAssignLive.Index do
@impl true
def handle_event("month-nav", %{"month" => nav}, socket) do
new_cursor =
cond do
nav == "now" ->
Date.utc_today()
true ->
socket.assigns.cursor_date
|> Date.add((nav == "prev" && -30) || 30)
|> cursor_date()
end
new_cursor = new_nav_cursor(nav, socket.assigns.cursor_date)
socket
|> assign(:cursor_date, new_cursor)

View file

@ -86,20 +86,19 @@ defmodule Shift73kWeb.ShiftLive.Index do
@impl true
def handle_event("month-nav", %{"month" => nav}, socket) do
new_cursor =
cond do
nav == "now" ->
Date.utc_today()
true ->
socket.assigns.cursor_date
|> Date.add((nav == "prev" && -30) || 30)
|> cursor_date()
end
new_cursor = new_nav_cursor(nav, socket.assigns.cursor_date)
socket
|> assign(:cursor_date, new_cursor)
|> update_agenda()
|> live_noreply()
end
defp new_nav_cursor("now", _cursor_date), do: Date.utc_today()
defp new_nav_cursor(nav, cursor_date) do
cursor_date
|> Date.add((nav == "prev" && -30) || 30)
|> cursor_date()
end
end