[FIX] White screen on start on single-server (#3329)

This commit is contained in:
Alex Junior 2021-08-16 15:19:06 -03:00 committed by GitHub
parent 8ee9a8ab75
commit ea46ae8469
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 9 additions and 20 deletions

View File

@ -1,4 +1,4 @@
import { put, takeLatest } from 'redux-saga/effects'; import { put, takeLatest, all } from 'redux-saga/effects';
import RNBootSplash from 'react-native-bootsplash'; import RNBootSplash from 'react-native-bootsplash';
// import * as actions from '../actions'; // import * as actions from '../actions';
@ -28,26 +28,15 @@ export const initLocalSettings = function* initLocalSettings() {
const restore = function* restore() { const restore = function* restore() {
try { try {
const server = yield UserPreferences.getStringAsync(RocketChat.CURRENT_SERVER); const { server } = appConfig;
let userId = yield UserPreferences.getStringAsync(`${ RocketChat.TOKEN_KEY }-${ server }`); const userId = yield UserPreferences.getStringAsync(`${ RocketChat.TOKEN_KEY }-${ server }`);
if (!server) { if (!userId) {
yield put(appStart({ root: ROOT_OUTSIDE })); yield all([
} else if (!userId) { UserPreferences.removeItem(RocketChat.TOKEN_KEY),
const serversDB = database.servers; UserPreferences.removeItem(RocketChat.CURRENT_SERVER)
const serversCollection = serversDB.get('servers'); ]);
const servers = yield serversCollection.query().fetch(); yield put(serverRequest(appConfig.server));
// Check if there're other logged in servers and picks first one
if (servers.length > 0) {
for (let i = 0; i < servers.length; i += 1) {
const newServer = servers[i].id;
userId = yield UserPreferences.getStringAsync(`${ RocketChat.TOKEN_KEY }-${ newServer }`);
if (userId) {
return yield put(selectServerRequest(newServer));
}
}
}
yield put(appStart({ root: ROOT_OUTSIDE })); yield put(appStart({ root: ROOT_OUTSIDE }));
} else { } else {
const serversDB = database.servers; const serversDB = database.servers;