+35
-24
appview/issues/issues.go
+35
-24
appview/issues/issues.go
···
198
199
func (rp *Issues) DeleteIssue(w http.ResponseWriter, r *http.Request) {
200
l := rp.logger.With("handler", "DeleteIssue")
201
user := rp.oauth.GetUser(r)
202
f, err := rp.repoResolver.Resolve(r)
203
if err != nil {
204
-
log.Println("failed to get repo and knot", err)
205
return
206
}
207
208
issue, ok := r.Context().Value("issue").(*db.Issue)
209
if !ok {
210
l.Error("failed to get issue")
211
-
rp.pages.Error404(w)
212
return
213
}
214
215
-
switch r.Method {
216
-
case http.MethodGet:
217
-
rp.pages.EditIssueFragment(w, pages.EditIssueParams{
218
-
LoggedInUser: user,
219
-
RepoInfo: f.RepoInfo(user),
220
-
Issue: issue,
221
-
})
222
-
case http.MethodPost:
223
}
224
}
225
226
func (rp *Issues) CloseIssue(w http.ResponseWriter, r *http.Request) {
···
338
replyToUri := r.FormValue("reply-to")
339
var replyTo *string
340
if replyToUri != "" {
341
-
uri, err := syntax.ParseATURI(replyToUri)
342
-
if err != nil {
343
-
l.Error("failed to get parse replyTo", "err", err, "replyTo", replyToUri)
344
-
rp.pages.Notice(w, "issue-comment", "Failed to create comment.")
345
-
return
346
-
}
347
-
if uri.Collection() != tangled.RepoIssueCommentNSID {
348
-
l.Error("invalid replyTo collection", "collection", uri.Collection())
349
-
rp.pages.Notice(w, "issue-comment", "Failed to create comment.")
350
-
return
351
-
}
352
-
u := uri.String()
353
-
replyTo = &u
354
}
355
356
comment := db.IssueComment{
···
697
return
698
}
699
_, err = client.RepoDeleteRecord(r.Context(), &comatproto.RepoDeleteRecord_Input{
700
-
Collection: tangled.GraphFollowNSID,
701
Repo: user.Did,
702
Rkey: comment.Rkey,
703
})
···
198
199
func (rp *Issues) DeleteIssue(w http.ResponseWriter, r *http.Request) {
200
l := rp.logger.With("handler", "DeleteIssue")
201
+
noticeId := "issue-actions-error"
202
+
203
user := rp.oauth.GetUser(r)
204
+
205
f, err := rp.repoResolver.Resolve(r)
206
if err != nil {
207
+
l.Error("failed to get repo and knot", "err", err)
208
return
209
}
210
211
issue, ok := r.Context().Value("issue").(*db.Issue)
212
if !ok {
213
l.Error("failed to get issue")
214
+
rp.pages.Notice(w, noticeId, "Failed to delete issue.")
215
+
return
216
+
}
217
+
l = l.With("did", issue.Did, "rkey", issue.Rkey)
218
+
219
+
// delete from PDS
220
+
client, err := rp.oauth.AuthorizedClient(r)
221
+
if err != nil {
222
+
log.Println("failed to get authorized client", err)
223
+
rp.pages.Notice(w, "issue-comment", "Failed to delete comment.")
224
+
return
225
+
}
226
+
_, err = client.RepoDeleteRecord(r.Context(), &comatproto.RepoDeleteRecord_Input{
227
+
Collection: tangled.RepoIssueNSID,
228
+
Repo: issue.Did,
229
+
Rkey: issue.Rkey,
230
+
})
231
+
if err != nil {
232
+
// TODO: transact this better
233
+
l.Error("failed to delete issue from PDS", "err", err)
234
+
rp.pages.Notice(w, noticeId, "Failed to delete issue.")
235
return
236
}
237
238
+
// delete from db
239
+
if err := db.DeleteIssues(rp.db, db.FilterEq("id", issue.Id)); err != nil {
240
+
l.Error("failed to delete issue", "err", err)
241
+
rp.pages.Notice(w, noticeId, "Failed to delete issue.")
242
+
return
243
}
244
+
245
+
// return to all issues page
246
+
rp.pages.HxRedirect(w, "/"+f.RepoInfo(user).FullName()+"/issues")
247
}
248
249
func (rp *Issues) CloseIssue(w http.ResponseWriter, r *http.Request) {
···
361
replyToUri := r.FormValue("reply-to")
362
var replyTo *string
363
if replyToUri != "" {
364
+
replyTo = &replyToUri
365
}
366
367
comment := db.IssueComment{
···
708
return
709
}
710
_, err = client.RepoDeleteRecord(r.Context(), &comatproto.RepoDeleteRecord_Input{
711
+
Collection: tangled.RepoIssueCommentNSID,
712
Repo: user.Did,
713
Rkey: comment.Rkey,
714
})
+3
-4
appview/pages/templates/repo/issues/issue.html
+3
-4
appview/pages/templates/repo/issues/issue.html
···
56
{{ template "issueActions" . }}
57
{{ end }}
58
</div>
59
{{ end }}
60
61
{{ define "issueActions" }}
···
76
{{ define "deleteIssue" }}
77
<a
78
class="text-gray-500 dark:text-gray-400 flex gap-1 items-center group"
79
-
hx-delete="/{{ .RepoInfo.FullName }}/issues/{{ .Issue.IssueId }}/delete"
80
hx-confirm="Are you sure you want to delete your issue?"
81
-
hx-swap="innerHTML"
82
-
hx-target="#comment-body-{{.Issue.IssueId}}"
83
-
>
84
{{ i "trash-2" "size-3" }}
85
{{ i "loader-circle" "size-3 animate-spin hidden group-[.htmx-request]:inline" }}
86
</a>
···
56
{{ template "issueActions" . }}
57
{{ end }}
58
</div>
59
+
<div id="issue-actions-error" class="error"></div>
60
{{ end }}
61
62
{{ define "issueActions" }}
···
77
{{ define "deleteIssue" }}
78
<a
79
class="text-gray-500 dark:text-gray-400 flex gap-1 items-center group"
80
+
hx-delete="/{{ .RepoInfo.FullName }}/issues/{{ .Issue.IssueId }}/"
81
hx-confirm="Are you sure you want to delete your issue?"
82
+
hx-swap="none">
83
{{ i "trash-2" "size-3" }}
84
{{ i "loader-circle" "size-3 animate-spin hidden group-[.htmx-request]:inline" }}
85
</a>