From a8bc4e59d28ceb636df4f5c4f6c759ccab6318ea Mon Sep 17 00:00:00 2001 From: Lewis Date: Mon, 29 Jun 2026 12:48:10 +0300 Subject: [PATCH] appview/pages: pull comment fixes Lewis: May this revision serve well! --- appview/pages/compose_parse_test.go | 3 + appview/pages/pages.go | 12 ++++ .../fragments/comment/pullComment.html | 13 ++++ .../fragments/line-quote-button.html | 4 +- .../repo/pulls/fragments/pullNewComment.html | 6 +- appview/pages/templates/repo/pulls/pull.html | 65 ++++++++++++------- appview/state/comment.go | 38 +++++++---- input.css | 7 +- 8 files changed, 109 insertions(+), 39 deletions(-) create mode 100644 appview/pages/templates/fragments/comment/pullComment.html diff --git a/appview/pages/compose_parse_test.go b/appview/pages/compose_parse_test.go index ad99eda0..938d4342 100644 --- a/appview/pages/compose_parse_test.go +++ b/appview/pages/compose_parse_test.go @@ -30,6 +30,9 @@ func TestPullComposeTemplatesParse(t *testing.T) { {"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 index 1cdbb05a..b0ce4608 100644 --- a/appview/pages/pages.go +++ b/appview/pages/pages.go @@ -1877,6 +1877,18 @@ func (p *Pages) CommentBodyFragment(w io.Writer, params CommentBodyFragmentParam 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/pages/templates/fragments/comment/pullComment.html b/appview/pages/templates/fragments/comment/pullComment.html new file mode 100644 index 00000000..90fbecb6 --- /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/fragments/line-quote-button.html b/appview/pages/templates/fragments/line-quote-button.html index 88f5ebf6..e3f13fd7 100644 --- 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/repo/pulls/fragments/pullNewComment.html b/appview/pages/templates/repo/pulls/fragments/pullNewComment.html index 496f99dc..fff9e896 100644 --- 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 }} diff --git a/appview/pages/templates/repo/pulls/pull.html b/appview/pages/templates/repo/pulls/pull.html index ea30d0a5..f6d5939f 100644 --- 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 }} -
+
{{ 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}} @@ -586,20 +617,6 @@ {{ 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/state/comment.go b/appview/state/comment.go index b09be951..78fa8dd8 100644 --- a/appview/state/comment.go +++ b/appview/state/comment.go @@ -94,6 +94,18 @@ func (s *State) NewComment(w http.ResponseWriter, r *http.Request) { 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") @@ -165,17 +177,6 @@ func (s *State) NewComment(w http.ResponseWriter, r *http.Request) { 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 replyToUriRaw := r.FormValue("reply-to-uri") replyToCidRaw := r.FormValue("reply-to-cid") @@ -295,6 +296,21 @@ func (s *State) NewComment(w http.ResponseWriter, r *http.Request) { 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. s.pages.HxRefresh(w) diff --git a/input.css b/input.css index 7877eb89..fe4cead8 100644 --- a/input.css +++ b/input.css @@ -550,7 +550,8 @@ } .line-quote-hl, -.line-range-hl { +.line-range-hl, +.comment-hl { @apply !bg-yellow-200/30 dark:!bg-yellow-700/30; } @@ -558,6 +559,10 @@ @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\] { @apply !bg-yellow-200/30 dark:!bg-yellow-700/30; } -- 2.51.2