2017-01-23 20:04:12 +01:00
|
|
|
import { takeLatest } from 'redux-saga';
|
|
|
|
import { put } from 'redux-saga/effects';
|
|
|
|
|
|
|
|
import {
|
2017-01-26 18:53:52 +01:00
|
|
|
loadedRecord
|
2017-01-23 20:04:12 +01:00
|
|
|
} from './actions';
|
|
|
|
|
|
|
|
import {
|
2017-01-26 18:53:52 +01:00
|
|
|
LOAD_RECORDS
|
2017-01-23 20:04:12 +01:00
|
|
|
} from './constants';
|
|
|
|
|
|
|
|
export function* getRecords() {
|
|
|
|
const fakeData = [{
|
2017-01-26 17:53:47 +01:00
|
|
|
id: 1,
|
2017-01-23 20:04:12 +01:00
|
|
|
title: 'Roger Federer has won the first set.',
|
|
|
|
message: 'Try to do better than that man and you will be a winner.'
|
|
|
|
}, {
|
2017-01-26 17:53:47 +01:00
|
|
|
id: 2,
|
2017-01-23 20:04:12 +01:00
|
|
|
title: 'Lewis Hamilton is on fire.',
|
|
|
|
message: 'Did you ever seen someone like that guy?'
|
|
|
|
}, {
|
2017-01-26 17:53:47 +01:00
|
|
|
id: 3,
|
2017-01-23 20:04:12 +01:00
|
|
|
title: 'Elon Musk is awesome!',
|
|
|
|
message: 'Space X, Paypal, Tesla, & cie.'
|
|
|
|
}];
|
|
|
|
|
2017-01-28 18:11:54 +01:00
|
|
|
try {
|
|
|
|
const opts = {
|
|
|
|
method: 'GET',
|
|
|
|
mode: 'cors',
|
|
|
|
cache: 'default'
|
|
|
|
};
|
|
|
|
const response = yield fetch('http://localhost:1337/admin/config/models', opts);
|
|
|
|
const data = yield response.json();
|
|
|
|
|
|
|
|
yield put(loadedRecord(fakeData, data));
|
|
|
|
} catch (err) {
|
|
|
|
console.error(err);
|
|
|
|
}
|
2017-01-23 20:04:12 +01:00
|
|
|
}
|
|
|
|
|
2017-01-20 16:22:57 +01:00
|
|
|
|
|
|
|
// Individual exports for testing
|
|
|
|
export function* defaultSaga() {
|
2017-01-23 20:04:12 +01:00
|
|
|
yield takeLatest(LOAD_RECORDS, getRecords);
|
2017-01-20 16:22:57 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// All sagas to be loaded
|
|
|
|
export default [
|
|
|
|
defaultSaga,
|
|
|
|
];
|