Skip to content

Commit

Permalink
create a todo
Browse files Browse the repository at this point in the history
  • Loading branch information
dnsbty committed Apr 13, 2019
1 parent 530818d commit b8535b7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
12 changes: 11 additions & 1 deletion lib/live_view_todos_web/live/todo_live.ex
Expand Up @@ -5,10 +5,20 @@ defmodule LiveViewTodosWeb.TodoLive do
alias LiveViewTodosWeb.TodoView

def mount(_session, socket) do
{:ok, assign(socket, todos: Todos.list_todos())}
{:ok, fetch(socket)}
end

def render(assigns) do
TodoView.render("todos.html", assigns)
end

def handle_event("add", %{"todo" => todo}, socket) do
Todos.create_todo(todo)

{:noreply, fetch(socket)}
end

defp fetch(socket) do
assign(socket, %{todos: Todos.list_todos()})
end
end
5 changes: 5 additions & 0 deletions lib/live_view_todos_web/templates/todo/todos.html.leex
@@ -1,3 +1,8 @@
<form action="#" phx-submit="add">
<%= text_input :todo, :title, placeholder: "What do you want to get done?" %>
<%= submit "Add", phx_disable_with: "Adding..." %>
</form>

<%= for todo <- @todos do %>
<div><%= todo.title %></div>
<% end %>

0 comments on commit b8535b7

Please sign in to comment.