mirror of
https://gitea.phreedom.club/localhost_frssoft/bloat.git
synced 2024-11-27 01:13:00 +00:00
Use a single form for new posts and replies
This commit is contained in:
parent
df875381d4
commit
39c57a6b65
7
model/replyContext.go
Normal file
7
model/replyContext.go
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
package model
|
||||||
|
|
||||||
|
type ReplyContext struct {
|
||||||
|
InReplyToID string
|
||||||
|
InReplyToName string
|
||||||
|
ReplyContent string
|
||||||
|
}
|
@ -2,6 +2,7 @@ package renderer
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"mastodon"
|
"mastodon"
|
||||||
|
"web/model"
|
||||||
)
|
)
|
||||||
|
|
||||||
type NavbarTemplateData struct {
|
type NavbarTemplateData struct {
|
||||||
@ -37,17 +38,15 @@ func NewTimelinePageTemplateData(statuses []*mastodon.Status, hasNext bool, next
|
|||||||
|
|
||||||
type ThreadPageTemplateData struct {
|
type ThreadPageTemplateData struct {
|
||||||
Statuses []*mastodon.Status
|
Statuses []*mastodon.Status
|
||||||
ReplyToID string
|
ReplyContext *model.ReplyContext
|
||||||
ReplyContent string
|
|
||||||
ReplyMap map[string][]mastodon.ReplyInfo
|
ReplyMap map[string][]mastodon.ReplyInfo
|
||||||
NavbarData *NavbarTemplateData
|
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{
|
return &ThreadPageTemplateData{
|
||||||
Statuses: statuses,
|
Statuses: statuses,
|
||||||
ReplyToID: replyToID,
|
ReplyContext: replyContext,
|
||||||
ReplyContent: replyContent,
|
|
||||||
ReplyMap: replyMap,
|
ReplyMap: replyMap,
|
||||||
NavbarData: navbarData,
|
NavbarData: navbarData,
|
||||||
}
|
}
|
||||||
|
@ -276,10 +276,9 @@ func (svc *service) ServeThreadPage(ctx context.Context, client io.Writer, c *ma
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
var content string
|
var replyContext *model.ReplyContext
|
||||||
var replyToID string
|
|
||||||
if reply {
|
if reply {
|
||||||
replyToID = id
|
var content string
|
||||||
if u.ID != status.Account.ID {
|
if u.ID != status.Account.ID {
|
||||||
content += "@" + status.Account.Acct + " "
|
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 + " "
|
content += "@" + status.Mentions[i].Acct + " "
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
replyContext = &model.ReplyContext{
|
||||||
|
InReplyToID: id,
|
||||||
|
InReplyToName: status.Account.Acct,
|
||||||
|
ReplyContent: content,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
context, err := c.GetStatusContext(ctx, id)
|
context, err := c.GetStatusContext(ctx, id)
|
||||||
@ -310,7 +314,7 @@ func (svc *service) ServeThreadPage(ctx context.Context, client io.Writer, c *ma
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
data := renderer.NewThreadPageTemplateData(statuses, replyToID, content, replyMap, navbarData)
|
data := renderer.NewThreadPageTemplateData(statuses, replyContext, replyMap, navbarData)
|
||||||
err = svc.renderer.RenderThreadPage(ctx, client, data)
|
err = svc.renderer.RenderThreadPage(ctx, client, data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
|
@ -107,7 +107,7 @@
|
|||||||
margin-right: 8px;
|
margin-right: 8px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.timeline-post-form {
|
.post-form {
|
||||||
margin: 8px 0;
|
margin: 8px 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
16
templates/postform.tmpl
Normal file
16
templates/postform.tmpl
Normal 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>
|
||||||
|
|
@ -3,21 +3,11 @@
|
|||||||
<div class="page-title"> Thread </div>
|
<div class="page-title"> Thread </div>
|
||||||
|
|
||||||
{{range .Statuses}}
|
{{range .Statuses}}
|
||||||
{{template "status.tmpl" .}}
|
|
||||||
|
|
||||||
{{if eq .ID $.ReplyToID}}
|
{{template "status.tmpl" .}}
|
||||||
<form class="timeline-post-form" action="/post" method="POST" enctype="multipart/form-data">
|
{{if $.ReplyContext}}{{if eq .ID $.ReplyContext.InReplyToID}}
|
||||||
<input type="hidden" name="reply_to_id" value="{{$.ReplyToID}}" />
|
{{template "postform.tmpl" $.ReplyContext}}
|
||||||
<label for="post-content"> reply to {{.Account.DisplayName}} </label>
|
{{end}}{{end}}
|
||||||
<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}}
|
|
||||||
|
|
||||||
{{end}}
|
{{end}}
|
||||||
|
|
||||||
|
@ -2,16 +2,8 @@
|
|||||||
{{template "navigation.tmpl" .NavbarData}}
|
{{template "navigation.tmpl" .NavbarData}}
|
||||||
<div class="page-title"> Timeline </div>
|
<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>
|
{{template "postform.tmpl" }}
|
||||||
<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>
|
|
||||||
|
|
||||||
{{range .Statuses}}
|
{{range .Statuses}}
|
||||||
{{template "status.tmpl" .}}
|
{{template "status.tmpl" .}}
|
||||||
|
Loading…
Reference in New Issue
Block a user