No Description

Cita.js 2.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. import React, {useState, useEffect, useRef} from 'react'
  2. import { Button, Text, View, StyleSheet, Dimensions} 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 Cita({route, navigation}) {
  14. const [threads, setThreads] = useState([]);
  15. const [loading, setLoading] = useState(true);
  16. console.log("ID", route.params);
  17. useEffect(() => {
  18. const fire = firebase.firestore()
  19. .collection('THREADS')
  20. .where("cita", "==", route.params.tag._id)
  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. console.log(threads);
  31. if(loading){
  32. setLoading(false);
  33. }
  34. });
  35. return () => {
  36. fire();
  37. }
  38. }, []);
  39. const dimensions = Dimensions.get('window');
  40. const screenWidth = dimensions.width;
  41. return (
  42. <ImageBackground style={styles.stdcontainer} source={require('../../assets/yellow-white.jpg')}>
  43. <FlatList style={{
  44. flex: 1,
  45. width: screenWidth,
  46. }}
  47. data={threads}
  48. keyExtractor = {item => item._id}
  49. ItemSeparatorComponent={() => <Divider />}
  50. renderItem = {({item}) => (
  51. <TouchableOpacity
  52. onPress={() => navigation.navigate('Room', {thread: item})}
  53. >
  54. <List.Item
  55. title={item.name}
  56. titleNumberOfLines={1}
  57. titleStyle={styles.listTitle}
  58. descriptionStyle={styles.listDescription}
  59. descriptionNumberOfLines={1}
  60. />
  61. </TouchableOpacity>
  62. )}
  63. />
  64. <Button
  65. title ='Ver mapa'
  66. onPress= {() => navigation.navigate('Map')}
  67. />
  68. <Button
  69. title ='Logout'
  70. onPress= {() => firebase.auth().signOut()}
  71. />
  72. </ImageBackground>
  73. );
  74. }
  75. const mapStateToProps = (store) => ({
  76. currentUser: store.userState.currentUser
  77. })
  78. const mapDispatchProps = (dispatch) => bindActionCreators({fetchUser}, dispatch);
  79. export default connect(mapStateToProps, mapDispatchProps)(Cita);