defmodule LivebookWeb.SessionLive.AppInfoComponent do
use LivebookWeb, :live_component
import LivebookWeb.AppHelpers
@impl true
def render(assigns) do
~H"""
App
<.app_info_icon />
<%= if @session.mode == :app do %>
This session is a running app. To deploy a modified version, you can fork it.
<.remix_icon icon="git-branch-line" />
Fork
<% else %>
<.remix_icon icon="rocket-line" class="align-middle mr-1" />
Deploy
<.link
patch={~p"/sessions/#{@session.id}/settings/app"}
class="button-base button-outlined-gray bg-transparent"
>
Configure
<%= if @app do %>
Latest deployment
<.labeled_text label="URL" one_line>
<%= ~p"/apps/#{@app.slug}" %>
<.labeled_text label="Version" one_line>
v<%= @app.version %>
<.labeled_text label="Session type" one_line>
<%= if(@app.multi_session, do: "Multi", else: "Single") %>
<.remix_icon icon="delete-bin-6-line" class="text-lg" />
Running sessions
<% end %>
<% end %>
"""
end
defp app_info_icon(assigns) do
~H"""
<.remix_icon icon="question-line" class="text-xl leading-none" />
"""
end
@impl true
def handle_event("terminate_app", %{}, socket) do
{:noreply, confirm_app_termination(socket, socket.assigns.app.pid)}
end
def handle_event("terminate_app_session", %{"session_id" => session_id}, socket) do
app_session = Enum.find(socket.assigns.app.sessions, &(&1.id == session_id))
Livebook.Session.close(app_session.pid)
{:noreply, socket}
end
def handle_event("deactivate_app_session", %{"session_id" => session_id}, socket) do
app_session = Enum.find(socket.assigns.app.sessions, &(&1.id == session_id))
Livebook.Session.app_deactivate(app_session.pid)
{:noreply, socket}
end
end