No Description

Home_page.js 2.9KB

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