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" }} +
+ +
+ {{ template "user/fragments/picLink" (list .Comment.Did.String "size-8") }} +
+ +
+ {{ template "fragments/comment/commentHeader" . }} + {{ template "fragments/comment/commentBody" . }} +
+
+{{ end }} diff --git a/appview/pages/templates/repo/pulls/pull.html b/appview/pages/templates/repo/pulls/pull.html --- a/appview/pages/templates/repo/pulls/pull.html +++ b/appview/pages/templates/repo/pulls/pull.html @@ -76,6 +76,38 @@ } })(); + {{ end }} {{ define "repoContentLayout" }} @@ -271,7 +303,7 @@ {{ $lastIdx := index . 2 }} {{ $root := index . 3 }} {{ $round := $item.RoundNumber }} -
+ " href="#round-{{ $round }}"> {{ template "repo/fragments/shortTime" $item.Created }}
{{ if or $root.IsInterdiff (ne $root.ActiveRound $round) }} + href="/{{ $root.RepoInfo.FullName }}/pulls/{{ $root.Pull.PullId }}/round/{{ $round }}?{{ safeUrl $root.DiffOpts.Encode }}#round-{{ $round }}"> {{ i "diff" "w-4 h-4" }} Diff @@ -544,14 +576,13 @@
-
+
{{ range $item.Comments }} - {{ template "comment" - (dict "LoggedInUser" $root.LoggedInUser - "Reactions" (index (asReactionMapMap $root.Reactions) .FeedCommentAtUri) - "UserReacted" (index (asReactionStatusMapMap $root.UserReacted) .FeedCommentAtUri) - "VouchRelationship" (index $root.VouchRelationships .Did) - "Comment" .) }} + {{ template "fragments/comment/pullComment" + (dict "LoggedInUser" $root.LoggedInUser + "Reactions" (index (asReactionMapMap $root.Reactions) .FeedCommentAtUri) + "UserReacted" (index (asReactionStatusMapMap $root.UserReacted) .FeedCommentAtUri) + "Comment" .) }} {{ end }}
{{ if gt $c 0}} @@ -584,20 +615,6 @@ "Loading" (eq $lastIdx $item.RoundNumber)) }}
-{{ end }} - -{{ define "comment" }} -
- -
- {{ template "user/fragments/picLink" (list .Comment.Did.String "size-8") }} -
- -
- {{ template "fragments/comment/commentHeader" . }} - {{ template "fragments/comment/commentBody" . }} -
-
{{ end }} {{ define "loginPrompt" }} diff --git a/appview/pages/templates/repo/pulls/fragments/pullNewComment.html b/appview/pages/templates/repo/pulls/fragments/pullNewComment.html --- a/appview/pages/templates/repo/pulls/fragments/pullNewComment.html +++ b/appview/pages/templates/repo/pulls/fragments/pullNewComment.html @@ -5,8 +5,10 @@ class="w-full flex flex-wrap gap-2 group" hx-post="/comment" hx-trigger="submit, keydown[(ctrlKey || metaKey) && key=='Enter'] from:find textarea" - hx-swap="none" + hx-target="#pull-comments-{{ .RoundNumber }}" + hx-swap="beforeend" hx-disabled-elt="find button[type='submit']" + hx-on::before-request="this.querySelector('.error').innerHTML = ''" hx-on::after-request="if(event.detail.successful) this.reset()" > @@ -19,7 +21,7 @@ placeholder="Add to the discussion..."> {{ template "replyActions" . }} -
+
{{ end }}