No Description

Home_page.js 3.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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. //const [roomName, setRoomName] = useState('');
  19. useEffect(() => {
  20. const fire = firebase.firestore()
  21. .collection('Users')
  22. .doc(firebase.auth().currentUser.uid)
  23. .collection('THREADS')
  24. .onSnapshot(querySnapshot => {
  25. const threads = querySnapshot.docs.map(documentSnapshot => {
  26. return{
  27. _id:documentSnapshot.id,
  28. name:'',
  29. ...documentSnapshot.data()
  30. };
  31. });
  32. setThreads(threads);
  33. if(loading){
  34. setLoading(false);
  35. }
  36. });
  37. return () => fire();
  38. }, []);
  39. if (loading) {
  40. return <Loading />;
  41. }
  42. function handleButtonPress() {
  43. if (roomName.length > 0) {
  44. firebase.firestore()
  45. .collection('Users')
  46. .doc(firebase.auth().currentUser.uid)
  47. .collection('THREADS')
  48. .add({
  49. name: roomName
  50. })
  51. //.then(() => {
  52. //navigation.navigate('allChats');
  53. //});
  54. }
  55. }
  56. return (
  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. <TextInput
  78. labelName='Room Name'
  79. placeholder="new chat room"
  80. onChangeText={(text) => setRoomName(text)}
  81. clearButtonMode='while-editing'
  82. />
  83. <Button
  84. title='Provisional'
  85. onPress={() => handleButtonPress()}
  86. />
  87. <Button
  88. title ='Hacer Busqueda'
  89. onPress= {() => navigation.navigate('Room')}
  90. />
  91. </ImageBackground>
  92. );
  93. }
  94. const mapStateToProps = (store) => ({
  95. currentUser: store.userState.currentUser
  96. })
  97. const mapDispatchProps = (dispatch) => bindActionCreators({fetchUser}, dispatch);
  98. export default connect(mapStateToProps, mapDispatchProps)(Home_page);