svg preview renderer

This commit is contained in:
zack 2024-10-26 21:41:22 -04:00
parent 43a8412f06
commit faa9599849
No known key found for this signature in database
GPG key ID: 5F873416BCF59F35
29 changed files with 1027 additions and 254 deletions

View file

@ -11,7 +11,8 @@ defmodule ZoeyscomputerWeb.GistLive.Index do
@impl true
def handle_params(params, _url, socket) do
{:noreply, apply_action(socket, socket.assigns.live_action, params)}
live_action = socket.assigns.live_action || :index
{:noreply, apply_action(socket, live_action, params)}
end
defp apply_action(socket, :edit, %{"id" => id}) do
@ -23,7 +24,16 @@ defmodule ZoeyscomputerWeb.GistLive.Index do
defp apply_action(socket, :new, _params) do
socket
|> assign(:page_title, "New Gist")
|> assign(:gist, %Gist{})
|> assign(:gist, %Gist{
code: "",
lang: nil
})
end
defp apply_action(socket, :show, %{"id" => id}) do
socket
|> assign(:page_title, "Show Gist")
|> assign(:gist, Gists.get_gist!(id))
end
defp apply_action(socket, :index, _params) do
@ -32,6 +42,13 @@ defmodule ZoeyscomputerWeb.GistLive.Index do
|> assign(:gist, nil)
end
# Catch-all clause for when live_action is nil
defp apply_action(socket, nil, _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)}