Skip to content

Commit

Permalink
Remove element from Todos
Browse files Browse the repository at this point in the history
  • Loading branch information
sirion1987 committed Jul 12, 2021
1 parent f603de6 commit c21ad6b
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions lib/todo_app_web/live/todo_live.ex
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ defmodule TodoAppWeb.TodoLive do
phx_value_todo_id: todo.id,
checked: todo.completed %>
<%= todo.title %>
<%= link "Delete",
to: "#",
phx_click: "delete-todo",
phx_value_todo_id: todo.id,
data: [confirm: "Are you sure?"] %>
</li>
<% end %>
</ul>
Expand Down Expand Up @@ -66,6 +71,14 @@ defmodule TodoAppWeb.TodoLive do
{:noreply, assign(socket, changeset: changeset)}
end

def handle_event("delete-todo", %{"todo-id" => id}, socket) do
todo = Todos.get_todo!(id)

{:ok, _} = Todos.delete_todo(todo)

{:noreply, fetch(socket)}
end

defp fetch(socket) do
socket
|> assign(:changeset, Todos.change_todo(%TodoApp.Todos.Todo{}))
Expand Down

0 comments on commit c21ad6b

Please sign in to comment.