From 23aa5efc2f3461341d144e1cd6fb14487765a9d8 Mon Sep 17 00:00:00 2001 From: Seongmin Lee Date: Sat, 9 May 2026 05:21:51 +0900 Subject: [PATCH] appview: use markdownEditor fragment for all markdown body inputs Signed-off-by: Seongmin Lee --- .../templates/fragments/comment/edit.html | 11 ++- .../templates/fragments/comment/reply.html | 12 +-- .../fragments/line-quote-button.html | 2 +- .../templates/fragments/markdownEditor.html | 69 +++++++++++++ .../repo/issues/fragments/newComment.html | 19 ++-- .../repo/pulls/fragments/pullNewComment.html | 13 ++- .../repo/pulls/fragments/pullStepDetails.html | 98 +++---------------- .../repo/pulls/fragments/pullStepReview.html | 6 +- appview/pages/templates/strings/string.html | 12 +-- appview/pulls/compose.go | 5 - appview/pulls/router.go | 1 - appview/state/comment.go | 2 +- appview/state/markup.go | 8 ++ appview/state/router.go | 3 + 14 files changed, 128 insertions(+), 133 deletions(-) create mode 100644 appview/pages/templates/fragments/markdownEditor.html create mode 100644 appview/state/markup.go diff --git a/appview/pages/templates/fragments/comment/edit.html b/appview/pages/templates/fragments/comment/edit.html index 3c060801..6689e3fa 100644 --- a/appview/pages/templates/fragments/comment/edit.html +++ b/appview/pages/templates/fragments/comment/edit.html @@ -8,11 +8,10 @@ hx-disabled-elt="find button[type='submit']" > - + {{ template "fragments/markdownEditor" + (dict "Name" "body" + "Value" .Comment.EditableBody + "Placeholder" "Describe this pull request. Markdown is supported.") }}
{{ template "editActions" $ }} @@ -42,6 +41,8 @@ hx-get="/comment?aturi={{ .Comment.AtUri }}" hx-target="closest form" hx-swap="outerHTML" + hx-indicator="this" + hx-disabled-elt="this" > {{ i "x" "size-4" }} Cancel diff --git a/appview/pages/templates/fragments/comment/reply.html b/appview/pages/templates/fragments/comment/reply.html index 46835e89..d33701b6 100644 --- a/appview/pages/templates/fragments/comment/reply.html +++ b/appview/pages/templates/fragments/comment/reply.html @@ -8,12 +8,12 @@ hx-disabled-elt="find button[type='submit']" > {{ template "user/fragments/picHandleLink" .LoggedInUser.Did }} - + {{ template "fragments/markdownEditor" + (dict "Name" "body" + "BlobName" "blob" + "Rows" 3 + "AutoFocus" true + "Placeholder" "Leave a reply...") }} {{ template "replyActions" . }} {{ end }} diff --git a/appview/pages/templates/fragments/line-quote-button.html b/appview/pages/templates/fragments/line-quote-button.html index e3f13fd7..e280067b 100644 --- a/appview/pages/templates/fragments/line-quote-button.html +++ b/appview/pages/templates/fragments/line-quote-button.html @@ -18,7 +18,7 @@ const btnEnd = document.getElementById('line-quote-btn-end'); const textarea = () => - document.getElementById('comment-textarea'); + document.querySelector('form[hx-post="/comment"] textarea'); const lineOf = (el) => el?.closest?.('span[id*="-O"]') diff --git a/appview/pages/templates/fragments/markdownEditor.html b/appview/pages/templates/fragments/markdownEditor.html new file mode 100644 index 00000000..635277f2 --- /dev/null +++ b/appview/pages/templates/fragments/markdownEditor.html @@ -0,0 +1,69 @@ +{{ define "fragments/markdownEditor" }} + {{ $name := .Name }} + {{ $value := .Value }} + {{ $blobName := .BlobName }} + {{ $blobValues := .BlobValues }} + {{ $rows := (or .Rows 5) }} + {{ $required := .Required }} + {{ $autofocus := .AutoFocus }} + {{ $placeholder := .Placeholder }} +
+
+ + +
+
+ +
+ +
+ +{{ end }} diff --git a/appview/pages/templates/repo/issues/fragments/newComment.html b/appview/pages/templates/repo/issues/fragments/newComment.html index cc6a680b..8e31c64e 100644 --- a/appview/pages/templates/repo/issues/fragments/newComment.html +++ b/appview/pages/templates/repo/issues/fragments/newComment.html @@ -3,26 +3,21 @@
-
+
{{ template "user/fragments/picHandleLink" .LoggedInUser.Did }}
- + {{ template "fragments/markdownEditor" + (dict "Name" "body" + "BlobName" "blob" + "Placeholder" "Add to the discussion. Markdown is supported.") }}
@@ -85,7 +80,7 @@ } function updateCommentForm() { - const textarea = document.getElementById('comment-textarea'); + const textarea = document.querySelector('form[hx-post="/comment"] textarea'); const commentButton = document.getElementById('comment-button'); const closeButtonText = document.getElementById('close-button-text'); diff --git a/appview/pages/templates/repo/pulls/fragments/pullNewComment.html b/appview/pages/templates/repo/pulls/fragments/pullNewComment.html index 034aec8a..3847ec0b 100644 --- a/appview/pages/templates/repo/pulls/fragments/pullNewComment.html +++ b/appview/pages/templates/repo/pulls/fragments/pullNewComment.html @@ -12,13 +12,12 @@ > - + {{ template "fragments/markdownEditor" + (dict "Name" "body" + "BlobName" "blob" + "Rows" 8 + "Required" true + "Placeholder" "Add to the discussion...") }} {{ template "replyActions" . }}
diff --git a/appview/pages/templates/repo/pulls/fragments/pullStepDetails.html b/appview/pages/templates/repo/pulls/fragments/pullStepDetails.html index 955dfc54..40471cf1 100644 --- a/appview/pages/templates/repo/pulls/fragments/pullStepDetails.html +++ b/appview/pages/templates/repo/pulls/fragments/pullStepDetails.html @@ -1,11 +1,10 @@ {{ define "repo/pulls/fragments/pullStepDetails" }} {{ $hasSidePanel := and .LabelDefs .RepoInfo.Roles.IsPushAllowed }} - {{ $previewUrl := printf "/%s/pulls/new/preview" .RepoInfo.FullName }} {{ $labelCtx := dict "Defs" .LabelDefs "State" .LabelState "RepoInfo" .RepoInfo "Subject" "" "LoggedInUser" .LoggedInUser }}
- {{ template "pullStepDetailsSingle" (dict "Root" . "PreviewUrl" $previewUrl) }} + {{ template "pullStepDetailsSingle" . }} {{ template "pullSubmitRow" . }}
@@ -17,84 +16,39 @@ {{ end }}
- {{ template "markdownEditorScript" }} + {{ end }} {{ define "pullStepDetailsSingle" }} - {{ $root := .Root }} - {{ $previewUrl := .PreviewUrl }} - - + +
- {{ template "markdownEditor" (dict - "Id" "pull-body" - "Name" "body" - "Value" $root.Body - "Rows" 6 + {{ template "fragments/markdownEditor" (dict + "Name" "body" + "Value" .Body + "Rows" 6 "Placeholder" "Describe your change. Markdown is supported." - "PreviewUrl" $previewUrl - "DirtyFlag" "bodyDirty" ) }} {{ end }} -{{ define "markdownEditor" }} - {{ $id := .Id }} - {{ $name := .Name }} - {{ $value := .Value }} - {{ $rows := .Rows }} - {{ $placeholder := .Placeholder }} - {{ $previewUrl := .PreviewUrl }} - {{ $dirtyFlag := .DirtyFlag }} -
-
- - -
-
- -
- -
-{{ end }} - {{ define "pullSubmitRow" }}
{{ if and .MergeCheck .MergeCheck.IsConflicted }} @@ -125,25 +79,3 @@
{{ end }} - -{{ define "markdownEditorScript" }} - -{{ end }} diff --git a/appview/pages/templates/repo/pulls/fragments/pullStepReview.html b/appview/pages/templates/repo/pulls/fragments/pullStepReview.html index 1a286851..c10bd5a3 100644 --- a/appview/pages/templates/repo/pulls/fragments/pullStepReview.html +++ b/appview/pages/templates/repo/pulls/fragments/pullStepReview.html @@ -98,7 +98,6 @@ {{ define "pullReviewStackedCommits" }} {{ $root := . }} {{ $commits := .Comparison.FormatPatch }} - {{ $previewUrl := printf "/%s/pulls/new/preview" .RepoInfo.FullName }} {{ $hasSidePanel := and $root.LabelDefs $root.RepoInfo.Roles.IsPushAllowed }}
    {{ range $idx, $p := $commits }} @@ -148,14 +147,11 @@ placeholder="{{ $p.Title }}" />
- {{ template "markdownEditor" (dict - "Id" (printf "stack-body-%s" $cid) + {{ template "fragments/markdownEditor" (dict "Name" $bodyName "Value" $bodyValue "Rows" 4 "Placeholder" "Describe this pull request. Markdown is supported." - "LabelText" "description" - "PreviewUrl" $previewUrl ) }}
{{ if $hasSidePanel }} diff --git a/appview/pages/templates/strings/string.html b/appview/pages/templates/strings/string.html index 0029cc4f..c6746af5 100644 --- a/appview/pages/templates/strings/string.html +++ b/appview/pages/templates/strings/string.html @@ -125,13 +125,11 @@
{{ template "user/fragments/picHandleLink" .LoggedInUser.Did }}
- + {{ template "fragments/markdownEditor" + (dict "Name" "body" + "BlobName" "blob" + "Required" true + "Placeholder" "Add to the discussion. Markdown is supported.") }}
diff --git a/appview/pulls/compose.go b/appview/pulls/compose.go index f6735fb0..3bc379f6 100644 --- a/appview/pulls/compose.go +++ b/appview/pulls/compose.go @@ -155,11 +155,6 @@ func (s *Pulls) NewPull(w http.ResponseWriter, r *http.Request) { } } -func (s *Pulls) MarkdownPreview(w http.ResponseWriter, r *http.Request) { - body := r.FormValue("body") - s.pages.MarkdownPreviewFragment(w, body) -} - func (s *Pulls) RefreshCompose(w http.ResponseWriter, r *http.Request) { l := s.logger.With("handler", "RefreshCompose") diff --git a/appview/pulls/router.go b/appview/pulls/router.go index e247846f..6d7dfe66 100644 --- a/appview/pulls/router.go +++ b/appview/pulls/router.go @@ -14,7 +14,6 @@ func (s *Pulls) Router(mw *middleware.Middleware) http.Handler { r.Get("/", s.NewPull) r.Get("/refresh", s.RefreshCompose) r.Post("/refresh", s.RefreshCompose) - r.Post("/preview", s.MarkdownPreview) r.Post("/", s.NewPull) }) diff --git a/appview/state/comment.go b/appview/state/comment.go index 7af5a29a..6fe6d6c3 100644 --- a/appview/state/comment.go +++ b/appview/state/comment.go @@ -71,7 +71,7 @@ func (s *State) EditCommentFragment(w http.ResponseWriter, r *http.Request) { Comment: comment, }) if err != nil { - l.Error("failed to render") + l.Error("failed to render", "err", err) } } diff --git a/appview/state/markup.go b/appview/state/markup.go new file mode 100644 index 00000000..21e068c9 --- /dev/null +++ b/appview/state/markup.go @@ -0,0 +1,8 @@ +package state + +import "net/http" + +func (s *State) MarkdownPreview(w http.ResponseWriter, r *http.Request) { + body := r.FormValue("body") + s.pages.MarkdownPreviewFragment(w, body) +} diff --git a/appview/state/router.go b/appview/state/router.go index b1d9b13f..1c685537 100644 --- a/appview/state/router.go +++ b/appview/state/router.go @@ -257,6 +257,9 @@ func (s *State) StandardRouter(mw *middleware.Middleware) http.Handler { r.Delete("/", s.DeleteComment) }) + r.With(middleware.AuthMiddleware(s.oauth)).Route("/markup", func(r chi.Router) { + r.Post("/preview", s.MarkdownPreview) + }) r.Get("/profile/popover", s.ProfilePopover) r.Route("/profile", func(r chi.Router) { -- 2.51.2