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