dotfiles/app/lib/prymn_web/live/app_index_live.ex
2023-11-23 15:45:33 +02:00

64 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="text-3xl font-medium">You have no Apps.</h1>
<h2 class="text-xl">Create your first App here!</h2>
<Button.primary class="mt-10" size="lg" patch={~p"/apps/new"}>
Create a new App
</Button.primary>
</div>
"""
end
end