import React, { Component } from 'react'; import { connect } from 'react-redux'; import { bindActionCreators } from 'redux'; import firebase from 'firebase'; import { Text, View, ImageBackground } from 'react-native'; import MaterialIcons from 'react-native-vector-icons/MaterialIcons'; import { fetchUser } from '../redux/actions/index' //import Loading from '../components/Loading' import Loading from './main/Loading' import { styles } from '../config/styles' export class HomeScreen extends Component { constructor(props){ super(props); this.state = { interpreter: false, }; this.onLogout = this.onLogout.bind(this) }; componentDidMount(){ this.props.fetchUser(); firebase.firestore() .collection("Interpreters") .doc(firebase.auth().currentUser.uid) .get() .then((snapshot) => { if(snapshot.exists){ this.setState({interpreter: true}) } }) } onLogout(){ firebase.auth().signOut(); } render() { const { currentUser } = this.props; if(currentUser == undefined){ return } if(this.state.interpreter){ return( this.onLogout()}/> this.props.navigation.navigate('Availability')}/> this.props.navigation.navigate('Mail')}/> ); } else{ return( You are a user ); } } } const mapStateProps = (store) => ({currentUser: store.userState.currentUser}) const mapDispatchProps = (dispatch) => bindActionCreators({fetchUser}, dispatch) export default connect(mapStateProps, mapDispatchProps)(HomeScreen) /*export default function HomeScreen({navigation}) { const [threads, setThreads] = useState([]); const [loading, setLoading] = useState(true); useEffect(() => { const fire = firebase.firestore() .collection('THREADS') .onSnapshot(querySnapshot => { const threads = querySnapshot.docs.map(documentSnapshot => { return{ _id:documentSnapshot.id, name:'', ...documentSnapshot.data() }; }); setThreads(threads); if(loading){ setLoading(false); } }); return () => fire(); }, []); if (loading) { return ; } return ( item._id} ItemSeparatorComponent={() => } renderItem = {({item}) => ( navigation.navigate('Room', {thread: item})} > )} />