defmodule LivebookWeb.SessionLive.InputCellSettingsComponent do
use LivebookWeb, :live_component
alias Livebook.Session
@impl true
def update(assigns, socket) do
cell = assigns.cell
socket =
socket
|> assign(assigns)
|> assign_new(:name, fn -> cell.name end)
|> assign_new(:type, fn -> cell.type end)
{:ok, socket}
end
@impl true
def render(assigns) do
~L"""
"""
end
@impl true
def handle_event("validate", %{"name" => name, "type" => type}, socket) do
type = String.to_existing_atom(type)
{:noreply, assign(socket, name: name, type: type)}
end
def handle_event("save", %{"name" => name, "type" => type}, socket) do
type = String.to_existing_atom(type)
attrs = %{name: name, type: type}
Session.set_cell_attributes(socket.assigns.session_id, socket.assigns.cell.id, attrs)
{:noreply, push_patch(socket, to: socket.assigns.return_to)}
end
end