defmodule CanneryWeb.HomeLive do @moduledoc """ Liveview for the home page """ use CanneryWeb, :live_view alias Cannery.Accounts @impl true def mount(_params, session, socket) do admins = Accounts.list_users_by_role(:admin) {:ok, socket |> assign_defaults(session) |> assign(query: "", results: %{}, admins: admins)} end @impl true def handle_event("suggest", %{"q" => query}, socket) do {:noreply, socket |> assign(results: search(query), query: query)} end @impl true def handle_event("search", %{"q" => query}, socket) do case search(query) do %{^query => vsn} -> {:noreply, redirect(socket, external: "https://hexdocs.pm/#{query}/#{vsn}")} _ -> {:noreply, socket |> put_flash(:error, "No dependencies found matching \"#{query}\"") |> assign(results: %{}, query: query)} end end @impl true def render(assigns) do ~H"""
Cannery lets you easily keep an eye on your ammo levels before and after range day
Self-host your own instance, or use an instance from someone you trust. Your data stays with you, period
Access from any internet-capable device
<%= if @admins |> Enum.empty?() do %> <%= link("Sign up to setup Cannery!", class: "hover:underline", to: Routes.user_registration_path(CanneryWeb.Endpoint, :new) ) %> <% else %>
<%= Application.get_env(:cannery, CanneryWeb.Endpoint)[:registration] |> case do "public" -> "Public Signups" _ -> "Invite Only" end %>