63 lines
1.5 KiB
Elixir
63 lines
1.5 KiB
Elixir
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</.back>
|
|
<.live_component
|
|
id={:new}
|
|
module={PrymnWeb.CreateApp}
|
|
app_type={assigns[:app_type]}
|
|
servers={@servers}
|
|
/>
|
|
<% assigns.apps == [] -> %>
|
|
<.onboarding />
|
|
<% true -> %>
|
|
<div class="mx-auto max-w-2xl">
|
|
<.header>
|
|
Live Apps
|
|
<:subtitle>
|
|
All of your apps accross all projects.
|
|
</:subtitle>
|
|
</.header>
|
|
</div>
|
|
<% 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"""
|
|
<div class="mx-auto max-w-2xl text-center">
|
|
<h1 class="mb-5 text-3xl font-medium">You have no Apps.</h1>
|
|
<.button type="link" patch={~p"/apps/new"}>
|
|
<.icon class="mr-2 h-6 w-6" name="hero-plus" /> Create your first App!
|
|
</.button>
|
|
</div>
|
|
"""
|
|
end
|
|
end
|