[FIX] Change server issue (#960)

* [FIX] Lazy fetch server info

* [FIX] Multiple servers issues
This commit is contained in:
Diego Mello 2019-06-05 16:11:29 -03:00 committed by GitHub
parent 109a247c8d
commit 3cd84a10f6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 71 additions and 61 deletions

View File

@ -174,6 +174,7 @@ const RocketChat = {
this.getUserPresence(); this.getUserPresence();
}, },
connect({ server, user }) { connect({ server, user }) {
return new Promise((resolve) => {
database.setActiveDB(server); database.setActiveDB(server);
reduxStore.dispatch(connectRequest()); reduxStore.dispatch(connectRequest());
@ -239,6 +240,9 @@ const RocketChat = {
} }
} }
})); }));
resolve();
});
}, },
register(credentials) { register(credentials) {

View File

@ -39,11 +39,11 @@ const handleSelectServer = function* handleSelectServer({ server, version, fetch
if (userStringified) { if (userStringified) {
const user = JSON.parse(userStringified); const user = JSON.parse(userStringified);
RocketChat.connect({ server, user }); yield RocketChat.connect({ server, user });
yield put(setUser(user)); yield put(setUser(user));
yield put(actions.appStart('inside')); yield put(actions.appStart('inside'));
} else { } else {
RocketChat.connect({ server }); yield RocketChat.connect({ server });
yield put(actions.appStart('outside')); yield put(actions.appStart('outside'));
} }

View File

@ -60,7 +60,11 @@ const Header = React.memo(({
} }
return ( return (
<View style={styles.container}> <View style={styles.container}>
<TouchableOpacity onPress={onPress} testID='rooms-list-header-server-dropdown-button'> <TouchableOpacity
onPress={onPress}
testID='rooms-list-header-server-dropdown-button'
disabled={connecting || isFetching}
>
{connecting ? <Text style={styles.updating}>{I18n.t('Connecting')}</Text> : null} {connecting ? <Text style={styles.updating}>{I18n.t('Connecting')}</Text> : null}
{isFetching ? <Text style={styles.updating}>{I18n.t('Updating')}</Text> : null} {isFetching ? <Text style={styles.updating}>{I18n.t('Updating')}</Text> : null}
<View style={styles.button}> <View style={styles.button}>

View File

@ -40,13 +40,14 @@ const styles = StyleSheet.create({
}); });
const HeaderTitle = React.memo(({ connecting, isFetching }) => { const HeaderTitle = React.memo(({ connecting, isFetching }) => {
let title = I18n.t('Messages');
if (connecting) { if (connecting) {
return <Text style={styles.title}>{I18n.t('Connecting')}</Text>; title = I18n.t('Connecting');
} }
if (isFetching) { if (isFetching) {
return <Text style={styles.title}>{I18n.t('Updating')}</Text>; title = I18n.t('Updating');
} }
return <Text style={styles.title}>{I18n.t('Messages')}</Text>; return <Text style={styles.title}>{title}</Text>;
}); });
const Header = React.memo(({ const Header = React.memo(({
@ -57,6 +58,7 @@ const Header = React.memo(({
onPress={onPress} onPress={onPress}
testID='rooms-list-header-server-dropdown-button' testID='rooms-list-header-server-dropdown-button'
style={styles.container} style={styles.container}
disabled={connecting || isFetching}
> >
<HeaderTitle connecting={connecting} isFetching={isFetching} /> <HeaderTitle connecting={connecting} isFetching={isFetching} />
<View style={styles.button}> <View style={styles.button}>

View File

@ -11,7 +11,7 @@ import Header from './Header';
showServerDropdown: state.rooms.showServerDropdown, showServerDropdown: state.rooms.showServerDropdown,
showSortDropdown: state.rooms.showSortDropdown, showSortDropdown: state.rooms.showSortDropdown,
showSearchHeader: state.rooms.showSearchHeader, showSearchHeader: state.rooms.showSearchHeader,
connecting: state.meteor.connecting, connecting: state.meteor.connecting || state.server.loading,
isFetching: state.rooms.isFetching, isFetching: state.rooms.isFetching,
serverName: state.settings.Site_Name serverName: state.settings.Site_Name
}), dispatch => ({ }), dispatch => ({