2017-08-21 03:00:41 +00:00
|
|
|
import { AsyncStorage } from 'react-native';
|
2017-09-21 17:08:00 +00:00
|
|
|
import { call, put, take } from 'redux-saga/effects';
|
2017-08-21 03:00:41 +00:00
|
|
|
import * as actions from '../actions';
|
|
|
|
import { setServer } from '../actions/server';
|
2017-11-13 13:19:24 +00:00
|
|
|
import { restoreToken } from '../actions/login';
|
2017-09-01 19:42:50 +00:00
|
|
|
import { APP } from '../actions/actionsTypes';
|
2017-08-21 03:00:41 +00:00
|
|
|
|
|
|
|
const restore = function* restore() {
|
|
|
|
try {
|
2017-09-01 19:42:50 +00:00
|
|
|
yield take(APP.INIT);
|
2017-11-13 13:19:24 +00:00
|
|
|
const token = yield call([AsyncStorage, 'getItem'], 'reactnativemeteor_usertoken');
|
|
|
|
if (token) {
|
|
|
|
yield put(restoreToken(token));
|
|
|
|
}
|
|
|
|
|
2017-08-21 03:00:41 +00:00
|
|
|
const currentServer = yield call([AsyncStorage, 'getItem'], 'currentServer');
|
2017-09-01 19:42:50 +00:00
|
|
|
if (currentServer) {
|
|
|
|
yield put(setServer(currentServer));
|
|
|
|
}
|
2017-11-13 13:19:24 +00:00
|
|
|
|
|
|
|
yield put(actions.appReady({}));
|
2017-08-21 03:00:41 +00:00
|
|
|
} catch (e) {
|
|
|
|
console.log(e);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
export default restore;
|