Skip to content

Commit

Permalink
fix: Fixing warnings.
Browse files Browse the repository at this point in the history
  • Loading branch information
LuchoTurtle committed Nov 8, 2022
1 parent d8360f7 commit 2642334
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 39 deletions.
7 changes: 3 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
64 changes: 32 additions & 32 deletions lib/app_web/live/app_live.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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,
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion test/app_web/controllers/tag_controller_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions test/app_web/live/app_live_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand Down

0 comments on commit 2642334

Please sign in to comment.