diff --git a/input.css b/input.css --- a/input.css +++ b/input.css @@ -550,12 +550,17 @@ } .line-quote-hl, -.line-range-hl { +.line-range-hl, +.comment-hl { @apply !bg-yellow-200/30 dark:!bg-yellow-700/30; } .chunk-match-hl { @apply rounded-sm !bg-yellow-300/70 dark:!bg-yellow-600/60; +} + +.comment-hl { + @apply rounded-md; } :is(.line-quote-hl, .line-range-hl) > .min-w-\[3\.5rem\] { diff --git a/appview/pages/compose_parse_test.go b/appview/pages/compose_parse_test.go --- a/appview/pages/compose_parse_test.go +++ b/appview/pages/compose_parse_test.go @@ -30,6 +30,9 @@ {"pullCompareForks", []string{"repo/pulls/fragments/pullCompareForks"}}, {"pullCompareBranches", []string{"repo/pulls/fragments/pullCompareBranches"}}, {"pullCompareForksBranches", []string{"repo/pulls/fragments/pullCompareForksBranches"}}, + {"pull.html via repo base", []string{"layouts/base", "layouts/repobase", "repo/pulls/pull"}}, + {"pullNewComment", []string{"repo/pulls/fragments/pullNewComment"}}, + {"pullComment", []string{"fragments/comment/pullComment"}}, } for _, c := range cases { diff --git a/appview/pages/pages.go b/appview/pages/pages.go --- a/appview/pages/pages.go +++ b/appview/pages/pages.go @@ -1877,6 +1877,18 @@ return p.executePlain("fragments/comment/commentBody", w, params) } +type PullCommentFragmentParams struct { + LoggedInUser *oauth.MultiAccountUser + Comment models.Comment + Reactions map[models.ReactionKind]models.ReactionDisplayData + UserReacted map[models.ReactionKind]bool + HxSwapOob bool +} + +func (p *Pages) PullCommentFragment(w io.Writer, params PullCommentFragmentParams) error { + return p.executePlain("fragments/comment/pullComment", w, params) +} + type CommentHeaderFragmentParams struct { Comment models.Comment Reactions map[models.ReactionKind]models.ReactionDisplayData diff --git a/appview/state/comment.go b/appview/state/comment.go --- a/appview/state/comment.go +++ b/appview/state/comment.go @@ -94,6 +94,18 @@ noticeId := "comment-error" ctx := r.Context() + var pullRoundIdx *int + if pullRoundIdxRaw := r.FormValue("pull-round-idx"); pullRoundIdxRaw != "" { + roundIdx, err := strconv.Atoi(pullRoundIdxRaw) + if err != nil { + l.Warn("invalid round idx", "err", err) + s.pages.Notice(w, noticeId, "pull round index should be valid integer") + return + } + pullRoundIdx = &roundIdx + noticeId = fmt.Sprintf("comment-error-%d", roundIdx) + } + body := r.FormValue("body") if body == "" { s.pages.Notice(w, noticeId, "Body is required") @@ -163,17 +175,6 @@ subject := comatproto.RepoStrongRef{ Uri: subjectUri.String(), Cid: subjectCid.String(), - } - - var pullRoundIdx *int - if pullRoundIdxRaw := r.FormValue("pull-round-idx"); pullRoundIdxRaw != "" { - roundIdx, err := strconv.Atoi(pullRoundIdxRaw) - if err != nil { - l.Warn("invalid round idx", "err", err) - s.pages.Notice(w, noticeId, "pull round index should be valid integer") - return - } - pullRoundIdx = &roundIdx } var replyTo *comatproto.RepoStrongRef @@ -294,6 +295,21 @@ } s.notifier.NewComment(ctx, &comment, mentions) + + if pullRoundIdx != nil { + var buf bytes.Buffer + if err := s.pages.PullCommentFragment(&buf, pages.PullCommentFragmentParams{ + LoggedInUser: user, + Comment: comment, + }); err != nil { + l.Error("failed to render pull comment fragment", "err", err) + s.pages.HxRefresh(w) + return + } + w.Header().Set("Content-Type", "text/html") + w.Write(buf.Bytes()) + return + } // TODO: return comment or reply-comment fragment // onattach, htmx-callback to focus on comment. diff --git a/appview/pages/templates/fragments/line-quote-button.html b/appview/pages/templates/fragments/line-quote-button.html --- a/appview/pages/templates/fragments/line-quote-button.html +++ b/appview/pages/templates/fragments/line-quote-button.html @@ -66,8 +66,10 @@ const highlightFromHash = () => { clearHl('line-range-hl'); - const hash = decodeURIComponent(window.location.hash.slice(1)); + let hash; + try { hash = decodeURIComponent(window.location.hash.slice(1)); } catch (e) { return; } if (!hash) return; + if (hash.startsWith('comment-') || hash.startsWith('round-')) return; const parts = hash.split('~'); const startEl = document.getElementById(parts[0]); diff --git a/appview/pages/templates/fragments/comment/pullComment.html b/appview/pages/templates/fragments/comment/pullComment.html new file mode 100644 --- /dev/null +++ b/appview/pages/templates/fragments/comment/pullComment.html @@ -0,0 +1,13 @@ +{{ define "fragments/comment/pullComment" }} +