No Description

Home_page.js 4.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  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. function handleButtonPress2() {
  57. firebase.firestore()
  58. .collection('Users')
  59. .doc(firebase.auth().currentUser.uid)
  60. .collection('THREADS')
  61. .add({
  62. name: 'citaFechaHora4'
  63. })
  64. //.then(() => {
  65. //navigation.navigate('allChats');
  66. //});
  67. firebase.firestore()
  68. .collection('Users')
  69. .doc('HGGAJlcIfwdpUoYfcBKLZFcDude2')
  70. .collection('THREADS')
  71. .add({
  72. name: 'citaFechaHora4'
  73. })
  74. /*firebase.database().ref('Users/' + 'HGGAJlcIfwdpUoYfcBKLZFcDude2' + '/THREADS/')
  75. .push()
  76. .set({
  77. name: 'citaFechaHora3'
  78. })*/
  79. }
  80. return (
  81. <ImageBackground style={styles.stdcontainer} source={require('../../assets/yellow-white.jpg')}>
  82. <FlatList
  83. data={threads}
  84. keyExtractor = {item => item._id}
  85. ItemSeparatorComponent={() => <Divider />}
  86. renderItem = {({item}) => (
  87. <TouchableOpacity
  88. onPress={() => navigation.navigate('Room', {thread: item})}
  89. >
  90. <List.Item
  91. title={item.name}
  92. description='Item description'
  93. titleNumberOfLines={1}
  94. titleStyle={styles.listTitle}
  95. descriptionStyle={styles.listDescription}
  96. descriptionNumberOfLines={1}
  97. />
  98. </TouchableOpacity>
  99. )}
  100. />
  101. <TextInput
  102. labelName='Room Name'
  103. placeholder="new chat room"
  104. onChangeText={(text) => setRoomName(text)}
  105. clearButtonMode='while-editing'
  106. />
  107. <Button
  108. title='CrearChat'
  109. onPress={() => handleButtonPress2()}
  110. />
  111. <Button
  112. title='Provisional'
  113. onPress={() => handleButtonPress()}
  114. />
  115. <Button
  116. title ='Hacer Busqueda'
  117. onPress= {() => navigation.navigate('Room')}
  118. />
  119. </ImageBackground>
  120. );
  121. }
  122. const mapStateToProps = (store) => ({
  123. currentUser: store.userState.currentUser
  124. })
  125. const mapDispatchProps = (dispatch) => bindActionCreators({fetchUser}, dispatch);
  126. export default connect(mapStateToProps, mapDispatchProps)(Home_page);