import React from 'react'; import PropTypes from 'prop-types'; import { Text, View, FlatList, StyleSheet } from 'react-native'; import Meteor from 'react-native-meteor'; import realm from '../lib/realm'; import RocketChat, { connect } from '../lib/meteor'; import RoomItem from '../components/RoomItem'; const styles = StyleSheet.create({ container: { flex: 1, alignItems: 'stretch', justifyContent: 'center' }, separator: { height: 1, backgroundColor: '#CED0CE' }, list: { width: '100%' }, emptyView: { flexGrow: 1, alignItems: 'stretch', justifyContent: 'center' }, emptyText: { textAlign: 'center', fontSize: 18, color: '#ccc' }, bannerContainer: { backgroundColor: '#ddd' }, bannerText: { textAlign: 'center', margin: 5 } }); let navigation; Meteor.getData().on('loggingIn', () => { setTimeout(() => { if (Meteor._isLoggingIn === false && Meteor.userId() == null) { console.log('loggingIn', Meteor.userId()); navigation.navigate('Login'); } }, 100); }); Meteor.Accounts.onLogin(() => { console.log('onLogin'); }); export default class RoomsListView extends React.Component { static propTypes = { navigation: PropTypes.object.isRequired } static navigationOptions = () => ({ title: 'Rooms' }); constructor(props) { super(props); this.state = this.getState(); } componentWillMount() { realm.addListener('change', this.updateState); navigation = this.props.navigation; if (RocketChat.currentServer) { connect(() => { // navigation.navigate('Login'); }); } else { navigation.navigate('ListServerModal'); } } componentWillUnmount() { realm.removeListener('change', this.updateState); } getState = () => ({ dataSource: realm.objects('subscriptions').filtered('_server.id = $0', RocketChat.currentServer).sorted('name').slice() .sort((a, b) => { if (a.unread < b.unread) { return 1; } if (a.unread > b.unread) { return -1; } return 0; }) }) updateState = () => { this.setState(this.getState()); } _onPressItem = (id) => { const { navigate } = this.props.navigation; navigate('Room', { sid: id }); } renderBanner = () => { const status = Meteor.getData() && Meteor.getData().ddp && Meteor.getData().ddp.status; if (status === 'disconnected') { return ( Connecting... ); } if (status === 'connected' && Meteor._isLoggingIn) { return ( Authenticating... ) } } renderItem = ({ item }) => ( ); renderSeparator = () => ( ); renderList = () => { if (this.state.dataSource.length) { return ( item._id} ItemSeparatorComponent={this.renderSeparator} /> ); } return ( No rooms ); } render() { return ( {this.renderBanner()} {this.renderList()} ); } }