defmodule LivebookWeb.SessionLive.CodeCellSettingsComponent do
use LivebookWeb, :live_component
alias Livebook.Session
@impl true
def update(assigns, socket) do
cell = assigns.cell
socket =
socket
|> assign(assigns)
|> assign_new(:disable_formatting, fn -> cell.disable_formatting end)
|> assign_new(:reevaluate_automatically, fn -> cell.reevaluate_automatically end)
{:ok, socket}
end
@impl true
def render(assigns) do
~H"""
"""
end
@impl true
def handle_event(
"save",
%{
"enable_formatting" => enable_formatting,
"reevaluate_automatically" => reevaluate_automatically
},
socket
) do
disable_formatting = enable_formatting == "false"
reevaluate_automatically = reevaluate_automatically == "true"
Session.set_cell_attributes(socket.assigns.session.pid, socket.assigns.cell.id, %{
disable_formatting: disable_formatting,
reevaluate_automatically: reevaluate_automatically
})
{:noreply, push_patch(socket, to: socket.assigns.return_to)}
end
end