tidying stray dev code

This commit is contained in:
Adam Piontek 2021-03-25 18:09:53 -04:00
parent 326b6624b5
commit 3b5794a401

View file

@ -13,22 +13,21 @@ defmodule Shift73kWeb.ShiftImportLive.Index do
socket socket
|> assign_defaults(session) |> assign_defaults(session)
|> assign(:url_valid, :false) |> assign(:url_valid, false)
|> assign(:url_validated, :false) |> assign(:url_validated, false)
|> assign(:tz_valid, :true) |> assign(:tz_valid, true)
|> live_okreply() |> live_okreply()
end end
@impl true @impl true
def handle_event("validate", %{"ics_import" => %{"ics_url" => url, "time_zone" => tz}}, socket) do def handle_event("validate", %{"ics_import" => %{"ics_url" => url, "time_zone" => tz}}, socket) do
socket socket
|> assign(:url_valid, Regex.match?(@url_regex, url) |> IO.inspect(label: "url valid?")) |> assign(:url_valid, Regex.match?(@url_regex, url))
|> assign(:url_validated, true) |> assign(:url_validated, true)
|> assign(:tz_valid, Enum.member?(Tzdata.zone_list(), tz)) |> assign(:tz_valid, Enum.member?(Tzdata.zone_list(), tz))
|> live_noreply() |> live_noreply()
end end
@impl true @impl true
def handle_event("save", %{"ics_import" => %{"ics_url" => url, "time_zone" => tz}}, socket) do def handle_event("save", %{"ics_import" => %{"ics_url" => url, "time_zone" => tz}}, socket) do
url url
@ -57,16 +56,12 @@ defmodule Shift73kWeb.ShiftImportLive.Index do
defp handle_parsed_ics_data([], socket, tz), do: handle_http_ics_response(false, socket, tz) defp handle_parsed_ics_data([], socket, tz), do: handle_http_ics_response(false, socket, tz)
defp handle_parsed_ics_data(events, socket, tz) do defp handle_parsed_ics_data(events, socket, tz) do
IO.inspect(events, label: "We got some ical events! :") events
IO.inspect(tz, label: "time zone was :") |> Stream.map(&shift_from_event(&1, tz, socket.assigns.current_user.id))
|> Enum.map(&Repo.timestamp/1)
to_insert = |> Shifts.create_multiple()
events |> handle_create_multiple_result(length(events), socket)
|> Stream.map(&shift_from_event(&1, tz, socket.assigns.current_user.id)) |> live_noreply()
|> Enum.map(&Repo.timestamp/1)
|> Shifts.create_multiple()
|> handle_create_multiple_result(length(events), socket)
|> live_noreply()
end end
defp handle_create_multiple_result(result, event_count, socket) do defp handle_create_multiple_result(result, event_count, socket) do
@ -81,14 +76,16 @@ defmodule Shift73kWeb.ShiftImportLive.Index do
if n == event_count do if n == event_count do
{:success, "Successfully imported #{n} event#{s}"} {:success, "Successfully imported #{n} event#{s}"}
else else
{:warning, "Some error, only #{n} event#{s} imported but seemed like iCal contained #{event_count}?"} {:warning,
"Some error, only #{n} event#{s} imported but seemed like iCal contained #{
event_count
}?"}
end end
end end
put_flash(socket, status, msg) put_flash(socket, status, msg)
end end
defp content_type_calendar?(headers) do defp content_type_calendar?(headers) do
headers headers
|> List.keyfind("Content-Type", 0) |> List.keyfind("Content-Type", 0)