From e5eb2e0a7e15bd55649fee1201ec5cdf1ecc0c6d Mon Sep 17 00:00:00 2001 From: William Petit Date: Thu, 5 Dec 2019 14:44:33 +0100 Subject: [PATCH] Handle issues paging --- client/src/store/sagas/issues.js | 13 +++++++++++-- client/src/util/gitea.js | 4 ++-- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/client/src/store/sagas/issues.js b/client/src/store/sagas/issues.js index 98b5939..f2322d9 100644 --- a/client/src/store/sagas/issues.js +++ b/client/src/store/sagas/issues.js @@ -5,9 +5,18 @@ import { gitea } from '../../util/gitea'; export function* fetchIssuesSaga(action) { const { project } = action; - let issues; + let issues = []; try { - issues = yield call(gitea.fetchIssues.bind(gitea), action.project); + let page = 1; + while(true) { + let pageIssues = yield call(gitea.fetchIssues.bind(gitea), action.project, page); + if (pageIssues.length === 0) { + break; + } + issues.push(...pageIssues); + page++; + } + } catch(error) { yield put({ type: FETCH_ISSUES_FAILURE, project, error }); return; diff --git a/client/src/util/gitea.js b/client/src/util/gitea.js index 809d892..1f6a214 100644 --- a/client/src/util/gitea.js +++ b/client/src/util/gitea.js @@ -8,8 +8,8 @@ export class GiteaUnauthorizedError extends Error { export class GiteaClient { - fetchIssues(project) { - return fetch(`/gitea/api/v1/repos/${project}/issues`) + fetchIssues(project, page = 1) { + return fetch(`/gitea/api/v1/repos/${project}/issues?page=${page}`) .then(this.assertAuthorization) .then(res => res.json()) ;