app opens now at last selectioned server
This commit is contained in:
parent
e3fab36f0a
commit
2ba17081ea
|
@ -12,6 +12,7 @@ function createRequestTypes(base, types = defaultTypes) {
|
|||
// Login events
|
||||
export const LOGIN = createRequestTypes('LOGIN', [...defaultTypes, 'SET_TOKEN', 'SUBMIT']);
|
||||
export const ROOMS = createRequestTypes('ROOMS');
|
||||
export const APP = createRequestTypes('APP', ['READY']);
|
||||
export const MESSAGES = createRequestTypes('MESSAGES');
|
||||
export const NAVIGATION = createRequestTypes('NAVIGATION', ['SET']);
|
||||
export const SERVER = createRequestTypes('SERVER', ['SELECT', 'CHANGED']);
|
||||
|
|
|
@ -1,5 +1,11 @@
|
|||
import * as types from '../constants/types';
|
||||
import { APP } from './actionsTypes';
|
||||
|
||||
export function appReady() {
|
||||
return {
|
||||
type: APP.READY
|
||||
};
|
||||
}
|
||||
export function setCurrentServer(server) {
|
||||
return {
|
||||
type: types.SET_CURRENT_SERVER,
|
||||
|
|
|
@ -1,12 +1,16 @@
|
|||
import { fork } from 'redux-saga/effects';
|
||||
import { fork, take } from 'redux-saga/effects';
|
||||
import * as types from '../actions/actionsTypes';
|
||||
import hello from './hello';
|
||||
import login from './login';
|
||||
import connect from './connect';
|
||||
import rooms from './rooms';
|
||||
import messages from './messages';
|
||||
import selectServer from './selectServer';
|
||||
import init from './init';
|
||||
|
||||
const root = function* root() {
|
||||
yield fork(init);
|
||||
yield take(types.APP.READY);
|
||||
yield fork(hello);
|
||||
yield fork(rooms);
|
||||
yield fork(login);
|
||||
|
|
|
@ -0,0 +1,15 @@
|
|||
import { AsyncStorage } from 'react-native';
|
||||
import { call, put } from 'redux-saga/effects';
|
||||
import * as actions from '../actions';
|
||||
import { setServer } from '../actions/server';
|
||||
|
||||
const restore = function* restore() {
|
||||
try {
|
||||
const currentServer = yield call([AsyncStorage, 'getItem'], 'currentServer');
|
||||
yield put(actions.appReady({}));
|
||||
if (currentServer) { yield put(setServer(currentServer)); }
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
}
|
||||
};
|
||||
export default restore;
|
|
@ -1,12 +1,14 @@
|
|||
import { put, takeEvery } from 'redux-saga/effects';
|
||||
|
||||
import { put, takeEvery, call } from 'redux-saga/effects';
|
||||
import { AsyncStorage } from 'react-native';
|
||||
import { SERVER } from '../actions/actionsTypes';
|
||||
import { connectRequest, disconnect } from '../actions/connect';
|
||||
import { changedServer } from '../actions/server';
|
||||
|
||||
const selectServer = function* selectServer(server) {
|
||||
const selectServer = function* selectServer({ server }) {
|
||||
yield put(disconnect());
|
||||
yield put(changedServer(server));
|
||||
yield console.log('SERVER->', server);
|
||||
yield call([AsyncStorage, 'setItem'], 'currentServer', server);
|
||||
yield put(connectRequest(server));
|
||||
};
|
||||
const root = function* root() {
|
||||
|
|
Loading…
Reference in New Issue