~emersion/public-inbox

yojo: /dashboard: implement pagination v1 APPLIED

Drew DeVault: 1
 /dashboard: implement pagination

 1 files changed, 25 insertions(+), 4 deletions(-)
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~emersion/public-inbox/patches/47863/mbox | git am -3
Learn more about email & git

[PATCH yojo] /dashboard: implement pagination Export this patch

Fetches all repos at once.

Implements: https://todo.sr.ht/~emersion/yojo/2
---
 main.go | 29 +++++++++++++++++++++++++----
 1 file changed, 25 insertions(+), 4 deletions(-)

diff --git a/main.go b/main.go
index 2f2000c..585c814 100644
--- a/main.go
+++ b/main.go
@@ -208,10 +208,31 @@ func main() {
			return
		}

		repos, _, err := giteaClient.ListMyRepos(gitea.ListReposOptions{})
		if err != nil {
			http.Error(w, fmt.Sprintf("failed to list Gitea repositories: %v", err), http.StatusInternalServerError)
			return
		var (
			repos   []*gitea.Repository
			page    int = 1
			maxPage int = -1
		)

		for maxPage == -1 || page <= maxPage {
			println(page, maxPage)
			batch, resp, err := giteaClient.ListMyRepos(gitea.ListReposOptions{
				ListOptions: gitea.ListOptions{
					Page: page,
				},
			})
			if err != nil {
				http.Error(w, fmt.Sprintf("failed to list Gitea repositories: %v", err), http.StatusInternalServerError)
				return
			}
			if maxPage == -1 {
				maxPage = resp.LastPage
			}
			repos = append(repos, batch...)
			if resp.NextPage == 0 {
				break
			}
			page = resp.NextPage
		}

		giteaHostname := sessionData.GiteaEndpoint
-- 
2.43.0
Pushed, thanks!