create gists

This commit is contained in:
zack 2024-10-26 15:01:33 -04:00
parent 79a17290d5
commit 43a8412f06
No known key found for this signature in database
GPG key ID: 5F873416BCF59F35
90 changed files with 1777 additions and 2107 deletions

View 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