create gists
This commit is contained in:
parent
79a17290d5
commit
43a8412f06
90 changed files with 1777 additions and 2107 deletions
47
lib/zoeyscomputer_web/live/gist_live/index.ex
Normal file
47
lib/zoeyscomputer_web/live/gist_live/index.ex
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
defmodule ZoeyscomputerWeb.GistLive.Index do
|
||||
use ZoeyscomputerWeb, :live_view
|
||||
|
||||
alias Zoeyscomputer.Gists
|
||||
alias Zoeyscomputer.Gists.Gist
|
||||
|
||||
@impl true
|
||||
def mount(_params, _session, socket) do
|
||||
{:ok, stream(socket, :gists, Gists.list_gists())}
|
||||
end
|
||||
|
||||
@impl true
|
||||
def handle_params(params, _url, socket) do
|
||||
{:noreply, apply_action(socket, socket.assigns.live_action, params)}
|
||||
end
|
||||
|
||||
defp apply_action(socket, :edit, %{"id" => id}) do
|
||||
socket
|
||||
|> assign(:page_title, "Edit Gist")
|
||||
|> assign(:gist, Gists.get_gist!(id))
|
||||
end
|
||||
|
||||
defp apply_action(socket, :new, _params) do
|
||||
socket
|
||||
|> assign(:page_title, "New Gist")
|
||||
|> assign(:gist, %Gist{})
|
||||
end
|
||||
|
||||
defp apply_action(socket, :index, _params) do
|
||||
socket
|
||||
|> assign(:page_title, "Listing Gists")
|
||||
|> assign(:gist, nil)
|
||||
end
|
||||
|
||||
@impl true
|
||||
def handle_info({ZoeyscomputerWeb.GistLive.FormComponent, {:saved, gist}}, socket) do
|
||||
{:noreply, stream_insert(socket, :gists, gist)}
|
||||
end
|
||||
|
||||
@impl true
|
||||
def handle_event("delete", %{"id" => id}, socket) do
|
||||
gist = Gists.get_gist!(id)
|
||||
{:ok, _} = Gists.delete_gist(gist)
|
||||
|
||||
{:noreply, stream_delete(socket, :gists, gist)}
|
||||
end
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue