diff --git a/.gitignore b/.gitignore index 8febc8dc..be491ac3 100644 --- a/.gitignore +++ b/.gitignore @@ -43,8 +43,7 @@ npm-debug.log # VS code elixir_ls folder see https://github.com/JakeBecker/vscode-elixir-ls .elixir_ls -.env - -#elm -elm-stuff/ +# VS code personal run config folder .vscode/ + +.env diff --git a/lib/app_web/live/app_live.ex b/lib/app_web/live/app_live.ex index 9f7fdfc0..0b9ac65d 100644 --- a/lib/app_web/live/app_live.ex +++ b/lib/app_web/live/app_live.ex @@ -129,37 +129,6 @@ defmodule AppWeb.AppLive do {:noreply, assign(socket, editing: nil, editing_timers: [])} end - @nodoc """ - Errors a specific changeset from a list of changesets and returns the updated list of changesets. - You should pass a: - - `timer_changeset_list: list of timer changesets to be updated - - `changeset_to_error`: changeset object that you want to error out - - `changeset_index`: changeset object index inside the list of timer changesets - - `changeset_error_key`: atom key of the changeset object you want to associate the error message - - `changeset_error_message`: the string message to error the changeset key with. - """ - defp error_timer_changeset( - timer_changeset_list, - changeset_to_error, - changeset_index, - changeset_error_key, - changeset_error_message - ) do - # Adding error to changeset - errored_changeset = - Ecto.Changeset.add_error( - changeset_to_error, - changeset_error_key, - changeset_error_message - ) - - {_reply, errored_changeset} = - Ecto.Changeset.apply_action(errored_changeset, :update) - - # Updated list with errored changeset - List.replace_at(timer_changeset_list, changeset_index, errored_changeset) - end - @impl true def handle_event( "update-item-timer", @@ -211,7 +180,7 @@ defmodule AppWeb.AppLive do assign(socket, editing_timers: updated_changeset_timers_list)} end rescue - e -> + _e -> updated_changeset_timers_list = error_timer_changeset( timer_changeset_list, @@ -226,6 +195,37 @@ defmodule AppWeb.AppLive do end end + + # Errors a specific changeset from a list of changesets and returns the updated list of changesets. + # You should pass a: + # - `timer_changeset_list: list of timer changesets to be updated + # - `changeset_to_error`: changeset object that you want to error out + # - `changeset_index`: changeset object index inside the list of timer changesets + # - `changeset_error_key`: atom key of the changeset object you want to associate the error message + # - `changeset_error_message`: the string message to error the changeset key with. + @doc false + defp error_timer_changeset( + timer_changeset_list, + changeset_to_error, + changeset_index, + changeset_error_key, + changeset_error_message + ) do + # Adding error to changeset + errored_changeset = + Ecto.Changeset.add_error( + changeset_to_error, + changeset_error_key, + changeset_error_message + ) + + {_reply, errored_changeset} = + Ecto.Changeset.apply_action(errored_changeset, :update) + + # Updated list with errored changeset + List.replace_at(timer_changeset_list, changeset_index, errored_changeset) + end + @impl true def handle_info(%Broadcast{event: "update", payload: _message}, socket) do person_id = get_person_id(socket.assigns) diff --git a/test/app_web/controllers/tag_controller_test.exs b/test/app_web/controllers/tag_controller_test.exs index 96c5cd0c..b1c92325 100644 --- a/test/app_web/controllers/tag_controller_test.exs +++ b/test/app_web/controllers/tag_controller_test.exs @@ -94,7 +94,7 @@ defmodule AppWeb.TagControllerTest do end defp create_person(_) do - person = Person.create_person(%{"person_id" => 0, "name" => "guest"}) + _person = Person.create_person(%{"person_id" => 0, "name" => "guest"}) person = Person.create_person(%{"person_id" => 1, "name" => "Person1"}) %{person: person} end diff --git a/test/app_web/live/app_live_test.exs b/test/app_web/live/app_live_test.exs index cc839014..77d7d1b2 100644 --- a/test/app_web/live/app_live_test.exs +++ b/test/app_web/live/app_live_test.exs @@ -137,8 +137,6 @@ defmodule AppWeb.AppLiveTest do {:ok, seven_seconds_ago} = NaiveDateTime.new(Date.utc_today(), Time.add(Time.utc_now(), -7)) - {:ok, now} = NaiveDateTime.new(Date.utc_today(), Time.utc_now()) - # Start the timer 7 seconds ago: {:ok, timer} = Timer.start(%{item_id: item.id, person_id: 1, start: seven_seconds_ago})