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" }}
+
+{{ 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 }}
-
+
{{ if gt $c 0}}
@@ -586,20 +617,6 @@
{{ end }}
-{{ define "comment" }}
-
-{{ 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;
}