import { AsyncStorage } from 'react-native';
import { NavigationActions } from 'react-navigation';
import codePush from 'react-native-code-push';

export default {
  namespace: 'welcome',
  state: { },
  reducers: {},
  effects: {
    *init(ignored, { put, call }) {
      try {
        yield call(codePush.sync);
      } catch (e) {
        console.log(e); // eslint-disable-line no-console
      }
      const token = yield call(AsyncStorage.getItem, 'token');
      if (!token) {
        yield put(NavigationActions.navigate({
          routeName: 'Login',
        }));
      } else {
        yield put(NavigationActions.navigate({
          routeName: 'Main',
        }));
      }
    },
  },
};
