2017-08-18 21:30:16 +00:00
|
|
|
import { put, call, takeEvery } from 'redux-saga/effects';
|
2017-08-17 02:06:22 +00:00
|
|
|
import * as types from '../actions/actionsTypes';
|
|
|
|
import { roomsSuccess, roomsFailure } from '../actions/rooms';
|
|
|
|
import RocketChat from '../lib/rocketchat';
|
|
|
|
|
2017-08-18 21:30:16 +00:00
|
|
|
const getRooms = function* getRooms() {
|
|
|
|
return yield RocketChat.getRooms();
|
|
|
|
};
|
2017-08-17 02:06:22 +00:00
|
|
|
|
|
|
|
const watchRoomsRequest = function* watchRoomsRequest() {
|
2017-08-18 21:30:16 +00:00
|
|
|
try {
|
2017-08-21 00:11:46 +00:00
|
|
|
console.log('getRooms');
|
2017-08-18 21:30:16 +00:00
|
|
|
yield call(getRooms);
|
|
|
|
yield put(roomsSuccess());
|
|
|
|
} catch (err) {
|
2017-09-21 17:08:00 +00:00
|
|
|
console.log(err);
|
2017-08-18 21:30:16 +00:00
|
|
|
yield put(roomsFailure(err.status));
|
2017-08-17 02:06:22 +00:00
|
|
|
}
|
|
|
|
};
|
2017-08-18 21:30:16 +00:00
|
|
|
const root = function* root() {
|
|
|
|
yield takeEvery(types.LOGIN.SUCCESS, watchRoomsRequest);
|
|
|
|
};
|
|
|
|
export default root;
|