import Link from "next/link"; import type { ReactNode } from "react"; import { Field } from "@unlocalhosted/metalui"; import { BookmarkIcon, HeartIcon, PlusIcon, RepoIcon, SearchIcon } from "./icons"; import { FieldIcon, FieldInput } from "./metal"; import { ButtonLink, Counter, Segmented, segmentClass } from "./ui"; export type ProfileTab = "repositories" | "lists" | "likes"; export const profileTab = (value: unknown): ProfileTab => (value === "lists" || value === "likes" ? value : "repositories"); const TABS: Record = { repositories: { label: "Repositories", icon: , find: "Find a repository…" }, lists: { label: "Lists", icon: , find: "Find a list…" }, likes: { label: "Liked", icon: , find: "Find a repository…" }, }; /** * A profile's main column: its tabs (repositories, lists and, for people, the repositories they * like) with their counts, the search box, and a New key for what the tab shows. */ export function ProfileTabs({ username, tab, counts, q, newHref, children, }: { username: string; tab: ProfileTab; /** Tabs without a count aren't shown. */ counts: Partial>; q: string; newHref?: string | false | null; children: ReactNode; }) { const tabs = (Object.keys(TABS) as ProfileTab[]).filter((t) => counts[t] !== undefined); return (
{tabs.map((t) => ( {TABS[t].icon} {TABS[t].label} {counts[t]} ))}
{tab !== "repositories" && }
{newHref && ( }> New )}
{children}
); } /** Whether a repository or list matches the profile's search. */ export const matches = (q: string, item: { name: string; description: string }) => !q || item.name.toLowerCase().includes(q) || item.description.toLowerCase().includes(q);