2021-04-01 18:56:19 +08:00
|
|
|
defmodule LivebookWeb.SessionLive.IndicatorsComponent do
|
|
|
|
use LivebookWeb, :live_component
|
|
|
|
|
|
|
|
@impl true
|
|
|
|
def render(assigns) do
|
2021-07-07 20:32:49 +08:00
|
|
|
~H"""
|
2021-10-25 01:38:57 +08:00
|
|
|
<div class="flex flex-col items-center space-y-2" data-element="notebook-indicators">
|
2021-08-14 03:17:43 +08:00
|
|
|
<%= if @file do %>
|
2021-07-07 20:32:49 +08:00
|
|
|
<%= if @dirty do %>
|
2021-08-14 03:17:43 +08:00
|
|
|
<%= if @autosave_interval_s do %>
|
2021-11-02 01:20:56 +08:00
|
|
|
<span class="tooltip left" data-tooltip="Autosave pending">
|
2021-08-14 03:17:43 +08:00
|
|
|
<%= live_patch to: Routes.session_path(@socket, :file_settings, @session_id),
|
2021-11-02 01:20:56 +08:00
|
|
|
class: "icon-button icon-outlined-button border-blue-400 hover:bg-blue-50 focus:bg-blue-50",
|
|
|
|
aria_label: "autosave pending, click to open file settings" do %>
|
2021-08-14 03:17:43 +08:00
|
|
|
<.remix_icon icon="save-line" class="text-xl text-blue-500" />
|
|
|
|
<% end %>
|
|
|
|
</span>
|
|
|
|
<% else %>
|
2021-11-02 01:20:56 +08:00
|
|
|
<span class="tooltip left" data-tooltip="No autosave configured, make sure to save manually">
|
2021-08-14 03:17:43 +08:00
|
|
|
<%= live_patch to: Routes.session_path(@socket, :file_settings, @session_id),
|
2022-01-17 21:19:20 +08:00
|
|
|
class: "icon-button icon-outlined-button border-yellow-bright-200 hover:bg-red-50 focus:bg-red-50",
|
2021-11-02 01:20:56 +08:00
|
|
|
aria_label: "no autosave configured, click to open file settings" do %>
|
2022-01-17 21:19:20 +08:00
|
|
|
<.remix_icon icon="save-line" class="text-xl text-yellow-bright-300" />
|
2021-08-14 03:17:43 +08:00
|
|
|
<% end %>
|
|
|
|
</span>
|
|
|
|
<% end %>
|
2021-04-01 18:56:19 +08:00
|
|
|
<% else %>
|
2021-11-02 01:20:56 +08:00
|
|
|
<span class="tooltip left" data-tooltip="Notebook saved">
|
2021-04-22 05:02:09 +08:00
|
|
|
<%= live_patch to: Routes.session_path(@socket, :file_settings, @session_id),
|
2022-01-17 21:19:20 +08:00
|
|
|
class: "icon-button icon-outlined-button border-green-bright-300 hover:bg-green-bright-50 focus:bg-green-bright-50",
|
2021-11-02 01:20:56 +08:00
|
|
|
aria_label: "notebook saved, click to open file settings" do %>
|
2022-01-17 21:19:20 +08:00
|
|
|
<.remix_icon icon="save-line" class="text-xl text-green-bright-400" />
|
2021-04-22 05:02:09 +08:00
|
|
|
<% end %>
|
2021-04-01 18:56:19 +08:00
|
|
|
</span>
|
|
|
|
<% end %>
|
|
|
|
<% else %>
|
2021-11-02 01:20:56 +08:00
|
|
|
<span class="tooltip left" data-tooltip="Choose a file to save the notebook">
|
2021-04-22 05:02:09 +08:00
|
|
|
<%= live_patch to: Routes.session_path(@socket, :file_settings, @session_id),
|
2021-11-02 01:20:56 +08:00
|
|
|
class: "icon-button icon-outlined-button border-gray-200 hover:bg-gray-100 focus:bg-gray-100",
|
|
|
|
aria_label: "choose a file to save the notebook" do %>
|
2021-07-07 20:32:49 +08:00
|
|
|
<.remix_icon icon="save-line" class="text-xl text-gray-400" />
|
2021-04-01 18:56:19 +08:00
|
|
|
<% end %>
|
|
|
|
</span>
|
|
|
|
<% end %>
|
|
|
|
|
2022-04-02 02:13:37 +08:00
|
|
|
<%= if Livebook.Runtime.connected?(@runtime) do %>
|
2021-11-01 20:15:21 +08:00
|
|
|
<.global_status
|
|
|
|
status={elem(@global_status, 0)}
|
|
|
|
cell_id={elem(@global_status, 1)} />
|
2021-04-01 18:56:19 +08:00
|
|
|
<% else %>
|
2021-11-02 01:20:56 +08:00
|
|
|
<span class="tooltip left" data-tooltip="Choose a runtime to run the notebook in">
|
2021-04-22 05:02:09 +08:00
|
|
|
<%= live_patch to: Routes.session_path(@socket, :runtime_settings, @session_id),
|
2021-11-02 01:20:56 +08:00
|
|
|
class: "icon-button icon-outlined-button border-gray-200 hover:bg-gray-100 focus:bg-gray-100",
|
|
|
|
aria_label: "choose a runtime to run the notebook in" do %>
|
2021-07-07 20:32:49 +08:00
|
|
|
<.remix_icon icon="loader-3-line" class="text-xl text-gray-400" />
|
2021-04-01 18:56:19 +08:00
|
|
|
<% end %>
|
|
|
|
</span>
|
|
|
|
<% end %>
|
|
|
|
|
|
|
|
<%# Note: this indicator is shown/hidden using CSS based on the current mode %>
|
2021-11-02 01:20:56 +08:00
|
|
|
<span class="tooltip left" data-tooltip="Insert mode" data-element="insert-mode-indicator">
|
2021-10-25 01:38:57 +08:00
|
|
|
<span class="text-sm font-medium text-gray-400 cursor-default">
|
2021-04-01 18:56:19 +08:00
|
|
|
ins
|
|
|
|
</span>
|
|
|
|
</span>
|
|
|
|
</div>
|
|
|
|
"""
|
|
|
|
end
|
|
|
|
|
2021-11-01 20:15:21 +08:00
|
|
|
defp global_status(%{status: :evaluating} = assigns) do
|
2021-07-07 20:32:49 +08:00
|
|
|
~H"""
|
2021-11-02 01:20:56 +08:00
|
|
|
<span class="tooltip left" data-tooltip="Go to evaluating cell">
|
2021-10-25 01:38:57 +08:00
|
|
|
<button class="border-blue-400 icon-button icon-outlined-button hover:bg-blue-50 focus:bg-blue-50"
|
2021-11-02 01:20:56 +08:00
|
|
|
aria-label="go to evaluating cell"
|
2021-04-01 18:56:19 +08:00
|
|
|
data-element="focus-cell-button"
|
2021-07-07 20:32:49 +08:00
|
|
|
data-target={@cell_id}>
|
|
|
|
<.remix_icon icon="loader-3-line" class="text-xl text-blue-500 animate-spin" />
|
2021-04-01 18:56:19 +08:00
|
|
|
</button>
|
|
|
|
</span>
|
|
|
|
"""
|
|
|
|
end
|
|
|
|
|
2021-11-01 20:15:21 +08:00
|
|
|
defp global_status(%{status: :evaluated} = assigns) do
|
2021-07-07 20:32:49 +08:00
|
|
|
~H"""
|
2021-11-02 01:20:56 +08:00
|
|
|
<span class="tooltip left" data-tooltip="Go to last evaluated cell">
|
2022-01-17 21:19:20 +08:00
|
|
|
<button class="border-green-bright-300 icon-button icon-outlined-button hover:bg-green-bright-50 focus:bg-green-bright-50"
|
2021-11-02 01:20:56 +08:00
|
|
|
aria-label="go to last evaluated cell"
|
2021-04-01 18:56:19 +08:00
|
|
|
data-element="focus-cell-button"
|
2021-07-07 20:32:49 +08:00
|
|
|
data-target={@cell_id}>
|
2022-01-17 21:19:20 +08:00
|
|
|
<.remix_icon icon="loader-3-line" class="text-xl text-green-bright-400" />
|
2021-04-01 18:56:19 +08:00
|
|
|
</button>
|
|
|
|
</span>
|
|
|
|
"""
|
|
|
|
end
|
|
|
|
|
2021-11-01 20:15:21 +08:00
|
|
|
defp global_status(%{status: :stale} = assigns) do
|
2021-07-07 20:32:49 +08:00
|
|
|
~H"""
|
2021-11-02 01:20:56 +08:00
|
|
|
<span class="tooltip left" data-tooltip="Go to first stale cell">
|
2022-01-17 21:19:20 +08:00
|
|
|
<button class="border-yellow-bright-200 icon-button icon-outlined-button hover:bg-yellow-bright-50 focus:bg-yellow-bright-50"
|
2021-11-02 01:20:56 +08:00
|
|
|
aria-label="go to first stale cell"
|
2021-04-01 18:56:19 +08:00
|
|
|
data-element="focus-cell-button"
|
2021-07-07 20:32:49 +08:00
|
|
|
data-target={@cell_id}>
|
2022-01-17 21:19:20 +08:00
|
|
|
<.remix_icon icon="loader-3-line" class="text-xl text-yellow-bright-300" />
|
2021-04-01 18:56:19 +08:00
|
|
|
</button>
|
|
|
|
</span>
|
|
|
|
"""
|
|
|
|
end
|
|
|
|
|
2021-11-01 20:15:21 +08:00
|
|
|
defp global_status(%{status: :fresh} = assigns) do
|
2021-07-07 20:32:49 +08:00
|
|
|
~H"""
|
2021-11-02 01:20:56 +08:00
|
|
|
<span class="tooltip left" data-tooltip="Ready to evaluate">
|
|
|
|
<div class="border-gray-200 icon-button icon-outlined-button hover:bg-gray-100 focus:bg-gray-100"
|
|
|
|
aria-label="ready to evaluate">
|
2021-07-07 20:32:49 +08:00
|
|
|
<.remix_icon icon="loader-3-line" class="text-xl text-gray-400" />
|
2021-11-02 01:20:56 +08:00
|
|
|
</div>
|
2021-04-01 18:56:19 +08:00
|
|
|
</span>
|
|
|
|
"""
|
|
|
|
end
|
|
|
|
end
|