Something went wrong. Try again.
[READ-ONLY] Mirror of https://github.com/SantaClaas/gigit. git client
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149import { For, Show } from "solid-js";
import type { RefEntry } from "../lib/bindings";import { highlight, type Refs } from "../lib/refs";import RefFilter from "./RefFilter";
/** * The repository's references. * * Entries are text rather than buttons: nothing happens when you click a * branch yet, and a control that looks interactive but is not is worse than * plain text. They become controls when checking out exists. */export default function RepositoryNav(props: { refs: Refs; /** The checked-out branch, so it can be marked among the others. */ head?: string; /** Whether a repository is open at all. */ isOpen: boolean;}) { return ( <nav aria-label="Repository" class="flex flex-col overflow-auto border-r border-outline-variant bg-surface-container-low p-3" > <Show when={props.isOpen}> <RefFilter refs={props.refs} /> </Show>
<Show when={!props.refs.isFiltering() || props.refs.counts().matched > 0}> <ul class="flex flex-col gap-5"> <Section title="Branches" entries={props.refs.grouped().branches} head={props.head} refs={props.refs} isOpen={props.isOpen} /> <Section title="Remotes" entries={props.refs.grouped().remotes} refs={props.refs} isOpen={props.isOpen} /> <Section title="Tags" entries={props.refs.grouped().tags} refs={props.refs} isOpen={props.isOpen} /> </ul> </Show>
{/* One message beats three sections each saying "None" for the same reason. */} <Show when={props.refs.isFiltering() && props.refs.counts().matched === 0}> <p class="px-2 text-body-sm text-on-surface-variant"> Nothing matches “{props.refs.query()}”. </p> </Show> </nav> );}
function Section(props: { title: string; entries: RefEntry[]; head?: string; refs: Refs; isOpen: boolean;}) { const headingId = () => `refs-${props.title.toLowerCase()}`;
/** How many there are, and — while filtering — of how many. */ const count = () => { if (!props.refs.isFiltering()) return `${props.entries.length}`;
const all = props.refs.entries().filter((entry) => kindOf(props.title) === entry.kind);
return `${props.entries.length} of ${all.length}`; };
return ( // While filtering, a section with nothing left in it is dropped entirely. // "None" would read as "this repository has no tags" when what is true is // "no tags match what you typed". <Show when={!props.refs.isFiltering() || props.entries.length > 0}> <li> <h2 id={headingId()} class="flex items-baseline gap-2 px-2 py-1"> <span class="text-label-lg text-on-surface-variant">{props.title}</span> <Show when={props.entries.length > 0}> {/* A count is worth having when a repository has hundreds of remote branches and the list below is mostly off screen. */} <span class="text-label-sm text-on-surface-variant tabular-nums">{count()}</span> </Show> </h2>
<Show when={props.entries.length > 0} fallback={ <p class="px-2 text-body-sm text-on-surface-variant">{props.isOpen ? "None" : "—"}</p> } > <ul aria-labelledby={headingId()} class="flex flex-col"> <For each={props.entries}> {(entry) => ( <li class={[ "truncate px-2 py-0.5 text-body-md", entry.shorthand === props.head ? "font-medium text-primary" : "text-on-surface", ]} title={entry.name} > <Show when={entry.shorthand === props.head}> <span class="sr-only">current branch: </span> </Show> <For each={highlight(entry.shorthand, props.refs.query())}> {(segment) => ( <Show when={segment.matched} fallback={segment.text}> {/* <mark> is exactly what this is: text made relevant by something the reader is doing right now. */} <mark class="bg-tertiary-container text-on-tertiary-container"> {segment.text} </mark> </Show> )} </For> </li> )} </For> </ul> </Show> </li> </Show> );}
/** Which ref kind a section heading stands for. */function kindOf(title: string): RefEntry["kind"] { switch (title) { case "Remotes": return "remoteBranch"; case "Tags": return "tag"; default: return "localBranch"; }}