Skip to content
Permalink
Browse files

create a todo

  • Loading branch information...
dnsbty committed Apr 13, 2019
1 parent 530818d commit b8535b71411afae549e9b22818ec708b55fd1ccd
@@ -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
@@ -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.
You can’t perform that action at this time.