fix warnings and better flow servers rooms room
This commit is contained in:
parent
138546e4c9
commit
6f16f66dc8
|
@ -40,7 +40,7 @@ const RocketChat = {
|
|||
});
|
||||
},
|
||||
get currentServer() {
|
||||
const current = realm.objects('servers').filtered('current = true')[0];
|
||||
const current = realm.objects('servers').filtered('current = true').slice(0, 1)[0];
|
||||
return current && current.id;
|
||||
},
|
||||
|
||||
|
@ -327,6 +327,8 @@ Meteor.Accounts.onLogin(() => {
|
|||
subscription._updatedAt = rooms[index]._updatedAt;
|
||||
return subscription;
|
||||
});
|
||||
Meteor.subscribe('stream-notify-user', `${ Meteor.userId() }/subscriptions-changed`, false);
|
||||
Meteor.subscribe('stream-notify-user', `${ Meteor.userId() }/rooms-changed`, false);
|
||||
realm.write(() => {
|
||||
data.forEach((subscription) => {
|
||||
// const subscription = {
|
||||
|
@ -341,8 +343,6 @@ Meteor.Accounts.onLogin(() => {
|
|||
});
|
||||
});
|
||||
}).then(() => {
|
||||
Meteor.subscribe('stream-notify-user', `${ Meteor.userId() }/subscriptions-changed`, false);
|
||||
Meteor.subscribe('stream-notify-user', `${ Meteor.userId() }/rooms-changed`, false);
|
||||
console.log('subscriptions done.');
|
||||
});
|
||||
});
|
||||
|
|
|
@ -4,23 +4,31 @@ import { StackNavigator } from 'react-navigation';
|
|||
import LoginView from './views/login';
|
||||
import NewServerView from './views/serverNew';
|
||||
import ListServerView from './views/serverList';
|
||||
import Main from './views/Main';
|
||||
import RoomsListView from './views/roomsList';
|
||||
import RoomView from './views/room';
|
||||
import CreateChannel from './views/CreateChannel';
|
||||
|
||||
|
||||
const MainCardNavigator = StackNavigator({
|
||||
Main: {
|
||||
screen: Main
|
||||
},
|
||||
Rooms: {
|
||||
screen: RoomsListView
|
||||
},
|
||||
Room: {
|
||||
screen: RoomView
|
||||
// navigationOptions: {
|
||||
// header: null
|
||||
// }
|
||||
},
|
||||
ListServerModal: {
|
||||
screen: ListServerView,
|
||||
navigationOptions: ({ navigation }) =>
|
||||
(Platform.OS === 'ios' ? ({
|
||||
headerLeft: Platform.OS === 'ios' && (<Button title='Close' onPress={() => navigation.dispatch({ type: 'Navigation/BACK' })} />)
|
||||
}) : {})
|
||||
}
|
||||
}, {
|
||||
initialRouteName: 'Rooms',
|
||||
initialRouteName: 'Main',
|
||||
cardStyle: {
|
||||
backgroundColor: '#fff'
|
||||
}
|
||||
|
@ -39,12 +47,6 @@ export default new StackNavigator({
|
|||
headerLeft: Platform.OS === 'ios' && (<Button title='Cancel' onPress={() => navigation.dispatch({ type: 'Navigation/BACK' })} />)
|
||||
})
|
||||
},
|
||||
ListServerModal: {
|
||||
screen: ListServerView,
|
||||
navigationOptions: ({ navigation }) => ({
|
||||
headerLeft: Platform.OS === 'ios' && (<Button title='Close' onPress={() => navigation.dispatch({ type: 'Navigation/BACK' })} />)
|
||||
})
|
||||
},
|
||||
NewServerModal: {
|
||||
screen: NewServerView,
|
||||
navigationOptions: ({ navigation }) => ({
|
||||
|
|
|
@ -0,0 +1,43 @@
|
|||
import { NavigationActions } from 'react-navigation';
|
||||
|
||||
import PropTypes from 'prop-types';
|
||||
import React from 'react';
|
||||
import realm from '../lib/realm';
|
||||
import RocketChat from '../lib/rocketchat';
|
||||
|
||||
|
||||
class App extends React.Component {
|
||||
static propTypes = {
|
||||
navigation: PropTypes.object.isRequired
|
||||
}
|
||||
constructor(...args) {
|
||||
super(...args);
|
||||
const navigation = this.props.navigation;
|
||||
realm.objects('servers').addListener(() => {
|
||||
if (RocketChat.currentServer) {
|
||||
const resetAction = NavigationActions.reset({
|
||||
index: 0,
|
||||
actions: [
|
||||
NavigationActions.navigate({ routeName: 'Rooms' })
|
||||
]
|
||||
});
|
||||
navigation.dispatch(resetAction);
|
||||
}
|
||||
});
|
||||
if (RocketChat.currentServer) {
|
||||
RocketChat.connect();
|
||||
} else {
|
||||
const resetAction = NavigationActions.reset({
|
||||
index: 0,
|
||||
actions: [
|
||||
NavigationActions.navigate({ routeName: 'ListServerModal' })
|
||||
]
|
||||
});
|
||||
navigation.dispatch(resetAction);
|
||||
}
|
||||
}
|
||||
render() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
export default App;
|
|
@ -178,6 +178,7 @@ export default class RoomView extends React.Component {
|
|||
<View style={styles.container}>
|
||||
{this.renderBanner()}
|
||||
<ListView
|
||||
enableEmptySections
|
||||
style={styles.list}
|
||||
onEndReachedThreshold={0.1}
|
||||
ListFooterComponent={this.renderHeader()}
|
||||
|
|
|
@ -113,7 +113,7 @@ export default class RoomsListView extends React.Component {
|
|||
<Text style={{ textAlign, fontSize: 10 }}>{server}</Text>
|
||||
</View>,
|
||||
title: 'Channels',
|
||||
[position]: <Button title='Servers' onPress={() => props.navigation.navigate('ListServerModal', { onSelect: setInitialData })} />
|
||||
[position]: <Button title='Servers' onPress={() => props.navigation.navigate('ListServerModal')} />
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -126,6 +126,7 @@ export default class RoomsListView extends React.Component {
|
|||
searchDataSource: [],
|
||||
searchText: ''
|
||||
};
|
||||
this.data.addListener(this.updateState);
|
||||
}
|
||||
|
||||
componentWillMount() {
|
||||
|
@ -133,9 +134,8 @@ export default class RoomsListView extends React.Component {
|
|||
|
||||
navigation = this.props.navigation;
|
||||
|
||||
// this.setInitialData();
|
||||
if (RocketChat.currentServer) {
|
||||
this.setInitialData();
|
||||
|
||||
RocketChat.connect();
|
||||
} else {
|
||||
navigation.navigate('ListServerModal', {
|
||||
|
@ -196,7 +196,7 @@ export default class RoomsListView extends React.Component {
|
|||
if (this.data) {
|
||||
this.data.removeListener(this.updateState);
|
||||
}
|
||||
|
||||
this.data = realm.objects('subscriptions').filtered('_server.id = $0', RocketChat.currentServer).sorted('_updatedAt', true);
|
||||
this.data.addListener(this.updateState);
|
||||
|
||||
this.updateState();
|
||||
|
@ -206,7 +206,7 @@ export default class RoomsListView extends React.Component {
|
|||
|
||||
updateState = debounce(() => {
|
||||
this.setState({
|
||||
dataSource: ds.cloneWithRows(this.data)
|
||||
dataSource: ds.cloneWithRows(this.data.filtered('_server.id = $0', RocketChat.currentServer))
|
||||
});
|
||||
}, 500);
|
||||
|
||||
|
|
Loading…
Reference in New Issue