spee.ch/react/sagas/show_channel.js

36 lines
1.3 KiB
JavaScript
Raw Normal View History

2018-02-08 23:17:03 +01:00
import { call, put, takeLatest } from 'redux-saga/effects';
import * as actions from 'constants/show_action_types';
import { updateRequestError, addNewChannelToChannelList, updateChannelClaims } from 'actions/show';
2018-02-08 23:17:03 +01:00
import { getChannelClaims } from 'api/channelApi';
function* getChannelClaimsAndShowChannel (action) {
const { id, name, shortId, longId } = action.data;
let claimsData;
2018-02-08 23:17:03 +01:00
try {
({ data: claimsData } = yield call(getChannelClaims, name, longId, 1));
2018-02-08 23:17:03 +01:00
} catch (error) {
return yield put(updateRequestError(error.message));
2018-02-08 23:17:03 +01:00
}
yield put(addNewChannelToChannelList(id, name, shortId, longId, claimsData));
yield put(updateRequestError(null));
2018-02-08 23:17:03 +01:00
}
export function* watchShowNewChannel () {
2018-02-13 05:01:02 +01:00
yield takeLatest(actions.CHANNEL_NEW_ASYNC, getChannelClaimsAndShowChannel);
2018-02-08 23:17:03 +01:00
};
function* getNewClaimsAndUpdateClaimsList (action) {
const { channelKey, name, longId, page } = action.data;
let claimsData;
try {
({ data: claimsData } = yield call(getChannelClaims, name, longId, page));
} catch (error) {
return yield put(updateRequestError(error.message));
}
yield put(updateChannelClaims(channelKey, claimsData));
}
export function* watchShowNewChannelClaimsRequest () {
2018-02-13 05:01:02 +01:00
yield takeLatest(actions.CHANNEL_CLAIMS_UPDATE_ASYNC, getNewClaimsAndUpdateClaimsList);
}