ikurotime / gitgud

public
main / internal/interface/web/templates/explore.templ
2.4 KB · Templ Raw
 1package templates
 2
 3import "gitgud/internal/domain"
 4
 5templ Explore(user *domain.User, repos []*domain.Repository) {
 6	@Layout("Explore · gitgud", user) {
 7		<div class="mx-auto max-w-3xl">
 8			<div class="mb-6 flex items-center justify-between gap-4">
 9				<div>
10					<h1 class="text-base font-semibold text-ink">Public repositories</h1>
11					<p class="mt-1 text-[13px] text-muted">
12						{ itoa(len(repos)) } public { plural(len(repos), "repository", "repositories") } on this instance.
13					</p>
14				</div>
15				if user != nil {
16					<a class="btn btn-primary shrink-0" href="/new">+ New repository</a>
17				}
18			</div>
19			if len(repos) == 0 {
20				if user != nil {
21					@emptyState("No public repositories yet", "Create a public repository and it will show up here for everyone.", "/new", "Create repository")
22				} else {
23					@emptyState("No public repositories yet", "When someone creates a public repository, it will appear here.", "", "")
24				}
25			} else {
26				@repoList(repos)
27			}
28		</div>
29	}
30}
31
32templ repoList(repos []*domain.Repository) {
33	<div class="flex flex-col">
34		for _, repo := range repos {
35			<a class="group block border-t border-line py-3.5 last:border-b" href={ templ.SafeURL("/" + repo.OwnerName + "/" + repo.Name) }>
36				<div class="mb-1.5 flex items-center gap-2">
37					<span class="font-mono text-sm font-semibold text-accent group-hover:underline">{ repo.OwnerName }/{ repo.Name }</span>
38					if repo.IsPrivate {
39						<span class="rounded border border-[#4a3d24] px-1.5 py-0.5 font-mono text-[10px] text-warn">private</span>
40					} else {
41						<span class="rounded border border-line2 px-1.5 py-0.5 font-mono text-[10px] text-faint">public</span>
42					}
43				</div>
44				if repo.Description != "" {
45					<p class="mb-2.5 line-clamp-2 text-[13px] text-muted">{ repo.Description }</p>
46				}
47				<div class="flex items-center gap-1.5 font-mono text-xs text-faint">
48					<span class="size-2 rounded-full bg-accent"></span>
49					{ repo.DefaultBranch }
50				</div>
51			</a>
52		}
53	</div>
54}
55
56templ emptyState(title, body, href, cta string) {
57	<div class="card flex flex-col items-center px-6 py-14 text-center">
58		<div class="mb-4 flex size-10 items-center justify-center rounded-full border border-line2 text-faint">·</div>
59		<h3 class="font-semibold text-ink">{ title }</h3>
60		<p class="mt-1 max-w-sm text-sm text-muted">{ body }</p>
61		if href != "" {
62			<a class="btn btn-primary mt-5" href={ templ.SafeURL(href) }>{ cta }</a>
63		}
64	</div>
65}