From 39c57a6b653a269668f459414d295e812f3628a8 Mon Sep 17 00:00:00 2001 From: r Date: Sat, 21 Dec 2019 08:36:44 +0000 Subject: Use a single form for new posts and replies --- model/replyContext.go | 7 +++++++ renderer/model.go | 9 ++++----- service/service.go | 12 ++++++++---- static/main.css | 2 +- templates/postform.tmpl | 16 ++++++++++++++++ templates/thread.tmpl | 18 ++++-------------- templates/timeline.tmpl | 12 ++---------- 7 files changed, 42 insertions(+), 34 deletions(-) create mode 100644 model/replyContext.go create mode 100644 templates/postform.tmpl diff --git a/model/replyContext.go b/model/replyContext.go new file mode 100644 index 0000000..b17aacb --- /dev/null +++ b/model/replyContext.go @@ -0,0 +1,7 @@ +package model + +type ReplyContext struct { + InReplyToID string + InReplyToName string + ReplyContent string +} diff --git a/renderer/model.go b/renderer/model.go index 053c2fd..ce81e78 100644 --- a/renderer/model.go +++ b/renderer/model.go @@ -2,6 +2,7 @@ package renderer import ( "mastodon" + "web/model" ) type NavbarTemplateData struct { @@ -37,17 +38,15 @@ func NewTimelinePageTemplateData(statuses []*mastodon.Status, hasNext bool, next type ThreadPageTemplateData struct { Statuses []*mastodon.Status - ReplyToID string - ReplyContent string + ReplyContext *model.ReplyContext ReplyMap map[string][]mastodon.ReplyInfo NavbarData *NavbarTemplateData } -func NewThreadPageTemplateData(statuses []*mastodon.Status, replyToID string, replyContent string, replyMap map[string][]mastodon.ReplyInfo, navbarData *NavbarTemplateData) *ThreadPageTemplateData { +func NewThreadPageTemplateData(statuses []*mastodon.Status, replyContext *model.ReplyContext, replyMap map[string][]mastodon.ReplyInfo, navbarData *NavbarTemplateData) *ThreadPageTemplateData { return &ThreadPageTemplateData{ Statuses: statuses, - ReplyToID: replyToID, - ReplyContent: replyContent, + ReplyContext: replyContext, ReplyMap: replyMap, NavbarData: navbarData, } diff --git a/service/service.go b/service/service.go index 4d74449..db7a1d7 100644 --- a/service/service.go +++ b/service/service.go @@ -276,10 +276,9 @@ func (svc *service) ServeThreadPage(ctx context.Context, client io.Writer, c *ma return } - var content string - var replyToID string + var replyContext *model.ReplyContext if reply { - replyToID = id + var content string if u.ID != status.Account.ID { content += "@" + status.Account.Acct + " " } @@ -288,6 +287,11 @@ func (svc *service) ServeThreadPage(ctx context.Context, client io.Writer, c *ma content += "@" + status.Mentions[i].Acct + " " } } + replyContext = &model.ReplyContext{ + InReplyToID: id, + InReplyToName: status.Account.Acct, + ReplyContent: content, + } } context, err := c.GetStatusContext(ctx, id) @@ -310,7 +314,7 @@ func (svc *service) ServeThreadPage(ctx context.Context, client io.Writer, c *ma return } - data := renderer.NewThreadPageTemplateData(statuses, replyToID, content, replyMap, navbarData) + data := renderer.NewThreadPageTemplateData(statuses, replyContext, replyMap, navbarData) err = svc.renderer.RenderThreadPage(ctx, client, data) if err != nil { return diff --git a/static/main.css b/static/main.css index 8341172..4f8d156 100644 --- a/static/main.css +++ b/static/main.css @@ -107,7 +107,7 @@ margin-right: 8px; } -.timeline-post-form { +.post-form { margin: 8px 0; } diff --git a/templates/postform.tmpl b/templates/postform.tmpl new file mode 100644 index 0000000..3f6eeaa --- /dev/null +++ b/templates/postform.tmpl @@ -0,0 +1,16 @@ +
+ {{if .}} + + + {{else}} + + {{end}} +
+ +
+
+ Attachments +
+ +
+ diff --git a/templates/thread.tmpl b/templates/thread.tmpl index d4c88de..9d8f650 100644 --- a/templates/thread.tmpl +++ b/templates/thread.tmpl @@ -3,21 +3,11 @@
Thread
{{range .Statuses}} -{{template "status.tmpl" .}} -{{if eq .ID $.ReplyToID}} -
- - -
- -
-
- Attachments -
- -
-{{end}} +{{template "status.tmpl" .}} +{{if $.ReplyContext}}{{if eq .ID $.ReplyContext.InReplyToID}} +{{template "postform.tmpl" $.ReplyContext}} +{{end}}{{end}} {{end}} diff --git a/templates/timeline.tmpl b/templates/timeline.tmpl index fe426de..09717c1 100644 --- a/templates/timeline.tmpl +++ b/templates/timeline.tmpl @@ -2,16 +2,8 @@ {{template "navigation.tmpl" .NavbarData}}
Timeline
-
- -
- -
-
- Attachments -
- -
+ +{{template "postform.tmpl" }} {{range .Statuses}} {{template "status.tmpl" .}} -- cgit v1.2.3