No Description

Home_page.js 2.5KB

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