import {take, put, call, fork, cancel, all, takeEvery} from 'redux-saga/effects';
import {get} from '../ajax';
import Actions from '../actions';

function* fetchOverview() {
    try {
        const result = yield get('/api.php/uebersicht');
        yield put(Actions.loadedOverview(result.data));
    }
    catch (e) {
        console.error("Exception in fetchOverview:", e);
        throw e;
    }
}

function* watchOverview() {
    yield takeEvery(Actions.ACTION_TYPES.LOAD_OVERVIEW, fetchOverview);
}

export default function* watchDataLoad() {
    yield all([
        fork(watchOverview)
    ]);
}
