Use a single form for new posts and replies
authorr <r@freesoftwareextremist.com>
Sat, 21 Dec 2019 08:36:44 +0000 (08:36 +0000)
committerr <r@freesoftwareextremist.com>
Sat, 21 Dec 2019 08:38:42 +0000 (08:38 +0000)
model/replyContext.go [new file with mode: 0644]
renderer/model.go
service/service.go
static/main.css
templates/postform.tmpl [new file with mode: 0644]
templates/thread.tmpl
templates/timeline.tmpl

diff --git a/model/replyContext.go b/model/replyContext.go
new file mode 100644 (file)
index 0000000..b17aacb
--- /dev/null
@@ -0,0 +1,7 @@
+package model
+
+type ReplyContext struct {
+       InReplyToID   string
+       InReplyToName string
+       ReplyContent  string
+}
index 053c2fd30b6aeaddd1b09970ac6824d5e83f5a00..ce81e78d2743da7750386f6b6d7d809edb759e5d 100644 (file)
@@ -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,
        }
index 4d74449bc59fc1a3aac59dd57725e70018b19880..db7a1d7750f9ff493dca51c27fd6b48fd2fd38ec 100644 (file)
@@ -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
index 834117213c52191790aea6eb8fe788227c53c3a3..4f8d1565b58e6c806f34110594ee383f50cbb503 100644 (file)
        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 (file)
index 0000000..3f6eeaa
--- /dev/null
@@ -0,0 +1,16 @@
+<form class="post-form" action="/post" method="POST" enctype="multipart/form-data">
+       {{if .}}
+       <input type="hidden" name="reply_to_id" value="{{.InReplyToID}}" />
+       <label for="post-content"> Reply to {{.InReplyToName}} </label>
+       {{else}}
+       <label for="post-content"> New post </label>
+       {{end}}
+       <div class="post-form-content-container">
+               <textarea id="post-content" name="content" class="post-content" cols="50" rows="5">{{if .}}{{.ReplyContent}}{{end}}</textarea>
+       </div>
+       <div>
+               Attachments <input id="post-file-picker" type="file" name="attachments" multiple>
+       </div>
+       <button type="submit"> Post </button>
+</form>
+
index d4c88de59963995a5129cd6757370618d60bf8ce..9d8f6503aacf02fcf8f06a0899f64f17dd2aa6f8 100644 (file)
@@ -3,21 +3,11 @@
 <div class="page-title"> Thread </div>
 
 {{range .Statuses}}
-{{template "status.tmpl" .}}
 
-{{if eq .ID $.ReplyToID}}
-<form class="timeline-post-form" action="/post" method="POST" enctype="multipart/form-data">
-       <input type="hidden" name="reply_to_id" value="{{$.ReplyToID}}" />
-       <label for="post-content"> reply to {{.Account.DisplayName}} </label>
-       <div class="post-form-content-container">
-               <textarea id="post-content" name="content" class="post-content" cols="50" rows="5">{{$.ReplyContent}}</textarea>
-       </div>
-       <div>
-               Attachments <input id="post-file-picker" type="file" name="attachments" multiple>
-       </div>
-       <button type="submit"> Post </button>
-</form>
-{{end}}
+{{template "status.tmpl" .}}
+{{if $.ReplyContext}}{{if eq .ID $.ReplyContext.InReplyToID}}
+{{template "postform.tmpl" $.ReplyContext}}
+{{end}}{{end}}
 
 {{end}}
 
index fe426ded18d05037b44d7cdc9434b623c767cfe6..09717c16194f0949ade1a9d990279d116aac64b1 100644 (file)
@@ -2,16 +2,8 @@
 {{template "navigation.tmpl" .NavbarData}}
 <div class="page-title"> Timeline </div>
 
-<form class="timeline-post-form" action="/post" method="POST" enctype="multipart/form-data">
-       <label for="post-content"> New Post </label>
-       <div class="post-content-container">
-               <textarea id="post-content" name="content" class="post-content" cols="50" rows="5"></textarea>
-       </div>
-       <div class="post-attachment-div">
-               Attachments <input id="post-file-picker" type="file" name="attachments" multiple>
-       </div>
-       <button type="submit"> Post </button>
-</form>
+
+{{template "postform.tmpl" }}
 
 {{range .Statuses}}
 {{template "status.tmpl" .}}