No Description

Cita.js 2.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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. const Pin = route.params.Pin;
  42. return (
  43. <ImageBackground style={styles.stdcontainer} source={require('../../assets/yellow-white.jpg')}>
  44. <FlatList style={{
  45. flex: 1,
  46. width: screenWidth,
  47. }}
  48. data={threads}
  49. keyExtractor = {item => item._id}
  50. ItemSeparatorComponent={() => <Divider />}
  51. renderItem = {({item}) => (
  52. <TouchableOpacity
  53. onPress={() => navigation.navigate('Room', {thread: item})}
  54. >
  55. <List.Item
  56. title={item.name}
  57. titleNumberOfLines={1}
  58. titleStyle={styles.listTitle}
  59. descriptionStyle={styles.listDescription}
  60. descriptionNumberOfLines={1}
  61. />
  62. </TouchableOpacity>
  63. )}
  64. />
  65. <Button
  66. title ='Ver mapa'
  67. onPress= {() => navigation.navigate('Map', {View_Only: true, Pin: Pin})}
  68. />
  69. <Button
  70. title ='Logout'
  71. onPress= {() => firebase.auth().signOut()}
  72. />
  73. </ImageBackground>
  74. );
  75. }
  76. const mapStateToProps = (store) => ({
  77. currentUser: store.userState.currentUser
  78. })
  79. const mapDispatchProps = (dispatch) => bindActionCreators({fetchUser}, dispatch);
  80. export default connect(mapStateToProps, mapDispatchProps)(Cita);