No Description

Home_page.js 3.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. import React, {useState, useEffect} from 'react'
  2. import { Button, Text, View, StyleSheet} from 'react-native'
  3. import {FlatList, ListViewBase } from 'react-native'
  4. import {TouchableOpacity} from 'react-native-gesture-handler'
  5. import {List, Divider} from 'react-native-paper'
  6. import Loading from './Loading'
  7. import firebase from 'firebase';
  8. import { styles } from "../../config/styles";
  9. import { TextInput, TouchableWithoutFeedback, Keyboard, ImageBackground} from "react-native";
  10. import { connect } from 'react-redux'
  11. import { bindActionCreators } from 'redux'
  12. import { fetchUser } from '../../redux/actions/index'
  13. export function Home_page({navigation}) {
  14. <<<<<<< HEAD
  15. return (
  16. <TouchableWithoutFeedback style={styles.stdcontainer} onPress={Keyboard.dismiss} accessible={false}>
  17. <ImageBackground style={styles.stdcontainer} source={require('../../assets/yellow-white.jpg')}>
  18. <CustomButton marginTop={25} title="Calendar" onPress={() => navigation.navigate('Calendar')}/>
  19. </ImageBackground>
  20. </TouchableWithoutFeedback>
  21. );
  22. }
  23. =======
  24. const [threads, setThreads] = useState([]);
  25. const [loading, setLoading] = useState(true);
  26. const [roomName, setRoomName] = useState('');
  27. useEffect(() => {
  28. const fire = firebase.firestore()
  29. .collection('THREADS')
  30. .where("members", "array-contains", firebase.auth().currentUser.uid)
  31. .onSnapshot(querySnapshot => {
  32. const threads = querySnapshot.docs.map(documentSnapshot => {
  33. return{
  34. _id:documentSnapshot.id,
  35. name:'',
  36. ...documentSnapshot.data()
  37. };
  38. });
  39. setThreads(threads);
  40. if(loading){
  41. setLoading(false);
  42. }
  43. });
  44. return () => fire();
  45. }, []);
  46. if (loading) {
  47. return <Loading />;
  48. }
  49. function handleButtonPress() {
  50. firebase.firestore()
  51. .collection('THREADS')
  52. .add({
  53. name: 'PedroFecha',
  54. members: [
  55. firebase.auth().currentUser.uid,
  56. '02yOZHxFcGUX4MNwjeEbAlCShdu1'
  57. ]
  58. })
  59. //.then(() => {
  60. //navigation.navigate('allChats');
  61. //});
  62. }
  63. return (
  64. <ImageBackground style={styles.stdcontainer} source={require('../../assets/yellow-white.jpg')}>
  65. <FlatList
  66. data={threads}
  67. keyExtractor = {item => item._id}
  68. ItemSeparatorComponent={() => <Divider />}
  69. renderItem = {({item}) => (
  70. <TouchableOpacity
  71. onPress={() => navigation.navigate('Room', {thread: item})}
  72. >
  73. <List.Item
  74. title={item.name}
  75. titleNumberOfLines={1}
  76. titleStyle={styles.listTitle}
  77. descriptionStyle={styles.listDescription}
  78. descriptionNumberOfLines={1}
  79. />
  80. </TouchableOpacity>
  81. )}
  82. />
  83. <Button
  84. title='Calendario'
  85. onPress={() => navigation.navigate('Calendar')}
  86. />
  87. <Button
  88. title='CrearChat'
  89. onPress={() => handleButtonPress()}
  90. />
  91. <Button
  92. title ='Hacer Busqueda'
  93. onPress= {() => navigation.navigate('Busqueda')}
  94. />
  95. </ImageBackground>
  96. );
  97. }
  98. >>>>>>> devErnesto
  99. const mapStateToProps = (store) => ({
  100. currentUser: store.userState.currentUser
  101. })
  102. const mapDispatchProps = (dispatch) => bindActionCreators({fetchUser}, dispatch);
  103. <<<<<<< HEAD
  104. export default connect(mapStateToProps, mapDispatchProps)(Home_page);
  105. const mapStateToProps = (store) => ({
  106. currentUser: store.userState.currentUser
  107. })
  108. const mapDispatchProps = (dispatch) => bindActionCreators({fetchUser}, dispatch);
  109. export default connect(mapStateToProps, mapDispatchProps)(Home_page);
  110. =======
  111. export default connect(mapStateToProps, mapDispatchProps)(Home_page);
  112. >>>>>>> devErnesto