defmodule CanneryWeb.HomeLive do @moduledoc """ Liveview for the home page """ use CanneryWeb, :live_view alias Cannery.Accounts alias CanneryWeb.Endpoint @impl true def mount(_params, _session, socket) do admins = Accounts.list_users_by_role(:admin) socket = socket |> assign(page_title: "Home", query: "", results: %{}, admins: admins) {:ok, socket} 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}")} _no_query -> {:noreply, socket |> put_flash(:error, "No dependencies found matching \"#{query}\"") |> assign(results: %{}, query: query)} end end @impl true def render(assigns) do ~H"""
<%= gettext( "%{name} lets you easily keep an eye on your ammo levels before and after range day", name: "Cannery" ) %>
<%= gettext("Self-host your own instance, or use an instance from someone you trust.") %> <%= gettext("Your data stays with you, period") %>
<%= gettext("Access from any internet-capable device") %>
<%= if @admins |> Enum.empty?() do %> <.link href={Routes.user_registration_path(CanneryWeb.Endpoint, :new)} class="hover:underline" > <%= dgettext("prompts", "Register to setup %{name}", name: "Cannery") %> <% else %>
<%= Application.get_env(:cannery, CanneryWeb.Endpoint)[:registration] |> case do "public" -> gettext("Public Signups") _ -> gettext("Invite Only") end %>
0.6.1
<%= gettext("View the source code") %>
<%= gettext("Help translate") %>
<%= gettext("Report bugs or request features") %>