forked from tangled.org/core
this repo has no description

appview/pages: rig up issue delete button

Signed-off-by: oppiliappan <me@oppi.li>

oppi.li 792c658c d7caef6a

verified
Changed files
+38 -28
appview
issues
pages
templates
repo
issues
+35 -24
appview/issues/issues.go
···
func (rp *Issues) DeleteIssue(w http.ResponseWriter, r *http.Request) {
l := rp.logger.With("handler", "DeleteIssue")
user := rp.oauth.GetUser(r)
f, err := rp.repoResolver.Resolve(r)
if err != nil {
-
log.Println("failed to get repo and knot", err)
return
}
issue, ok := r.Context().Value("issue").(*db.Issue)
if !ok {
l.Error("failed to get issue")
-
rp.pages.Error404(w)
return
}
-
switch r.Method {
-
case http.MethodGet:
-
rp.pages.EditIssueFragment(w, pages.EditIssueParams{
-
LoggedInUser: user,
-
RepoInfo: f.RepoInfo(user),
-
Issue: issue,
-
})
-
case http.MethodPost:
}
}
func (rp *Issues) CloseIssue(w http.ResponseWriter, r *http.Request) {
···
replyToUri := r.FormValue("reply-to")
var replyTo *string
if replyToUri != "" {
-
uri, err := syntax.ParseATURI(replyToUri)
-
if err != nil {
-
l.Error("failed to get parse replyTo", "err", err, "replyTo", replyToUri)
-
rp.pages.Notice(w, "issue-comment", "Failed to create comment.")
-
return
-
}
-
if uri.Collection() != tangled.RepoIssueCommentNSID {
-
l.Error("invalid replyTo collection", "collection", uri.Collection())
-
rp.pages.Notice(w, "issue-comment", "Failed to create comment.")
-
return
-
}
-
u := uri.String()
-
replyTo = &u
}
comment := db.IssueComment{
···
return
}
_, err = client.RepoDeleteRecord(r.Context(), &comatproto.RepoDeleteRecord_Input{
-
Collection: tangled.GraphFollowNSID,
Repo: user.Did,
Rkey: comment.Rkey,
})
···
func (rp *Issues) DeleteIssue(w http.ResponseWriter, r *http.Request) {
l := rp.logger.With("handler", "DeleteIssue")
+
noticeId := "issue-actions-error"
+
user := rp.oauth.GetUser(r)
+
f, err := rp.repoResolver.Resolve(r)
if err != nil {
+
l.Error("failed to get repo and knot", "err", err)
return
}
issue, ok := r.Context().Value("issue").(*db.Issue)
if !ok {
l.Error("failed to get issue")
+
rp.pages.Notice(w, noticeId, "Failed to delete issue.")
+
return
+
}
+
l = l.With("did", issue.Did, "rkey", issue.Rkey)
+
+
// delete from PDS
+
client, err := rp.oauth.AuthorizedClient(r)
+
if err != nil {
+
log.Println("failed to get authorized client", err)
+
rp.pages.Notice(w, "issue-comment", "Failed to delete comment.")
+
return
+
}
+
_, err = client.RepoDeleteRecord(r.Context(), &comatproto.RepoDeleteRecord_Input{
+
Collection: tangled.RepoIssueNSID,
+
Repo: issue.Did,
+
Rkey: issue.Rkey,
+
})
+
if err != nil {
+
// TODO: transact this better
+
l.Error("failed to delete issue from PDS", "err", err)
+
rp.pages.Notice(w, noticeId, "Failed to delete issue.")
return
}
+
// delete from db
+
if err := db.DeleteIssues(rp.db, db.FilterEq("id", issue.Id)); err != nil {
+
l.Error("failed to delete issue", "err", err)
+
rp.pages.Notice(w, noticeId, "Failed to delete issue.")
+
return
}
+
+
// return to all issues page
+
rp.pages.HxRedirect(w, "/"+f.RepoInfo(user).FullName()+"/issues")
}
func (rp *Issues) CloseIssue(w http.ResponseWriter, r *http.Request) {
···
replyToUri := r.FormValue("reply-to")
var replyTo *string
if replyToUri != "" {
+
replyTo = &replyToUri
}
comment := db.IssueComment{
···
return
}
_, err = client.RepoDeleteRecord(r.Context(), &comatproto.RepoDeleteRecord_Input{
+
Collection: tangled.RepoIssueCommentNSID,
Repo: user.Did,
Rkey: comment.Rkey,
})
+3 -4
appview/pages/templates/repo/issues/issue.html
···
{{ template "issueActions" . }}
{{ end }}
</div>
{{ end }}
{{ define "issueActions" }}
···
{{ define "deleteIssue" }}
<a
class="text-gray-500 dark:text-gray-400 flex gap-1 items-center group"
-
hx-delete="/{{ .RepoInfo.FullName }}/issues/{{ .Issue.IssueId }}/delete"
hx-confirm="Are you sure you want to delete your issue?"
-
hx-swap="innerHTML"
-
hx-target="#comment-body-{{.Issue.IssueId}}"
-
>
{{ i "trash-2" "size-3" }}
{{ i "loader-circle" "size-3 animate-spin hidden group-[.htmx-request]:inline" }}
</a>
···
{{ template "issueActions" . }}
{{ end }}
</div>
+
<div id="issue-actions-error" class="error"></div>
{{ end }}
{{ define "issueActions" }}
···
{{ define "deleteIssue" }}
<a
class="text-gray-500 dark:text-gray-400 flex gap-1 items-center group"
+
hx-delete="/{{ .RepoInfo.FullName }}/issues/{{ .Issue.IssueId }}/"
hx-confirm="Are you sure you want to delete your issue?"
+
hx-swap="none">
{{ i "trash-2" "size-3" }}
{{ i "loader-circle" "size-3 animate-spin hidden group-[.htmx-request]:inline" }}
</a>