ref: 9ab6febaf561d60c49f62f003245e80340873ffc
parent: b74bf1e60f0bf1f4e044cff8ee4bf5e291b05d9e
author: penny <penny@limitedideas.org>
date: Wed Sep 24 09:32:07 EDT 2025
use an interface to load posts instead of pagination itself
--- a/hellclient.go
+++ b/hellclient.go
@@ -48,7 +48,7 @@
actionBuffer []func()
//pointer to our current page item
- page Page
+ page *Page
stats *Stats
}
--- a/main.go
+++ b/main.go
@@ -126,11 +126,9 @@
fmt.Printf(hc.page.String())
return
case "notice":
- noticePage := &NotificationPages{}- noticePage.hc = hc
- hc.page = noticePage
-
- fmt.Printf(noticePage.String())
+ hc.page = &Page{}+ hc.page.loader = &NotificationPages{hc: hc}+ fmt.Printf(hc.page.String())
return
case "notice2":
notifications, err := hc.GetUnreadNotifications()
--- a/pages.go
+++ b/pages.go
@@ -3,16 +3,19 @@
import (
"context"
"fmt"
+ "strings"
"codeberg.org/penny64/hellclient-go-mastodon"
)
-type Page interface {- String() string
- Next()
- Prev()
- Current() int64
+type StatusLoader interface {+ Load(int) *[]PageItem
}
+
+type Page struct {+ loader StatusLoader
+ index int
+}
type NotificationPages struct {hc *Hellclient
page *mastodon.Pagination
@@ -20,14 +23,14 @@
type PageItem struct {itemtext string
- lines int32
+ lines int
}
-func (noticeData *NotificationPages) String() string {+func (noticeData *NotificationPages) Load(limit int) *[]PageItem { if noticeData.page == nil { noticeData.page = &mastodon.Pagination{}}
- noticeData.page.Limit = 5
+ noticeData.page.Limit = int64(limit)
notices, err := noticeData.hc.client.GetNotifications(context.Background(), noticeData.page)
if err != nil { fmt.Printf("Error getting notification page: %s\n", err)@@ -35,17 +38,34 @@
fmt.Printf("%+v\n", noticeData.page)notices = reverseArray(notices)
- return noticeData.hc.RenderNotifications(notices)
+ noticeArray := noticeData.hc.RenderNotificationsArray(notices)
+
+ var itemArray []PageItem
+ for i, _ := range noticeArray {+ item := PageItem{itemtext: noticeArray[i]}+ itemArray = append(itemArray, item)
+ }
+
+ return &itemArray
}
-func (noticeData *NotificationPages) Next() {- noticeData.page.MinID = ""
+
+func (page *Page) String() string {+ items := page.loader.Load(5)
+ var sb strings.Builder
+
+ for i, _ := range *items {+ sb.WriteString((*items)[i].itemtext)
+ }
+ return sb.String()
}
-func (noticeData *NotificationPages) Prev() {- noticeData.page.MaxID = ""
+func (page *Page) Next() {}
-func (noticeData *NotificationPages) Current() int64 {+func (page *Page) Prev() {+}
+
+func (page *Page) Current() int {return 0
}
--
⑨