From b43e1f431ea42aa78d5f70e5e14ac2a3ae7e4878 Mon Sep 17 00:00:00 2001 From: Yanislav Igonin Date: Mon, 31 Jan 2022 15:26:54 +0200 Subject: [PATCH] feat: separate post --- repositories/structs.go | 8 ++++++++ templates/components/post.html | 20 ++++++++++++++++++++ templates/pages/thread.html | 21 +-------------------- 3 files changed, 29 insertions(+), 20 deletions(-) create mode 100644 templates/components/post.html diff --git a/repositories/structs.go b/repositories/structs.go index 38ed648..164d677 100644 --- a/repositories/structs.go +++ b/repositories/structs.go @@ -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 diff --git a/templates/components/post.html b/templates/components/post.html new file mode 100644 index 0000000..267f522 --- /dev/null +++ b/templates/components/post.html @@ -0,0 +1,20 @@ +{{ define "post" }} +
+ {{ $filesLength := len .Files }} + {{ if gt $filesLength 0 }} +
+ {{ range $File := .Files }} +
+ + Uploaded picture + +
+ {{ end }} +
+ {{ end }} + +
+

{{.Text}}

+
+
+{{ end }} \ No newline at end of file diff --git a/templates/pages/thread.html b/templates/pages/thread.html index dc38f8f..4671a2f 100644 --- a/templates/pages/thread.html +++ b/templates/pages/thread.html @@ -18,26 +18,7 @@
{{ range $Post := .Thread }} -
- - {{ $filesLength := len $Post.Files }} - {{ if gt $filesLength 0 }} -
- {{ range $File := $Post.Files }} -
- - Uploaded picture - -
- {{ end }} -
- {{ end }} - -
-

{{$Post.Text}}

-
- -
+ {{ template "post" $Post }} {{ end }}