ikurotime / gitgud

public
main / internal/interface/web/templates/issue_detail.templ
2.3 KB · Templ Raw
 1package templates
 2
 3import "gitgud/internal/domain"
 4
 5templ IssueDetail(user *domain.User, repo *domain.Repository, issue *domain.Issue, comments []*domain.IssueComment, canModify bool) {
 6	@Layout(issue.Title+" · "+repo.Name, user) {
 7		@repoHeader(repo, "issues")
 8		<div class="mb-1 flex items-start gap-3">
 9			<h2 class="text-2xl font-semibold tracking-tight text-ink">{ issue.Title } <span class="font-normal text-faint">#{ itoa(issue.Number) }</span></h2>
10		</div>
11		<div class="mb-6 flex items-center gap-3">
12			if issue.State == domain.IssueOpen {
13				<span class="badge-open"><span class="size-2 rounded-full border-2 border-grassink"></span> Open</span>
14			} else {
15				<span class="badge-closed"><span class="size-2 rounded-full border-2 border-current"></span> Closed</span>
16			}
17			<span class="meta">{ issue.AuthorName } opened this on { fmtTime(issue.CreatedAt) }</span>
18		</div>
19		@commentCard(issue.AuthorName, fmtTime(issue.CreatedAt), issue.Body)
20		for _, c := range comments {
21			@commentCard(c.AuthorName, fmtTime(c.CreatedAt), c.Body)
22		}
23		if canModify {
24			<form method="post" action={ templ.SafeURL(repoPath(repo, "/issues/"+itoa(issue.Number)+stateAction(issue.State))) } class="mb-6">
25				@csrfField()
26				if issue.State == domain.IssueOpen {
27					<button class="btn btn-danger" type="submit">Close issue</button>
28				} else {
29					<button class="btn" type="submit">Reopen issue</button>
30				}
31			</form>
32		}
33		if user != nil {
34			<form method="post" action={ templ.SafeURL(repoPath(repo, "/issues/"+itoa(issue.Number)+"/comments")) } class="flex flex-col gap-3">
35				@csrfField()
36				<textarea class="textarea" name="body" rows="4" placeholder="Leave a comment… (markdown supported)"></textarea>
37				<div class="flex justify-end">
38					<button class="btn btn-primary" type="submit">Comment</button>
39				</div>
40			</form>
41		} else {
42			<p class="text-sm text-muted"><a class="text-accent hover:underline" href="/login">Sign in</a> to comment.</p>
43		}
44	}
45}
46
47templ commentCard(author, when, body string) {
48	<div class="card mb-4 overflow-hidden">
49		<div class="flex items-center gap-2 border-b border-line bg-[#0e1410] px-4 py-2.5">
50			@avatar(author, "size-5")
51			<span class="text-sm font-medium text-ink">{ author }</span>
52			<span class="meta">commented on { when }</span>
53		</div>
54		<div class="prose-dark px-4 py-3">
55			@templ.Raw(markdown(body))
56		</div>
57	</div>
58}