livebook/lib/livebook_web/live/home_live/close_session_component.ex

40 lines
1.3 KiB
Elixir
Raw Normal View History

defmodule LivebookWeb.HomeLive.CloseSessionComponent do
use LivebookWeb, :live_component
alias LivebookWeb.HomeLive.SessionListComponent
@impl true
def render(assigns) do
~H"""
<div class="p-6 pb-4 flex flex-col space-y-8">
<h3 class="text-2xl font-semibold text-gray-800">
Close session
</h3>
<p class="text-gray-700">
2022-08-02 21:51:02 +08:00
Are you sure you want to close this session - <span class="font-semibold"><%= @session.notebook_name %></span>?
<br />
<%= if @session.file,
2022-08-02 21:51:02 +08:00
do: "This won't delete any persisted files.",
else: "The notebook is not persisted and content may be lost." %>
</p>
<div class="mt-8 flex justify-end space-x-2">
2022-08-02 21:51:02 +08:00
<button
class="button-base button-red"
role="button"
phx-click={SessionListComponent.toggle_edit(:off) |> JS.push("close", target: @myself)}
>
<.remix_icon icon="close-circle-line" class="align-middle mr-1" /> Close session
</button>
2022-08-02 21:51:02 +08:00
<%= live_patch("Cancel", to: @return_to, class: "button-base button-outlined-gray") %>
</div>
</div>
"""
end
@impl true
def handle_event("close", %{}, socket) do
Livebook.Session.close(socket.assigns.session.pid)
{:noreply, push_patch(socket, to: socket.assigns.return_to, replace: true)}
end
end