livebook/lib/live_book_web/live/sessions_component.ex
Jonatan Kłosko 0925ec77cd
Implement notebook persistence and import (#44)
* Basic filesystem navigation

* Add file picker modal

* Implement autosave when dirty and show the status

* Add hompage link in the session view

* Improve file picker and use in both places

* Move session list to homepage

* Some refactoring

* Show import messages if any

* Fix and extend tests

* Show a message when there are no sessions running

* Rename import to fork and make that clear in notebook name

* Fix old route

* Show info when no file is connected to the given session

* Show runtime type next to filename

* Show button for joining session when a running path is selected

* Move modal components to SessionLive namespace

* Add FileGuard to lock files used for notebook persistence

* Use radio for specifying persistence type

* Don't lock nil path

* Simplify FileGuard implementation

* Test notebook persistence

* Fix typo

* Further simplify FileGuard

* Improve file listing

* Don't show parent dir when there's a basename being typed

* Add path component tests
2021-02-21 16:54:44 +01:00

39 lines
1.2 KiB
Elixir

defmodule LiveBookWeb.SessionsComponent do
use LiveBookWeb, :live_component
alias LiveBook.SessionSupervisor
@impl true
def render(assigns) do
~L"""
<div class="mt-3 flex flex-col space-y-2">
<%= for summary <- @session_summaries do %>
<div class="shadow rounded-md p-2">
<div class="p-3 flex items-center">
<div class="flex-grow flex flex-col space-y-1 text-gray-700 text-lg hover:text-gray-900">
<%= live_redirect summary.notebook_name, to: Routes.session_path(@socket, :page, summary.session_id) %>
<div class="text-gray-500 text-sm">
<%= summary.path || "No file" %>
</div>
</div>
<button class="text-gray-500 hover:text-current"
phx-click="delete_session"
phx-value-id="<%= summary.session_id %>"
phx-target="<%= @myself %>"
aria-label="delete">
<%= Icons.svg(:trash, class: "h-6") %>
</button>
</div>
</div>
<% end %>
</div>
"""
end
@impl true
def handle_event("delete_session", %{"id" => session_id}, socket) do
SessionSupervisor.delete_session(session_id)
{:noreply, socket}
end
end