2021-03-04 05:56:28 +08:00
|
|
|
defmodule LivebookWeb.SessionsComponent do
|
|
|
|
use LivebookWeb, :live_component
|
2021-02-21 23:54:44 +08:00
|
|
|
|
2021-03-04 05:56:28 +08:00
|
|
|
alias Livebook.SessionSupervisor
|
2021-02-21 23:54:44 +08:00
|
|
|
|
|
|
|
@impl true
|
|
|
|
def render(assigns) do
|
|
|
|
~L"""
|
2021-03-12 18:57:01 +08:00
|
|
|
<div class="flex flex-col space-y-4">
|
2021-02-21 23:54:44 +08:00
|
|
|
<%= for summary <- @session_summaries do %>
|
2021-03-12 18:57:01 +08:00
|
|
|
<div class="p-5 flex items-center border border-gray-200 rounded-lg">
|
|
|
|
<div class="flex-grow flex flex-col space-y-1">
|
|
|
|
<%= live_redirect summary.notebook_name, to: Routes.session_path(@socket, :page, summary.session_id),
|
|
|
|
class: "font-semibold text-gray-800 hover:text-gray-900" %>
|
|
|
|
<div class="text-gray-600 text-sm">
|
|
|
|
<%= summary.path || "No file" %>
|
2021-02-21 23:54:44 +08:00
|
|
|
</div>
|
|
|
|
</div>
|
2021-03-20 21:10:15 +08:00
|
|
|
<div class="relative">
|
|
|
|
<button data-element="menu-toggle">
|
|
|
|
<%= remix_icon("more-2-fill", class: "text-xl action-icon") %>
|
|
|
|
</button>
|
|
|
|
<div class="absolute right-0 z-20 rounded-lg shadow-center bg-white flex flex-col py-2" data-element="menu">
|
|
|
|
<button class="flex space-x-3 px-5 py-2 items-center text-gray-500 hover:bg-gray-50"
|
|
|
|
phx-click="fork_session"
|
|
|
|
phx-value-id="<%= summary.session_id %>"
|
|
|
|
phx-target="<%= @myself %>">
|
|
|
|
<%= remix_icon("git-branch-line") %>
|
|
|
|
<span class="font-medium">Fork</span>
|
|
|
|
</button>
|
|
|
|
<button class="flex space-x-3 px-5 py-2 items-center text-red-600 hover:bg-gray-50"
|
|
|
|
phx-click="delete_session"
|
|
|
|
phx-value-id="<%= summary.session_id %>"
|
|
|
|
phx-target="<%= @myself %>">
|
|
|
|
<%= remix_icon("delete-bin-6-line") %>
|
|
|
|
<span class="font-medium">Delete</span>
|
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
</div>
|
2021-02-21 23:54:44 +08:00
|
|
|
</div>
|
|
|
|
<% end %>
|
|
|
|
</div>
|
|
|
|
"""
|
|
|
|
end
|
|
|
|
|
|
|
|
@impl true
|
|
|
|
def handle_event("delete_session", %{"id" => session_id}, socket) do
|
|
|
|
SessionSupervisor.delete_session(session_id)
|
|
|
|
{:noreply, socket}
|
|
|
|
end
|
2021-03-20 21:10:15 +08:00
|
|
|
|
|
|
|
def handle_event("fork_session", %{"id" => session_id}, socket) do
|
|
|
|
send(self(), {:fork_session, session_id})
|
|
|
|
{:noreply, socket}
|
|
|
|
end
|
2021-02-21 23:54:44 +08:00
|
|
|
end
|