Monorepo for Tangled tangled.org

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
··· 198 198 199 199 func (rp *Issues) DeleteIssue(w http.ResponseWriter, r *http.Request) { 200 200 l := rp.logger.With("handler", "DeleteIssue") 201 + noticeId := "issue-actions-error" 202 + 201 203 user := rp.oauth.GetUser(r) 204 + 202 205 f, err := rp.repoResolver.Resolve(r) 203 206 if err != nil { 204 - log.Println("failed to get repo and knot", err) 207 + l.Error("failed to get repo and knot", "err", err) 205 208 return 206 209 } 207 210 208 211 issue, ok := r.Context().Value("issue").(*db.Issue) 209 212 if !ok { 210 213 l.Error("failed to get issue") 211 - rp.pages.Error404(w) 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.") 212 235 return 213 236 } 214 237 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: 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 223 243 } 244 + 245 + // return to all issues page 246 + rp.pages.HxRedirect(w, "/"+f.RepoInfo(user).FullName()+"/issues") 224 247 } 225 248 226 249 func (rp *Issues) CloseIssue(w http.ResponseWriter, r *http.Request) { ··· 338 361 replyToUri := r.FormValue("reply-to") 339 362 var replyTo *string 340 363 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 364 + replyTo = &replyToUri 354 365 } 355 366 356 367 comment := db.IssueComment{ ··· 697 708 return 698 709 } 699 710 _, err = client.RepoDeleteRecord(r.Context(), &comatproto.RepoDeleteRecord_Input{ 700 - Collection: tangled.GraphFollowNSID, 711 + Collection: tangled.RepoIssueCommentNSID, 701 712 Repo: user.Did, 702 713 Rkey: comment.Rkey, 703 714 })
+3 -4
appview/pages/templates/repo/issues/issue.html
··· 56 56 {{ template "issueActions" . }} 57 57 {{ end }} 58 58 </div> 59 + <div id="issue-actions-error" class="error"></div> 59 60 {{ end }} 60 61 61 62 {{ define "issueActions" }} ··· 76 77 {{ define "deleteIssue" }} 77 78 <a 78 79 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-delete="/{{ .RepoInfo.FullName }}/issues/{{ .Issue.IssueId }}/" 80 81 hx-confirm="Are you sure you want to delete your issue?" 81 - hx-swap="innerHTML" 82 - hx-target="#comment-body-{{.Issue.IssueId}}" 83 - > 82 + hx-swap="none"> 84 83 {{ i "trash-2" "size-3" }} 85 84 {{ i "loader-circle" "size-3 animate-spin hidden group-[.htmx-request]:inline" }} 86 85 </a>