forked from
tangled.org/core
Monorepo for Tangled — https://tangled.org
1{{ define "title" }}{{ .Issue.Title }} · issue #{{ .Issue.IssueId }} · {{ .RepoInfo.FullName }}{{ end }}
2
3{{ define "repoContent" }}
4 <header class="pb-4">
5 <h1 class="text-2xl">
6 {{ .Issue.Title }}
7 <span class="text-gray-500 dark:text-gray-400">#{{ .Issue.IssueId }}</span>
8 </h1>
9 </header>
10
11 {{ $bgColor := "bg-gray-800 dark:bg-gray-700" }}
12 {{ $icon := "ban" }}
13 {{ if eq .State "open" }}
14 {{ $bgColor = "bg-green-600 dark:bg-green-700" }}
15 {{ $icon = "circle-dot" }}
16 {{ end }}
17
18 <section class="mt-2">
19 <div class="inline-flex items-center gap-2">
20 <div id="state"
21 class="inline-flex items-center rounded px-3 py-1 {{ $bgColor }}">
22 {{ i $icon "w-4 h-4 mr-1.5 text-white" }}
23 <span class="text-white">{{ .State }}</span>
24 </div>
25 <span class="text-gray-500 dark:text-gray-400 text-sm">
26 opened by
27 {{ $owner := didOrHandle .Issue.OwnerDid .IssueOwnerHandle }}
28 <a href="/{{ $owner }}" class="no-underline hover:underline"
29 >{{ $owner }}</a
30 >
31 <span class="px-1 select-none before:content-['\00B7']"></span>
32 <time title="{{ .Issue.Created | longTimeFmt }}">
33 {{ .Issue.Created | timeFmt }}
34 </time>
35 </span>
36 </div>
37
38 {{ if .Issue.Body }}
39 <article id="body" class="mt-8 prose dark:prose-invert">
40 {{ .Issue.Body | markdown }}
41 </article>
42 {{ end }}
43 </section>
44{{ end }}
45
46{{ define "repoAfter" }}
47 <section id="comments" class="my-2 mt-2 space-y-2 relative">
48 {{ range $index, $comment := .Comments }}
49 <div
50 id="comment-{{ .CommentId }}"
51 class="bg-white dark:bg-gray-800 rounded drop-shadow-sm py-2 px-4 relative w-full md:max-w-3/5 md:w-fit">
52 {{ if gt $index 0 }}
53 <div class="absolute left-8 -top-2 w-px h-2 bg-gray-300 dark:bg-gray-600"></div>
54 {{ end }}
55 {{ template "repo/issues/fragments/issueComment" (dict "RepoInfo" $.RepoInfo "LoggedInUser" $.LoggedInUser "DidHandleMap" $.DidHandleMap "Issue" $.Issue "Comment" .)}}
56 </div>
57 {{ end }}
58 </section>
59
60 {{ block "newComment" . }} {{ end }}
61
62{{ end }}
63
64{{ define "newComment" }}
65 {{ if .LoggedInUser }}
66 <form
67 id="comment-form"
68 hx-post="/{{ .RepoInfo.FullName }}/issues/{{ .Issue.IssueId }}/comment"
69 hx-on::after-request="if(event.detail.successful) this.reset()"
70 >
71 <div class="bg-white dark:bg-gray-800 rounded drop-shadow-sm py-4 px-4 relative w-full md:w-3/5">
72 <div class="text-sm pb-2 text-gray-500 dark:text-gray-400">
73 {{ didOrHandle .LoggedInUser.Did .LoggedInUser.Handle }}
74 </div>
75 <textarea
76 id="comment-textarea"
77 name="body"
78 class="w-full p-2 rounded border border-gray-200 dark:border-gray-700"
79 placeholder="Add to the discussion. Markdown is supported."
80 onkeyup="updateCommentForm()"
81 ></textarea>
82 <div id="issue-comment"></div>
83 <div id="issue-action" class="error"></div>
84 </div>
85
86 <div class="flex gap-2 mt-2">
87 <button
88 id="comment-button"
89 hx-post="/{{ .RepoInfo.FullName }}/issues/{{ .Issue.IssueId }}/comment"
90 type="submit"
91 hx-disabled-elt="#comment-button"
92 class="btn p-2 flex items-center gap-2 no-underline hover:no-underline"
93 disabled
94 >
95 {{ i "message-square-plus" "w-4 h-4" }}
96 comment
97 </button>
98
99 {{ $isIssueAuthor := and .LoggedInUser (eq .LoggedInUser.Did .Issue.OwnerDid) }}
100 {{ $isRepoCollaborator := .RepoInfo.Roles.IsCollaborator }}
101 {{ if and (or $isIssueAuthor $isRepoCollaborator) (eq .State "open") }}
102 <button
103 id="close-button"
104 type="button"
105 class="btn flex items-center gap-2"
106 hx-trigger="click"
107 >
108 {{ i "ban" "w-4 h-4" }}
109 close
110 </button>
111 <div
112 id="close-with-comment"
113 hx-post="/{{ .RepoInfo.FullName }}/issues/{{ .Issue.IssueId }}/comment"
114 hx-trigger="click from:#close-button"
115 hx-disabled-elt="#close-with-comment"
116 hx-target="#issue-comment"
117 hx-vals="js:{body: document.getElementById('comment-textarea').value.trim() !== '' ? document.getElementById('comment-textarea').value : ''}"
118 hx-swap="none"
119 >
120 </div>
121 <div
122 id="close-issue"
123 hx-disabled-elt="#close-issue"
124 hx-post="/{{ .RepoInfo.FullName }}/issues/{{ .Issue.IssueId }}/close"
125 hx-trigger="click from:#close-button"
126 hx-target="#issue-action"
127 hx-swap="none"
128 >
129 </div>
130 <script>
131 document.addEventListener('htmx:configRequest', function(evt) {
132 if (evt.target.id === 'close-with-comment') {
133 const commentText = document.getElementById('comment-textarea').value.trim();
134 if (commentText === '') {
135 evt.detail.parameters = {};
136 evt.preventDefault();
137 }
138 }
139 });
140 </script>
141 {{ else if and (or $isIssueAuthor $isRepoCollaborator) (eq .State "closed") }}
142 <button
143 type="button"
144 class="btn flex items-center gap-2"
145 hx-post="/{{ .RepoInfo.FullName }}/issues/{{ .Issue.IssueId }}/reopen"
146 hx-swap="none"
147 >
148 {{ i "refresh-ccw-dot" "w-4 h-4" }}
149 reopen
150 </button>
151 {{ end }}
152
153 <script>
154 function updateCommentForm() {
155 const textarea = document.getElementById('comment-textarea');
156 const commentButton = document.getElementById('comment-button');
157 const closeButton = document.getElementById('close-button');
158
159 if (textarea.value.trim() !== '') {
160 commentButton.removeAttribute('disabled');
161 } else {
162 commentButton.setAttribute('disabled', '');
163 }
164
165 if (closeButton) {
166 if (textarea.value.trim() !== '') {
167 closeButton.innerHTML = '{{ i "ban" "w-4 h-4" }} close with comment';
168 } else {
169 closeButton.innerHTML = '{{ i "ban" "w-4 h-4" }} close';
170 }
171 }
172 }
173
174 document.addEventListener('DOMContentLoaded', function() {
175 updateCommentForm();
176 });
177 </script>
178 </div>
179 </form>
180 {{ else }}
181 <div class="bg-white dark:bg-gray-800 rounded drop-shadow-sm py-4 px-4 relative w-fit">
182 <a href="/login" class="underline">login</a> to join the discussion
183 </div>
184 {{ end }}
185{{ end }}