defmodule GitGudWeb.SymsLive.Index do
@moduledoc """
A user's syms index: every configured symbol with how many repos they
have marked with it.
"""
use GitGudWeb, :live_view
alias GitGud.Accounts
alias GitGud.Syms
@impl true
def mount(%{"handle" => handle}, _session, socket) do
case Accounts.get_user_by_handle(handle) do
nil ->
{:ok, socket |> put_flash(:error, "User not found.") |> push_navigate(to: ~p"/")}
user ->
{:ok,
socket
|> assign(:user, user)
|> assign(:symbols, Syms.symbols())
|> assign(:counts, Syms.counts_for_user(user))
|> assign(:page_title, "@#{user.handle}: syms")}
end
end
@impl true
def render(assigns) do
~H"""
<Layouts.app flash={@flash} current_scope={@current_scope}>
<div class="space-y-4 max-w-2xl">
<h1 class="text-xl font-semibold">
<.link navigate={~p"/u/#{@user.handle}"} class="link link-hover">
@{@user.handle}
</.link>
<span class="opacity-50">/</span>
syms
</h1>
<p :if={@symbols == []} class="text-sm opacity-60">
This instance has no symbols configured, so syms are disabled.
</p>
<ul class="divide-y divide-base-300">
<li :for={sym <- @symbols} class="py-3 flex items-center justify-between gap-3">
<.link navigate={~p"/u/#{@user.handle}/syms/#{sym}"} class="flex items-center gap-3">
<span class="text-2xl leading-none">{sym}</span>
<span class="text-sm link link-hover">
{count_of(@counts, sym)} {if count_of(@counts, sym) == 1,
do: "repository",
else: "repositories"}
</span>
</.link>
</li>
</ul>
</div>
</Layouts.app>
"""
end
defp count_of(counts, sym), do: Map.get(counts, sym, 0)
end
neiam /gitgud
Git Gud
public · Issues · Pulls · Labels · Forks · Compare · Actions success · Packages
⭐
Log in to mark this repository.
1.9 KiB · text
History
6280797