aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--model/replyContext.go7
-rw-r--r--renderer/model.go9
-rw-r--r--service/service.go12
-rw-r--r--static/main.css2
-rw-r--r--templates/postform.tmpl16
-rw-r--r--templates/thread.tmpl18
-rw-r--r--templates/timeline.tmpl12
7 files changed, 42 insertions, 34 deletions
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 @@
+<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>
+
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 @@
<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}}
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}}
<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" .}}