説明なし

HomeScreen.js 3.7KB

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