defmodule LivebookWeb.SessionLive.IndicatorsComponent do
use LivebookWeb, :html
def render(assigns) do
~H"""
<.view_indicator />
<.persistence_indicator
file={@file}
dirty={@dirty}
persistence_warnings={@persistence_warnings}
autosave_interval_s={@autosave_interval_s}
session_id={@session_id}
/>
<.runtime_indicator
runtime={@runtime}
global_status={@global_status}
session_id={@session_id}
/>
<.insert_mode_indicator />
"""
end
defp view_indicator(assigns) do
~H"""
<.menu id="views-menu" position={:top_right}>
<:toggle>
<.menu_item>
<.menu_item>
"""
end
defp persistence_indicator(%{file: nil} = assigns) do
~H"""
<.link
patch={~p"/sessions/#{@session_id}/settings/file"}
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"
>
<.remix_icon icon="save-line" class="text-xl text-gray-400" />
"""
end
defp persistence_indicator(%{dirty: false} = assigns) do
~H"""
"Notebook saved"
warnings ->
"Notebook saved with warnings:\n" <> Enum.map_join(warnings, "\n", &("- " <> &1))
end
}
>
<.link
patch={~p"/sessions/#{@session_id}/settings/file"}
class="icon-button icon-outlined-button border-green-bright-300 hover:bg-green-bright-50 focus:bg-green-bright-50 relative"
aria-label="notebook saved, click to open file settings"
>
<.remix_icon icon="save-line" class="text-xl text-green-bright-400" />
<.remix_icon
:if={@persistence_warnings != []}
icon="error-warning-fill"
class="text-lg text-red-400 absolute -top-1.5 -right-2"
/>
"""
end
defp persistence_indicator(%{autosave_interval_s: nil} = assigns) do
~H"""
<.link
patch={~p"/sessions/#{@session_id}/settings/file"}
class="icon-button icon-outlined-button border-yellow-bright-200 hover:bg-red-50 focus:bg-red-50"
aria-label="no autosave configured, click to open file settings"
>
<.remix_icon icon="save-line" class="text-xl text-yellow-bright-300" />
"""
end
defp persistence_indicator(assigns) do
~H"""
<.link
patch={~p"/sessions/#{@session_id}/settings/file"}
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"
>
<.remix_icon icon="save-line" class="text-xl text-blue-500" />
"""
end
defp runtime_indicator(assigns) do
~H"""
<%= if Livebook.Runtime.connected?(@runtime) do %>
<.global_status status={elem(@global_status, 0)} cell_id={elem(@global_status, 1)} />
<% else %>
<.link
patch={~p"/sessions/#{@session_id}/settings/runtime"}
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"
>
<.remix_icon icon="loader-3-line" class="text-xl text-gray-400" />
<% end %>
"""
end
defp global_status(%{status: :evaluating} = assigns) do
~H"""
"""
end
defp global_status(%{status: :evaluated} = assigns) do
~H"""
"""
end
defp global_status(%{status: :errored} = assigns) do
~H"""
"""
end
defp global_status(%{status: :stale} = assigns) do
~H"""
"""
end
defp global_status(%{status: :fresh} = assigns) do
~H"""
<.remix_icon icon="loader-3-line" class="text-xl text-gray-400" />
"""
end
defp insert_mode_indicator(assigns) do
~H"""
<% # Note: this indicator is shown/hidden using CSS based on the current mode %>
ins
"""
end
end