From 23aa5efc2f3461341d144e1cd6fb14487765a9d8 Mon Sep 17 00:00:00 2001 From: Seongmin Lee Date: Fri, 08 May 2026 20:21:51 +0000 Subject: [PATCH] appview: use markdownEditor fragment for all markdown body inputs Signed-off-by: Seongmin Lee --- 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 +++ appview/pages/templates/fragments/line-quote-button.html | 2 +- appview/pages/templates/fragments/markdownEditor.html | 69 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ appview/pages/templates/strings/string.html | 12 +++++------- appview/pages/templates/fragments/comment/edit.html | 11 ++++++----- appview/pages/templates/fragments/comment/reply.html | 12 ++++++------ appview/pages/templates/repo/issues/fragments/newComment.html | 19 +++++++------------ appview/pages/templates/repo/pulls/fragments/pullNewComment.html | 13 ++++++------- appview/pages/templates/repo/pulls/fragments/pullStepDetails.html | 98 +++++++++++++++----------------------------------------------------------------------------------- appview/pages/templates/repo/pulls/fragments/pullStepReview.html | 6 +----- 14 file(s) changed, 128 insertion(s)(+), 133 deletion(s)(-) diff --git a/appview/pulls/compose.go b/appview/pulls/compose.go --- a/appview/pulls/compose.go +++ b/appview/pulls/compose.go @@ -155,11 +155,6 @@ } } -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 --- a/appview/pulls/router.go +++ b/appview/pulls/router.go @@ -14,7 +14,6 @@ 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 --- a/appview/state/comment.go +++ b/appview/state/comment.go @@ -71,7 +71,7 @@ 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 --- /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 --- a/appview/state/router.go +++ b/appview/state/router.go @@ -257,6 +257,9 @@ 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) { 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 @@ -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 --- /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/strings/string.html b/appview/pages/templates/strings/string.html --- 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/pages/templates/fragments/comment/edit.html b/appview/pages/templates/fragments/comment/edit.html --- 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 --- 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/repo/issues/fragments/newComment.html b/appview/pages/templates/repo/issues/fragments/newComment.html --- 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 --- 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 --- 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,82 +16,37 @@ {{ 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" }} @@ -124,26 +78,4 @@
-{{ end }} - -{{ define "markdownEditorScript" }} - {{ end }} diff --git a/appview/pages/templates/repo/pulls/fragments/pullStepReview.html b/appview/pages/templates/repo/pulls/fragments/pullStepReview.html --- 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 }} -- tangled.sh