3.6 KiB · text History 5901e75
defmodule VigilWeb.HomeLive do
  @moduledoc """
  The front page, for everyone. Signed out, it says how to get in (an
  invite, or NEIAM); signed in, it's the starting point.
  """
  use VigilWeb, :live_view

  alias Vigil.Accounts

  @impl true
  def mount(_params, _session, socket) do
    {:ok, assign(socket, :page_title, "Home")}
  end

  @impl true
  def render(assigns) do
    ~H"""
    <Layouts.app flash={@flash} current_scope={@current_scope} active={:home}>
      <%= if @current_scope && @current_scope.user do %>
        <section id="home-signed-in" class="space-y-6">
          <div class="space-y-1">
            <p class="text-xs font-semibold uppercase tracking-[0.2em] text-primary">Vigil</p>
            <h1 class="text-2xl font-extrabold tracking-tight sm:text-3xl">
              Welcome back, {Accounts.display_name(@current_scope.user)}.
            </h1>
          </div>

          <div class="grid gap-4 sm:grid-cols-2">
            <.home_card
              id="home-invites"
              navigate={~p"/users/invites"}
              icon="hero-envelope"
              title="Invites"
            >
              Bring someone in: make a one-time sign-up link and hand it over.
            </.home_card>
            <.home_card
              id="home-settings"
              navigate={~p"/users/settings"}
              icon="hero-cog-6-tooth"
              title="Settings"
            >
              Your email, password and linked NEIAM account.
            </.home_card>
          </div>
        </section>
      <% else %>
        <section id="landing" class="mx-auto max-w-2xl space-y-6 py-12 text-center">
          <span class="mx-auto grid size-14 place-items-center rounded-2xl bg-primary text-primary-content shadow-lg">
            <.icon name="hero-eye-solid" class="size-7" />
          </span>
          <div class="space-y-2">
            <h1 class="text-3xl font-extrabold tracking-tight sm:text-4xl">Vigil</h1>
            <p class="text-base-content/70">
              <%= if Accounts.registration_open?() do %>
                Make an account, or log in to the one you have.
              <% else %>
                Sign-up is by invite: open the link you were sent, or log in.
              <% end %>
            </p>
          </div>
          <div class="flex flex-wrap justify-center gap-2">
            <.link navigate={~p"/users/log-in"} class="btn btn-primary" id="landing-log-in">
              Log in
            </.link>
            <.link
              :if={Accounts.registration_open?() and NeiamAuth.local_login_enabled?()}
              navigate={~p"/users/register"}
              class="btn btn-ghost"
              id="landing-register"
            >
              Register
            </.link>
          </div>
        </section>
      <% end %>
    </Layouts.app>
    """
  end

  attr :id, :string, required: true
  attr :navigate, :string, required: true
  attr :icon, :string, required: true
  attr :title, :string, required: true
  slot :inner_block, required: true

  defp home_card(assigns) do
    ~H"""
    <.link
      id={@id}
      navigate={@navigate}
      class="group flex items-start gap-4 rounded-box border border-base-300 bg-base-100 p-5 transition hover:-translate-y-0.5 hover:border-primary/50 hover:shadow-md"
    >
      <span class="grid size-10 shrink-0 place-items-center rounded-lg bg-primary/10 text-primary transition-transform group-hover:-rotate-6">
        <.icon name={@icon} class="size-5" />
      </span>
      <div class="space-y-1">
        <p class="font-semibold">{@title}</p>
        <p class="text-sm text-base-content/70">{render_slot(@inner_block)}</p>
      </div>
    </.link>
    """
  end
end