import { 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 (
);
}
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".
0}>
{props.title} 0}>
{/* A count is worth having when a repository has hundreds of remote
branches and the list below is mostly off screen. */}
{count()}
0}
fallback={
{props.isOpen ? "None" : "—"}
}
>
{(entry) => (
current branch:
{(segment) => (
{/* is exactly what this is: text made relevant by
something the reader is doing right now. */}
{segment.text}
)}
)}
);
}
/** 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";
}
}