No Description

Home_page.js 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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. const [threads, setThreads] = useState([]);
  15. const [loading, setLoading] = useState(true);
  16. //const [roomName, setRoomName] = useState('');
  17. //const navigation = useNavigation();
  18. useEffect(() => {
  19. const fire = firebase.firestore()
  20. .collection('Users')
  21. .doc(firebase.auth().currentUser.uid)
  22. .collection('THREADS')
  23. .onSnapshot(querySnapshot => {
  24. const threads = querySnapshot.docs.map(documentSnapshot => {
  25. return{
  26. _id:documentSnapshot.id,
  27. name:'',
  28. ...documentSnapshot.data()
  29. };
  30. });
  31. setThreads(threads);
  32. if(loading){
  33. setLoading(false);
  34. }
  35. });
  36. return () => fire();
  37. }, []);
  38. if (loading) {
  39. return <Loading />;
  40. }
  41. /*function handleButtonPress() {
  42. if (roomName.length > 0) {
  43. firebase.firestore()
  44. .collection('Users')
  45. .doc(firebase.auth().currentUser.uid)
  46. .collection('THREADS')
  47. .add({
  48. name: roomName
  49. })
  50. .then(() => {
  51. navigation.navigate('allChats');
  52. });
  53. }
  54. }*/
  55. return (
  56. <View>
  57. <ImageBackground style={styles.stdcontainer} source={require('../../assets/yellow-white.jpg')}>
  58. <FlatList
  59. data={threads}
  60. keyExtractor = {item => item._id}
  61. ItemSeparatorComponent={() => <Divider />}
  62. renderItem = {({item}) => (
  63. <TouchableOpacity
  64. onPress={() => navigation.navigate('Room', {thread: item})}
  65. >
  66. <List.Item
  67. title={item.name}
  68. description='Item description'
  69. titleNumberOfLines={1}
  70. titleStyle={styles.listTitle}
  71. descriptionStyle={styles.listDescription}
  72. descriptionNumberOfLines={1}
  73. />
  74. </TouchableOpacity>
  75. )}
  76. />
  77. <Button
  78. title='Ver mensajes'
  79. onPress={() => navigation.navigate('Add')}
  80. />
  81. <Button
  82. title ='Hacer Busqueda'
  83. onPress= {() => navigation.navigate('Room')}
  84. />
  85. </ImageBackground>
  86. </View>
  87. );
  88. }
  89. const mapStateToProps = (store) => ({
  90. currentUser: store.userState.currentUser
  91. })
  92. const mapDispatchProps = (dispatch) => bindActionCreators({fetchUser}, dispatch);
  93. export default connect(mapStateToProps, mapDispatchProps)(Home_page);