defmodule LivebookWeb.AppsLive do use LivebookWeb, :live_view @impl true def mount(_params, _session, socket) do if connected?(socket) do Livebook.Apps.subscribe() end apps = Livebook.Apps.list_apps() empty_apps_path? = Livebook.Apps.empty_apps_path?() {:ok, assign(socket, apps: apps, empty_apps_path?: empty_apps_path?)} end @impl true def render(assigns) do ~H"""
<.link navigate={~p"/"}> logo livebook
<.link navigate={~p"/apps-dashboard"} class="flex items-center text-blue-600"> Dashboard <.remix_icon icon="arrow-right-line" class="align-middle ml-1" />

Apps

<.link :for={app <- apps_listing(@apps)} navigate={~p"/apps/#{app.slug}"} class="px-4 py-3 border border-gray-200 rounded-xl text-gray-800 pointer hover:bg-gray-50 flex items-center justify-between" > <%= app.notebook_name %> <.remix_icon :if={not app.public?} icon="lock-password-line" />
<.no_entries :if={@apps == []}> No apps running.
No app notebooks found. Follow these steps to list your apps here:
  1. Open a notebook
  2. Click <.remix_icon icon="rocket-line" class="align-baseline text-lg" /> in the sidebar and configure the app as public
  3. Save the notebook to the <%= Livebook.Config.apps_path() %> folder
  4. Relaunch your Livebook app
""" end @impl true def handle_info({type, _app} = event, socket) when type in [:app_created, :app_updated, :app_closed] do {:noreply, update(socket, :apps, &LivebookWeb.AppComponents.update_app_list(&1, event))} end def handle_info(_message, socket), do: {:noreply, socket} defp apps_listing(apps) do Enum.sort_by(apps, & &1.notebook_name) end end