ikurotime / gitgud

public
main / internal/interface/web/templates/compare.templ
2.3 KB · Templ Raw
 1package templates
 2
 3import "gitgud/internal/domain"
 4
 5templ Compare(user *domain.User, repo *domain.Repository, base, head string, branches []string, cmp *domain.Comparison, errMsg string) {
 6	@Layout("Compare · "+repo.Name, user) {
 7		@repoHeader(repo, "pulls")
 8		<h2 class="mb-4 text-lg font-semibold tracking-tight">Compare changes</h2>
 9		if errMsg != "" {
10			<div class="mb-4 rounded-md border border-closed/30 bg-closed/10 px-3 py-2 text-sm text-closed">{ errMsg }</div>
11		}
12		<form method="get" action={ templ.SafeURL(repoPath(repo, "/compare")) } class="mb-6 flex flex-wrap items-center gap-2 text-sm">
13			<span class="text-muted">base</span>
14			<select name="base" class="select w-auto py-1.5 font-mono text-xs">
15				@branchOptions(branches, base)
16			</select>
17			<span class="text-faint">←</span>
18			<span class="text-muted">compare</span>
19			<select name="head" class="select w-auto py-1.5 font-mono text-xs">
20				<option value="">select branch</option>
21				@branchOptions(branches, head)
22			</select>
23			<button class="btn" type="submit">Compare</button>
24		</form>
25		if cmp != nil {
26			<div class="mb-5 flex items-center gap-2 text-sm text-muted">
27				<span class="badge"><span class="text-open">{ itoa(len(cmp.Commits)) }</span> commits</span>
28				<span class="badge"><span class="text-accent">{ itoa(len(cmp.Files)) }</span> files changed</span>
29			</div>
30			if user != nil && cmp.Mergeable {
31				<div class="card mb-6 p-5">
32					<h3 class="mb-3 font-semibold text-ink">Open a pull request</h3>
33					<form method="post" action={ templ.SafeURL(repoPath(repo, "/pulls")) } class="flex flex-col gap-3">
34						@csrfField()
35						<input type="hidden" name="base" value={ base }/>
36						<input type="hidden" name="head" value={ head }/>
37						<input class="input" type="text" name="title" placeholder="Title" value={ head }/>
38						<textarea class="textarea" name="body" rows="4" placeholder="Description (markdown supported)"></textarea>
39						<div class="flex justify-end">
40							<button class="btn btn-primary" type="submit">Create pull request</button>
41						</div>
42					</form>
43				</div>
44			}
45			@commitsList(repo, cmp.Commits)
46			@diffFiles(cmp.Files)
47		}
48	}
49}
50
51templ branchOptions(branches []string, selected string) {
52	for _, b := range branches {
53		if b == selected {
54			<option value={ b } selected>{ b }</option>
55		} else {
56			<option value={ b }>{ b }</option>
57		}
58	}
59}