25 lines
637 B
TypeScript
25 lines
637 B
TypeScript
import { put, call } from 'redux-saga/effects';
|
|
import { FETCH_PROJECTS_SUCCESS, FETCH_PROJECTS_FAILURE } from '../actions/projects';
|
|
import { gitea } from '../../util/gitea';
|
|
|
|
export function* fetchProjectsSaga() {
|
|
let projects = [];
|
|
try {
|
|
let page = 1;
|
|
while(true) {
|
|
let pageProjects = yield call(gitea.fetchUserProjects.bind(gitea), page);
|
|
if (pageProjects.length === 0) {
|
|
break;
|
|
}
|
|
projects.push(...pageProjects);
|
|
page++;
|
|
}
|
|
|
|
} catch(error) {
|
|
yield put({ type: FETCH_PROJECTS_FAILURE, error });
|
|
return;
|
|
}
|
|
|
|
yield put({ type: FETCH_PROJECTS_SUCCESS, projects });
|
|
}
|