No Description

HomeScreen.js 3.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. import React, { Component } from 'react';
  2. import { connect } from 'react-redux';
  3. import { bindActionCreators } from 'redux';
  4. import firebase from 'firebase';
  5. import { Text, View, ImageBackground } from 'react-native';
  6. import MaterialIcons from 'react-native-vector-icons/MaterialIcons';
  7. import { fetchUser } from '../redux/actions/index'
  8. import Loading from '../components/Loading'
  9. import { styles } from '../config/styles'
  10. export class HomeScreen extends Component {
  11. constructor(props){
  12. super(props);
  13. this.state = {
  14. interpreter: false,
  15. };
  16. this.onLogout = this.onLogout.bind(this)
  17. };
  18. componentDidMount(){
  19. this.props.fetchUser();
  20. firebase.firestore()
  21. .collection("Interpreters")
  22. .doc(firebase.auth().currentUser.uid)
  23. .get()
  24. .then((snapshot) => {
  25. if(snapshot.exists){
  26. this.setState({interpreter: true})
  27. }
  28. })
  29. }
  30. onLogout(){
  31. firebase.auth().signOut();
  32. }
  33. render() {
  34. const { currentUser } = this.props;
  35. if(currentUser == undefined){
  36. return <Loading/>
  37. }
  38. if(this.state.interpreter){
  39. return(
  40. <View style={styles.regcontainer}>
  41. <ImageBackground style={styles.home} source={require("../assets/yellow-white.jpg")}>
  42. <View style={styles.homeTopView}>
  43. <MaterialIcons name='logout' size={30} color='dodgerblue' onPress={() => this.onLogout()}/>
  44. <MaterialIcons name='event' size={30} color='dodgerblue' style={styles.homeIcon} onPress={() => this.props.navigation.navigate('Availability')}/>
  45. <MaterialIcons name='mail' size={30} color='dodgerblue' onPress={() => this.props.navigation.navigate('Mail')}/>
  46. </View>
  47. </ImageBackground>
  48. <View style={styles.regcontainer}></View>
  49. </View>
  50. );
  51. }
  52. else{
  53. return(
  54. <View style={styles.regcontainer}><Text>You are a user</Text></View>
  55. );
  56. }
  57. }
  58. }
  59. const mapStateProps = (store) => ({currentUser: store.userState.currentUser})
  60. const mapDispatchProps = (dispatch) => bindActionCreators({fetchUser}, dispatch)
  61. export default connect(mapStateProps, mapDispatchProps)(HomeScreen)
  62. /*export default function HomeScreen({navigation}) {
  63. const [threads, setThreads] = useState([]);
  64. const [loading, setLoading] = useState(true);
  65. useEffect(() => {
  66. const fire = firebase.firestore()
  67. .collection('THREADS')
  68. .onSnapshot(querySnapshot => {
  69. const threads = querySnapshot.docs.map(documentSnapshot => {
  70. return{
  71. _id:documentSnapshot.id,
  72. name:'',
  73. ...documentSnapshot.data()
  74. };
  75. });
  76. setThreads(threads);
  77. if(loading){
  78. setLoading(false);
  79. }
  80. });
  81. return () => fire();
  82. }, []);
  83. if (loading) {
  84. return <Loading />;
  85. }
  86. return (
  87. <View style={styles.container}>
  88. <FlatList
  89. data={threads}
  90. keyExtractor = {item => item._id}
  91. ItemSeparatorComponent={() => <Divider />}
  92. renderItem = {({item}) => (
  93. <TouchableOpacity
  94. onPress={() => navigation.navigate('Room', {thread: item})}
  95. >
  96. <List.Item
  97. title={item.name}
  98. description='Item description'
  99. titleNumberOfLines={1}
  100. titleStyle={styles.listTitle}
  101. descriptionStyle={styles.listDescription}
  102. descriptionNumberOfLines={1}
  103. />
  104. </TouchableOpacity>
  105. )}
  106. />
  107. <Button
  108. title='Add Room'
  109. onPress={() => navigation.navigate('Add')}
  110. />
  111. <Button
  112. title ='Room'
  113. onPress= {() => navigation.navigate('Room')}
  114. />
  115. </View>
  116. );
  117. }
  118. */