ikurotime / gitgud

public
main / internal/interface/web/templates/repo_header.templ
1.8 KB · Templ Raw
 1package templates
 2
 3import "gitgud/internal/domain"
 4
 5templ repoHeader(repo *domain.Repository, active string) {
 6	<div class="mb-6">
 7		<div class="mb-4 flex items-center gap-3">
 8			<span class="text-accent">@gitLogo("size-5")</span>
 9			<h1 class="flex items-center gap-1.5 font-mono text-[15px]">
10				<a class="text-accent hover:underline" href={ templ.SafeURL("/" + repo.OwnerName) }>{ repo.OwnerName }</a>
11				<span class="text-faint">/</span>
12				<a class="font-semibold text-ink hover:text-accent" href={ templ.SafeURL(repoPath(repo, "")) }>{ repo.Name }</a>
13			</h1>
14			if repo.IsPrivate {
15				<span class="badge"><span class="size-1.5 rounded-full bg-warn"></span> private</span>
16			} else {
17				<span class="badge">public</span>
18			}
19		</div>
20		<nav class="flex gap-1 border-b border-line">
21			@repoTab(repoPath(repo, ""), "Code", active == "code")
22			@repoTab(repoPath(repo, "/issues"), "Issues", active == "issues")
23			@repoTab(repoPath(repo, "/pulls"), "Pull requests", active == "pulls")
24		</nav>
25	</div>
26}
27
28templ repoTab(href, label string, current bool) {
29	if current {
30		<a class="tab tab-active px-3" href={ templ.SafeURL(href) }>{ label }</a>
31	} else {
32		<a class="tab px-3" href={ templ.SafeURL(href) }>{ label }</a>
33	}
34}
35
36templ branchSwitcher(repo *domain.Repository, ref string, branches []string) {
37	<div class="relative inline-flex">
38		<select class="select w-auto cursor-pointer appearance-none py-1.5 pr-9 pl-3 font-mono text-xs" onchange="location.href=this.value">
39			for _, b := range branches {
40				if b == ref {
41					<option value={ repoPath(repo, "/tree/" + b) } selected>{ b }</option>
42				} else {
43					<option value={ repoPath(repo, "/tree/" + b) }>{ b }</option>
44				}
45			}
46		</select>
47		<span class="pointer-events-none absolute right-3 top-1/2 -translate-y-1/2 text-faint">▾</span>
48	</div>
49}