defmodule PrymnWeb.AppIndexLive do
use PrymnWeb, :live_view
@impl true
def mount(_, _, socket) do
apps = Prymn.Apps.list_apps()
servers = Prymn.Servers.list_servers()
{:ok,
socket
|> assign(:servers, servers)
|> assign(:apps, apps)}
end
@impl true
def render(assigns) do
~H"""
<%= cond do %>
<% assigns.live_action == :new -> %>
<.back navigate={~p"/apps"}>Go back
<.live_component
id={:new}
module={PrymnWeb.CreateApp}
app_type={assigns[:app_type]}
servers={@servers}
/>
<% assigns.apps == [] -> %>
<.onboarding />
<% true -> %>
<.header>
Live Apps
<:subtitle>
All of your apps accross all projects.
<% end %>
"""
end
@impl true
def handle_params(%{"app_type" => app_type}, _, socket) do
{:noreply, assign(socket, app_type: app_type)}
end
def handle_params(_, _, socket) do
{:noreply,
socket
|> assign(:page_title, (socket.assigns.live_action == :new && "New App") || "Apps")}
end
defp onboarding(assigns) do
~H"""
You have no Apps.
<.button type="link" patch={~p"/apps/new"}>
<.icon class="mr-2 h-6 w-6" name="hero-plus" /> Create your first App!
"""
end
end