Fix prev pagination
authorr <r@freesoftwareextremist.com>
Sun, 15 Dec 2019 06:55:13 +0000 (06:55 +0000)
committerr <r@freesoftwareextremist.com>
Sun, 15 Dec 2019 06:55:13 +0000 (06:55 +0000)
service/service.go
static/main.css
templates/timeline.tmpl

index 15dab5da34df6d60edf5286926888c535df75923..e502b65f3c86da1253b12fc6022f2056cd6d2051 100644 (file)
@@ -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)
index f6393578a3fb81770659edd9a7ea61b502c93c1e..3f551cc7f90aae102eb198a243630f387ab3c41b 100644 (file)
        font-size: 11pt;
        font-family: initial;
 }
+
+.pagination {
+       margin: 4px;
+}
+
+.pagination a {
+       margin: 0 8px;
+}
index 51bf12e3652afce9552963da37b8cc48c368bef3..527c91b02f30dc1be91b4309b4270a0e32ac1277 100644 (file)
 {{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"}}