2017-01-26 18:53:52 +01:00
|
|
|
import { takeLatest } from 'redux-saga';
|
2017-03-20 22:08:49 +01:00
|
|
|
import { put, select } from 'redux-saga/effects';
|
2017-01-26 18:53:52 +01:00
|
|
|
|
|
|
|
import {
|
|
|
|
loadedRecord,
|
|
|
|
} from './actions';
|
|
|
|
|
|
|
|
import {
|
|
|
|
LOAD_RECORD,
|
|
|
|
} from './constants';
|
|
|
|
|
2017-03-20 22:08:49 +01:00
|
|
|
import {
|
|
|
|
makeSelectCurrentModel,
|
|
|
|
} from './selectors';
|
|
|
|
|
|
|
|
export function* getRecord(params) {
|
|
|
|
const currentModel = yield select(makeSelectCurrentModel());
|
|
|
|
|
|
|
|
try {
|
|
|
|
const opts = {
|
|
|
|
method: 'GET',
|
|
|
|
mode: 'cors',
|
|
|
|
cache: 'default'
|
|
|
|
};
|
|
|
|
const response = yield fetch(`http://localhost:1337/content-manager/explorer/${currentModel}/${params.id}`, opts);
|
|
|
|
const data = yield response.json();
|
2017-01-26 18:53:52 +01:00
|
|
|
|
2017-03-20 22:08:49 +01:00
|
|
|
yield put(loadedRecord(data));
|
|
|
|
} catch (err) {
|
|
|
|
console.error(err);
|
|
|
|
}
|
2017-01-26 18:53:52 +01:00
|
|
|
}
|
2017-01-26 17:53:47 +01:00
|
|
|
|
|
|
|
// Individual exports for testing
|
|
|
|
export function* defaultSaga() {
|
2017-01-26 18:53:52 +01:00
|
|
|
yield takeLatest(LOAD_RECORD, getRecord);
|
2017-01-26 17:53:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// All sagas to be loaded
|
|
|
|
export default [
|
|
|
|
defaultSaga,
|
|
|
|
];
|