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() {
|
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;
|
return current && current.id;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -327,6 +327,8 @@ Meteor.Accounts.onLogin(() => {
|
||||||
subscription._updatedAt = rooms[index]._updatedAt;
|
subscription._updatedAt = rooms[index]._updatedAt;
|
||||||
return subscription;
|
return subscription;
|
||||||
});
|
});
|
||||||
|
Meteor.subscribe('stream-notify-user', `${ Meteor.userId() }/subscriptions-changed`, false);
|
||||||
|
Meteor.subscribe('stream-notify-user', `${ Meteor.userId() }/rooms-changed`, false);
|
||||||
realm.write(() => {
|
realm.write(() => {
|
||||||
data.forEach((subscription) => {
|
data.forEach((subscription) => {
|
||||||
// const subscription = {
|
// const subscription = {
|
||||||
|
@ -341,8 +343,6 @@ Meteor.Accounts.onLogin(() => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}).then(() => {
|
}).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.');
|
console.log('subscriptions done.');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -4,23 +4,31 @@ import { StackNavigator } from 'react-navigation';
|
||||||
import LoginView from './views/login';
|
import LoginView from './views/login';
|
||||||
import NewServerView from './views/serverNew';
|
import NewServerView from './views/serverNew';
|
||||||
import ListServerView from './views/serverList';
|
import ListServerView from './views/serverList';
|
||||||
|
import Main from './views/Main';
|
||||||
import RoomsListView from './views/roomsList';
|
import RoomsListView from './views/roomsList';
|
||||||
import RoomView from './views/room';
|
import RoomView from './views/room';
|
||||||
import CreateChannel from './views/CreateChannel';
|
import CreateChannel from './views/CreateChannel';
|
||||||
|
|
||||||
|
|
||||||
const MainCardNavigator = StackNavigator({
|
const MainCardNavigator = StackNavigator({
|
||||||
|
Main: {
|
||||||
|
screen: Main
|
||||||
|
},
|
||||||
Rooms: {
|
Rooms: {
|
||||||
screen: RoomsListView
|
screen: RoomsListView
|
||||||
},
|
},
|
||||||
Room: {
|
Room: {
|
||||||
screen: RoomView
|
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: {
|
cardStyle: {
|
||||||
backgroundColor: '#fff'
|
backgroundColor: '#fff'
|
||||||
}
|
}
|
||||||
|
@ -39,12 +47,6 @@ export default new StackNavigator({
|
||||||
headerLeft: Platform.OS === 'ios' && (<Button title='Cancel' onPress={() => navigation.dispatch({ type: 'Navigation/BACK' })} />)
|
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: {
|
NewServerModal: {
|
||||||
screen: NewServerView,
|
screen: NewServerView,
|
||||||
navigationOptions: ({ navigation }) => ({
|
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}>
|
<View style={styles.container}>
|
||||||
{this.renderBanner()}
|
{this.renderBanner()}
|
||||||
<ListView
|
<ListView
|
||||||
|
enableEmptySections
|
||||||
style={styles.list}
|
style={styles.list}
|
||||||
onEndReachedThreshold={0.1}
|
onEndReachedThreshold={0.1}
|
||||||
ListFooterComponent={this.renderHeader()}
|
ListFooterComponent={this.renderHeader()}
|
||||||
|
|
|
@ -113,7 +113,7 @@ export default class RoomsListView extends React.Component {
|
||||||
<Text style={{ textAlign, fontSize: 10 }}>{server}</Text>
|
<Text style={{ textAlign, fontSize: 10 }}>{server}</Text>
|
||||||
</View>,
|
</View>,
|
||||||
title: 'Channels',
|
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: [],
|
searchDataSource: [],
|
||||||
searchText: ''
|
searchText: ''
|
||||||
};
|
};
|
||||||
|
this.data.addListener(this.updateState);
|
||||||
}
|
}
|
||||||
|
|
||||||
componentWillMount() {
|
componentWillMount() {
|
||||||
|
@ -133,9 +134,8 @@ export default class RoomsListView extends React.Component {
|
||||||
|
|
||||||
navigation = this.props.navigation;
|
navigation = this.props.navigation;
|
||||||
|
|
||||||
|
// this.setInitialData();
|
||||||
if (RocketChat.currentServer) {
|
if (RocketChat.currentServer) {
|
||||||
this.setInitialData();
|
|
||||||
|
|
||||||
RocketChat.connect();
|
RocketChat.connect();
|
||||||
} else {
|
} else {
|
||||||
navigation.navigate('ListServerModal', {
|
navigation.navigate('ListServerModal', {
|
||||||
|
@ -196,7 +196,7 @@ export default class RoomsListView extends React.Component {
|
||||||
if (this.data) {
|
if (this.data) {
|
||||||
this.data.removeListener(this.updateState);
|
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.data.addListener(this.updateState);
|
||||||
|
|
||||||
this.updateState();
|
this.updateState();
|
||||||
|
@ -206,7 +206,7 @@ export default class RoomsListView extends React.Component {
|
||||||
|
|
||||||
updateState = debounce(() => {
|
updateState = debounce(() => {
|
||||||
this.setState({
|
this.setState({
|
||||||
dataSource: ds.cloneWithRows(this.data)
|
dataSource: ds.cloneWithRows(this.data.filtered('_server.id = $0', RocketChat.currentServer))
|
||||||
});
|
});
|
||||||
}, 500);
|
}, 500);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue