2.2 KiB · text History 6280797
defmodule GitGudWeb.PrNav do
@moduledoc """
Tabs across a pull request's three pages: the conversation, the diff,
and the history.
The diff moved off the conversation page onto `/files` — reviewing
code and reading the discussion want different amounts of screen, and
a long diff buried the comment box underneath it.
"""
use GitGudWeb, :html
attr :handle, :string, required: true
attr :repo, :map, required: true
attr :pr, :map, required: true
attr :active, :atom, required: true, values: [:conversation, :files, :reviews, :history]
attr :files_count, :integer, default: nil
attr :comments_count, :integer, default: nil
attr :reviews_count, :integer, default: nil
attr :events_count, :integer, default: nil
def nav(assigns) do
~H"""
<nav class="flex gap-1 border-b border-base-300 text-sm">
<.tab
navigate={~p"/r/#{@handle}/#{@repo.name}/pulls/#{@pr.number}"}
active?={@active == :conversation}
label="Conversation"
count={@comments_count}
/>
<.tab
navigate={~p"/r/#{@handle}/#{@repo.name}/pulls/#{@pr.number}/files"}
active?={@active == :files}
label="Files changed"
count={@files_count}
/>
<.tab
navigate={~p"/r/#{@handle}/#{@repo.name}/pulls/#{@pr.number}/reviews"}
active?={@active == :reviews}
label="Reviews"
count={@reviews_count}
/>
<.tab
navigate={~p"/r/#{@handle}/#{@repo.name}/pulls/#{@pr.number}/history"}
active?={@active == :history}
label="History"
count={@events_count}
/>
</nav>
"""
end
attr :navigate, :string, required: true
attr :active?, :boolean, required: true
attr :label, :string, required: true
attr :count, :integer, default: nil
defp tab(assigns) do
~H"""
<.link
navigate={@navigate}
aria-current={@active? && "page"}
class={[
"px-3 py-2 -mb-px border-b-2 transition-colors",
if(@active?,
do: "border-primary font-medium",
else: "border-transparent opacity-70 hover:opacity-100"
)
]}
>
{@label}<span :if={is_integer(@count) and @count > 0} class="badge badge-xs badge-ghost ml-1">
{@count}
</span>
</.link>
"""
end
end