feat: separate post

This commit is contained in:
Yanislav Igonin 2022-01-31 15:26:54 +02:00
parent 7898323167
commit b43e1f431e
3 changed files with 29 additions and 20 deletions

View File

@ -19,6 +19,13 @@ type Post struct {
UpdatedAt time.Time `json:"-"`
}
func (p *Post) getThreadID() int {
if p.IsParent {
return p.ID
}
return p.ParentID
}
type File struct {
ID int `json:"-"`
PostID int `json:"-"`
@ -39,6 +46,7 @@ type HtmlFormData struct {
IsCaptchaActive bool
}
// index.html
type HtmlPaginationData struct {
PagesCount int
Page int

View File

@ -0,0 +1,20 @@
{{ define "post" }}
<div class="post-container mb-4">
{{ $filesLength := len .Files }}
{{ if gt $filesLength 0 }}
<div class="files-container">
{{ range $File := .Files }}
<div class="file-container">
<a href="/uploads/{{.getThreadID}}/o/{{$File.ID}}.{{$File.Ext}}" target="blank">
<img src="/uploads/{{.getThreadID}}/t/{{$File.ID}}.{{$File.Ext}}" class="file" alt="Uploaded picture">
</a>
</div>
{{ end }}
</div>
{{ end }}
<div class="p-2">
<p class="card-text line-break text-break">{{.Text}}</p>
</div>
</div>
{{ end }}

View File

@ -18,26 +18,7 @@
<div id="postsСontainer">
{{ range $Post := .Thread }}
<div class="post-container mb-4">
{{ $filesLength := len $Post.Files }}
{{ if gt $filesLength 0 }}
<div class="files-container">
{{ range $File := $Post.Files }}
<div class="file-container">
<a href="/uploads/{{$FirstPost.ID}}/o/{{$File.ID}}.{{$File.Ext}}" target="blank">
<img src="/uploads/{{$FirstPost.ID}}/t/{{$File.ID}}.{{$File.Ext}}" class="file" alt="Uploaded picture">
</a>
</div>
{{ end }}
</div>
{{ end }}
<div class="p-2">
<p class="card-text line-break text-break">{{$Post.Text}}</p>
</div>
</div>
{{ template "post" $Post }}
{{ end }}
</div>
</div>