Skip to content
23 changes: 7 additions & 16 deletions app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,26 +18,17 @@ const startLogged = () => {
Navigation.loadView('RoomHeaderView');
Navigation.loadView('SettingsView');
Navigation.loadView('SidebarView');

Navigation.setRoot({
root: {
sideMenu: {
left: {
stack: {
id: 'AppRoot',
children: [{
component: {
id: 'SidebarView',
name: 'SidebarView'
id: 'RoomsListView',
name: 'RoomsListView'
}
},
center: {
stack: {
id: 'AppRoot',
children: [{
component: {
id: 'RoomsListView',
name: 'RoomsListView'
}
}]
}
}
}]
}
}
});
Expand Down
21 changes: 20 additions & 1 deletion app/sagas/login.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ import {
import Navigation from '../lib/Navigation';
import * as types from '../actions/actionsTypes';
import { appStart } from '../actions';
import { serverFinishAdd } from '../actions/server';
import { serverFinishAdd, selectServerRequest } from '../actions/server';
import { loginFailure, loginSuccess } from '../actions/login';
import RocketChat from '../lib/rocketchat';
import log from '../utils/log';
import I18n from '../i18n';
import database from '../lib/realm';

const getServer = state => state.server.server;
const loginWithPasswordCall = args => RocketChat.loginWithPassword(args);
Expand Down Expand Up @@ -60,8 +61,26 @@ const handleLogout = function* handleLogout() {
if (server) {
try {
yield call(logoutCall, { server });
const { serversDB } = database.databases;
// all servers
const servers = yield serversDB.objects('servers');
// filter logging out server and delete it
const serverRecord = servers.filtered('id = $0', server);
serversDB.write(() => {
serversDB.delete(serverRecord);
});
// see if there's other logged in servers and selects first one
if (servers.length > 0) {
const newServer = servers[0].id;
const token = yield AsyncStorage.getItem(`${ RocketChat.TOKEN_KEY }-${ newServer }`);
if (token) {
return yield put(selectServerRequest(newServer));
}
}
// if there's no servers, go outside
yield put(appStart('outside'));
} catch (e) {
yield put(appStart('outside'));
log('handleLogout', e);
}
}
Expand Down
41 changes: 1 addition & 40 deletions app/views/ProfileView/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import React from 'react';
import PropTypes from 'prop-types';
import {
View, ScrollView, Keyboard, BackHandler
} from 'react-native';
import { View, ScrollView, Keyboard } from 'react-native';
import { connect } from 'react-redux';
import Dialog from 'react-native-dialog';
import SHA256 from 'js-sha256';
Expand All @@ -12,7 +10,6 @@ import RNPickerSelect from 'react-native-picker-select';
import SafeAreaView from 'react-native-safe-area-view';
import equal from 'deep-equal';

import Navigation from '../../lib/Navigation';
import LoggedView from '../View';
import KeyboardView from '../../presentation/KeyboardView';
import sharedStyles from '../Styles';
Expand All @@ -26,9 +23,7 @@ import I18n from '../../i18n';
import Button from '../../containers/Button';
import Avatar from '../../containers/Avatar';
import Touch from '../../utils/touch';
import { appStart as appStartAction } from '../../actions';
import { setUser as setUserAction } from '../../actions/login';
import Icons from '../../lib/Icons';

@connect(state => ({
user: {
Expand All @@ -42,40 +37,24 @@ import Icons from '../../lib/Icons';
Accounts_CustomFields: state.settings.Accounts_CustomFields,
baseUrl: state.settings.Site_Url || state.server ? state.server.server : ''
}), dispatch => ({
appStart: () => dispatch(appStartAction()),
setUser: params => dispatch(setUserAction(params))
}))
/** @extends React.Component */
export default class ProfileView extends LoggedView {
static options() {
return {
topBar: {
leftButtons: [{
id: 'settings',
icon: Icons.getSource('settings'),
testID: 'rooms-list-view-sidebar'
}],
title: {
text: I18n.t('Profile')
}
},
sideMenu: {
left: {
enabled: true
},
right: {
enabled: true
}
}
};
}

static propTypes = {
baseUrl: PropTypes.string,
componentId: PropTypes.string,
user: PropTypes.object,
Accounts_CustomFields: PropTypes.string,
appStart: PropTypes.func,
setUser: PropTypes.func
}

Expand All @@ -94,8 +73,6 @@ export default class ProfileView extends LoggedView {
avatarSuggestions: {},
customFields: {}
};
Navigation.events().bindComponent(this);
BackHandler.addEventListener('hardwareBackPress', this.handleBackPress);
}

async componentDidMount() {
Expand Down Expand Up @@ -126,22 +103,6 @@ export default class ProfileView extends LoggedView {
return false;
}

componentWillUnmount() {
BackHandler.removeEventListener('hardwareBackPress', this.handleBackPress);
}

navigationButtonPressed = ({ buttonId }) => {
if (buttonId === 'settings') {
Navigation.toggleDrawer();
}
}

handleBackPress = () => {
const { appStart } = this.props;
appStart('background');
return false;
}

setAvatar = (avatar) => {
this.setState({ avatar });
}
Expand Down
14 changes: 8 additions & 6 deletions app/views/RoomsListView/ServerDropdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,13 @@ export default class ServerDropdown extends Component {
}
}

componentWillUnmount() {
if (this.newServerTimeout) {
clearTimeout(this.newServerTimeout);
this.newServerTimeout = false;
}
}

updateState = () => {
const { servers } = this;
this.setState({ servers });
Expand Down Expand Up @@ -137,12 +144,7 @@ export default class ServerDropdown extends Component {
const token = await AsyncStorage.getItem(`${ RocketChat.TOKEN_KEY }-${ server }`);
if (!token) {
appStart();
try {
this.sdk.disconnect();
} catch (error) {
console.warn(error);
}
setTimeout(() => {
this.newServerTimeout = setTimeout(() => {
EventEmitter.emit('NewServer', { server });
}, 1000);
} else {
Expand Down
17 changes: 16 additions & 1 deletion app/views/RoomsListView/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,22 @@ export default class RoomsListView extends LoggedView {
}
});
} else if (buttonId === 'settings') {
Navigation.toggleDrawer();
Navigation.showModal({
stack: {
children: [{
component: {
name: 'SidebarView',
options: {
topBar: {
title: {
text: I18n.t('Settings')
}
}
}
}
}]
}
});
} else if (buttonId === 'search') {
this.initSearchingAndroid();
} else if (buttonId === 'back') {
Expand Down
41 changes: 3 additions & 38 deletions app/views/SettingsView/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import PropTypes from 'prop-types';
import { View, ScrollView, BackHandler } from 'react-native';
import { View, ScrollView } from 'react-native';
import RNPickerSelect from 'react-native-picker-select';
import { connect } from 'react-redux';
import SafeAreaView from 'react-native-safe-area-view';
Expand All @@ -18,45 +18,28 @@ import Loading from '../../containers/Loading';
import { showErrorAlert, showToast } from '../../utils/info';
import log from '../../utils/log';
import { setUser as setUserAction } from '../../actions/login';
import { appStart as appStartAction } from '../../actions';
import Icons from '../../lib/Icons';

@connect(state => ({
userLanguage: state.login.user && state.login.user.language
}), dispatch => ({
setUser: params => dispatch(setUserAction(params)),
appStart: () => dispatch(appStartAction())
setUser: params => dispatch(setUserAction(params))
}))
/** @extends React.Component */
export default class SettingsView extends LoggedView {
static options() {
return {
topBar: {
leftButtons: [{
id: 'settings',
icon: Icons.getSource('settings'),
testID: 'rooms-list-view-sidebar'
}],
title: {
text: I18n.t('Settings')
}
},
sideMenu: {
left: {
enabled: true
},
right: {
enabled: true
}
}
};
}

static propTypes = {
componentId: PropTypes.string,
userLanguage: PropTypes.string,
setUser: PropTypes.func,
appStart: PropTypes.func
setUser: PropTypes.func
}

constructor(props) {
Expand Down Expand Up @@ -85,8 +68,6 @@ export default class SettingsView extends LoggedView {
}],
saving: false
};
Navigation.events().bindComponent(this);
BackHandler.addEventListener('hardwareBackPress', this.handleBackPress);
}

shouldComponentUpdate(nextProps, nextState) {
Expand All @@ -104,22 +85,6 @@ export default class SettingsView extends LoggedView {
return false;
}

componentWillUnmount() {
BackHandler.removeEventListener('hardwareBackPress', this.handleBackPress);
}

navigationButtonPressed = ({ buttonId }) => {
if (buttonId === 'settings') {
Navigation.toggleDrawer();
}
}

handleBackPress = () => {
const { appStart } = this.props;
appStart('background');
return false;
}

getLabel = (language) => {
const { languages } = this.state;
const l = languages.find(i => i.value === language);
Expand Down
Loading