diff options
author | r <r@freesoftwareextremist.com> | 2019-12-15 06:55:13 +0000 |
---|---|---|
committer | r <r@freesoftwareextremist.com> | 2019-12-15 06:55:13 +0000 |
commit | 51a4b16af518fde883df50f7f627fda21c18065e (patch) | |
tree | 26cc0c66a85db79bc0fc25d102998bf297329d28 | |
parent | e129ea922e6cbe8966f9a9f0b1c6c94401516c61 (diff) | |
download | bloat-51a4b16af518fde883df50f7f627fda21c18065e.tar.gz bloat-51a4b16af518fde883df50f7f627fda21c18065e.zip |
Fix prev pagination
-rw-r--r-- | service/service.go | 32 | ||||
-rw-r--r-- | static/main.css | 8 | ||||
-rw-r--r-- | templates/timeline.tmpl | 14 |
3 files changed, 40 insertions, 14 deletions
diff --git a/service/service.go b/service/service.go index 15dab5d..e502b65 100644 --- a/service/service.go +++ b/service/service.go @@ -207,10 +207,9 @@ func (svc *service) ServeTimelinePage(ctx context.Context, client io.Writer, var nextLink, prevLink string var pg = mastodon.Pagination{ - MaxID: maxID, - SinceID: sinceID, - MinID: minID, - Limit: 20, + MaxID: maxID, + MinID: minID, + Limit: 20, } statuses, err := c.GetTimelineHome(ctx, &pg) @@ -218,14 +217,31 @@ func (svc *service) ServeTimelinePage(ctx context.Context, client io.Writer, 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 { hasNext = true 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) err = svc.renderer.RenderTimelinePage(ctx, client, data) diff --git a/static/main.css b/static/main.css index f639357..3f551cc 100644 --- a/static/main.css +++ b/static/main.css @@ -135,3 +135,11 @@ font-size: 11pt; font-family: initial; } + +.pagination { + margin: 4px; +} + +.pagination a { + margin: 0 8px; +} diff --git a/templates/timeline.tmpl b/templates/timeline.tmpl index 51bf12e..527c91b 100644 --- a/templates/timeline.tmpl +++ b/templates/timeline.tmpl @@ -16,10 +16,12 @@ {{template "status.tmpl" .}} {{end}} -{{if .HasNext}} - <a href="{{.NextLink}}"> next </a> -{{end}} -{{if .HasPrev}} - <a href="{{.PrevLink}}"> next </a> -{{end}} +<div class="pagination"> + {{if .HasPrev}} + <a href="{{.PrevLink}}">prev</a> + {{end}} + {{if .HasNext}} + <a href="{{.NextLink}}">next</a> + {{end}} +</div> {{template "footer.tmpl"}} |