mirror of
https://gitea.phreedom.club/localhost_frssoft/bloat.git
synced 2024-12-25 15:09:49 +00:00
Fix prev pagination
This commit is contained in:
parent
e129ea922e
commit
51a4b16af5
@ -208,7 +208,6 @@ func (svc *service) ServeTimelinePage(ctx context.Context, client io.Writer,
|
|||||||
|
|
||||||
var pg = mastodon.Pagination{
|
var pg = mastodon.Pagination{
|
||||||
MaxID: maxID,
|
MaxID: maxID,
|
||||||
SinceID: sinceID,
|
|
||||||
MinID: minID,
|
MinID: minID,
|
||||||
Limit: 20,
|
Limit: 20,
|
||||||
}
|
}
|
||||||
@ -218,14 +217,31 @@ func (svc *service) ServeTimelinePage(ctx context.Context, client io.Writer,
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if len(maxID) > 0 && len(statuses) > 0 {
|
||||||
|
hasPrev = true
|
||||||
|
prevLink = fmt.Sprintf("/timeline?min_id=%s", statuses[0].ID)
|
||||||
|
}
|
||||||
|
if len(minID) > 0 && len(pg.MinID) > 0 {
|
||||||
|
newStatuses, err := c.GetTimelineHome(ctx, &mastodon.Pagination{MinID: pg.MinID, Limit: 20})
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
newStatusesLen := len(newStatuses)
|
||||||
|
if newStatusesLen == 20 {
|
||||||
|
hasPrev = true
|
||||||
|
prevLink = fmt.Sprintf("/timeline?min_id=%s", pg.MinID)
|
||||||
|
} else {
|
||||||
|
i := 20 - newStatusesLen - 1
|
||||||
|
if len(statuses) > i {
|
||||||
|
hasPrev = true
|
||||||
|
prevLink = fmt.Sprintf("/timeline?min_id=%s", statuses[i].ID)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
if len(pg.MaxID) > 0 {
|
if len(pg.MaxID) > 0 {
|
||||||
hasNext = true
|
hasNext = true
|
||||||
nextLink = fmt.Sprintf("/timeline?max_id=%s", pg.MaxID)
|
nextLink = fmt.Sprintf("/timeline?max_id=%s", pg.MaxID)
|
||||||
}
|
}
|
||||||
if len(pg.SinceID) > 0 {
|
|
||||||
hasPrev = true
|
|
||||||
prevLink = fmt.Sprintf("/timeline?since_id=%s", pg.SinceID)
|
|
||||||
}
|
|
||||||
|
|
||||||
data := renderer.NewTimelinePageTemplateData(statuses, hasNext, nextLink, hasPrev, prevLink)
|
data := renderer.NewTimelinePageTemplateData(statuses, hasNext, nextLink, hasPrev, prevLink)
|
||||||
err = svc.renderer.RenderTimelinePage(ctx, client, data)
|
err = svc.renderer.RenderTimelinePage(ctx, client, data)
|
||||||
|
@ -135,3 +135,11 @@
|
|||||||
font-size: 11pt;
|
font-size: 11pt;
|
||||||
font-family: initial;
|
font-family: initial;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.pagination {
|
||||||
|
margin: 4px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.pagination a {
|
||||||
|
margin: 0 8px;
|
||||||
|
}
|
||||||
|
@ -16,10 +16,12 @@
|
|||||||
{{template "status.tmpl" .}}
|
{{template "status.tmpl" .}}
|
||||||
{{end}}
|
{{end}}
|
||||||
|
|
||||||
|
<div class="pagination">
|
||||||
|
{{if .HasPrev}}
|
||||||
|
<a href="{{.PrevLink}}">prev</a>
|
||||||
|
{{end}}
|
||||||
{{if .HasNext}}
|
{{if .HasNext}}
|
||||||
<a href="{{.NextLink}}">next</a>
|
<a href="{{.NextLink}}">next</a>
|
||||||
{{end}}
|
{{end}}
|
||||||
{{if .HasPrev}}
|
</div>
|
||||||
<a href="{{.PrevLink}}"> next </a>
|
|
||||||
{{end}}
|
|
||||||
{{template "footer.tmpl"}}
|
{{template "footer.tmpl"}}
|
||||||
|
Loading…
Reference in New Issue
Block a user