feat: separate pagination

This commit is contained in:
Yanislav Igonin 2022-01-30 14:23:50 +02:00
parent c73c6e9aec
commit 5f72acdb3a
7 changed files with 28 additions and 19 deletions

View File

@ -55,8 +55,10 @@ func GetThreads(c *gin.Context) {
captchaID := captcha.New() captchaID := captcha.New()
htmlData := Repositories.GetThreadsHtmlData{ htmlData := Repositories.GetThreadsHtmlData{
Threads: threads, Threads: threads,
Pagination: Repositories.HtmlPaginationData{
PagesCount: pagesCount, PagesCount: pagesCount,
Page: page, Page: page,
},
FormData: Repositories.HtmlFormData{ FormData: Repositories.HtmlFormData{
CaptchaID: captchaID, CaptchaID: captchaID,
IsCaptchaActive: Config.App.IsCaptchaActive, IsCaptchaActive: Config.App.IsCaptchaActive,

View File

@ -39,6 +39,11 @@ type HtmlFormData struct {
IsCaptchaActive bool IsCaptchaActive bool
} }
type HtmlPaginationData struct {
PagesCount int
Page int
}
// thread.html // thread.html
type GetThreadHtmlData struct { type GetThreadHtmlData struct {
Thread []Post Thread []Post
@ -48,8 +53,7 @@ type GetThreadHtmlData struct {
// index.html // index.html
type GetThreadsHtmlData struct { type GetThreadsHtmlData struct {
Threads []Post `json:"threads"` Threads []Post `json:"threads"`
PagesCount int `json:"pagesCount"` Pagination HtmlPaginationData
Page int `json:"page"`
FormData HtmlFormData FormData HtmlFormData
} }

View File

@ -0,0 +1,12 @@
{{ define "pagiantion" }}
<nav aria-label="Page navigation">
<ul id="pagesList" class="pagination justify-content-center">
{{ $ActivePage := .Page }}
{{ range $i := Iterate .PagesCount }}
<li class="page-item {{ if (eq $i $ActivePage) }} active {{ end }}">
<a class="page-link" href="/?page={{ $i }}">{{ $i }}</a>
</li>
{{ end }}
</ul>
</nav>
{{ end }}

View File

@ -20,16 +20,7 @@
</div> </div>
<div class="col col-12"> <div class="col col-12">
<nav aria-label="Page navigation"> {{ template "pagiantion" .Pagination }}
<ul id="pagesList" class="pagination justify-content-center">
{{ $ActivePage := .Page }}
{{ range $i := Iterate .PagesCount }}
<li class="page-item {{ if (eq $i $ActivePage) }} active {{ end }}">
<a class="page-link" href="/?page={{ $i }}">{{ $i }}</a>
</li>
{{ end }}
</ul>
</nav>
</div> </div>
</div> </div>

View File

@ -38,7 +38,7 @@
</div> </div>
</div> </div>
{{end}} {{ end }}
</div> </div>
</div> </div>