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"""

Cell settings

<.switch_checkbox name="enable_formatting" label="Format code when saving to file" checked={not @disable_formatting} />
<.switch_checkbox name="reevaluate_automatically" label="Reevaluate automatically" checked={@reevaluate_automatically} />
<%= live_patch("Cancel", to: @return_to, class: "button-base button-outlined-gray") %>
""" 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