Use a single form for new posts and replies

This commit is contained in:
r 2019-12-21 08:36:44 +00:00
parent df875381d4
commit 39c57a6b65
7 changed files with 42 additions and 34 deletions

7
model/replyContext.go Normal file
View File

@ -0,0 +1,7 @@
package model
type ReplyContext struct {
InReplyToID string
InReplyToName string
ReplyContent string
}

View 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,
}

View 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

View File

@ -107,7 +107,7 @@
margin-right: 8px;
}
.timeline-post-form {
.post-form {
margin: 8px 0;
}

16
templates/postform.tmpl Normal file
View File

@ -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>

View 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}}

View 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" .}}