No Description

Cita.js 4.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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. const [appointments, setAppointments] = useState([]);
  18. useEffect(() => {
  19. const fire = firebase.firestore()
  20. .collection('THREADS')
  21. .where("cita", "==", route.params.tag._id)
  22. .onSnapshot(querySnapshot => {
  23. const threads = querySnapshot.docs.map(documentSnapshot => {
  24. return{
  25. _id:documentSnapshot.id,
  26. name:'',
  27. ...documentSnapshot.data()
  28. };
  29. });
  30. setThreads(threads);
  31. console.log(threads);
  32. if(loading){
  33. setLoading(false);
  34. }
  35. });
  36. const cita = firebase.firestore().collection('APPOINTMENTS').where("citaID", "==", route.params.tag._id).onSnapshot(snapShot => {
  37. const appointments = snapShot.docs.map(docSnap => {
  38. return{
  39. _id:docSnap.id,
  40. new:'',
  41. Day:'',
  42. Month:'',
  43. Time:'',
  44. i_token:'',
  45. u_token:'',
  46. Pin: {},
  47. ...docSnap.data()
  48. };
  49. });
  50. setAppointments(appointments);
  51. console.log("appointment", appointments);
  52. });
  53. return () => {
  54. fire();
  55. cita();
  56. }
  57. }, []);
  58. const dimensions = Dimensions.get('window');
  59. const screenWidth = dimensions.width;
  60. const Pin = route.params.Pin;
  61. return (
  62. <ImageBackground style={styles.stdcontainer} source={require('../../assets/yellow-white.jpg')}>
  63. <FlatList style={{
  64. flex: 1,
  65. width: screenWidth,
  66. }}
  67. data={threads}
  68. keyExtractor = {item => item._id}
  69. ItemSeparatorComponent={() => <Divider />}
  70. renderItem = {({item}) => (
  71. <TouchableOpacity
  72. onPress={() => navigation.navigate('Room', {thread: item})}
  73. >
  74. <List.Item
  75. title={item.name}
  76. titleNumberOfLines={1}
  77. titleStyle={styles.listTitle}
  78. descriptionStyle={styles.listDescription}
  79. descriptionNumberOfLines={1}
  80. />
  81. </TouchableOpacity>
  82. )}
  83. />
  84. <FlatList style={{
  85. flex: 1,
  86. width: screenWidth,
  87. }}
  88. data={appointments}
  89. keyExtractor = {item => item._id}
  90. ItemSeparatorComponent={() => <Divider />}
  91. renderItem = {({item}) => (
  92. <TouchableOpacity
  93. onPress={async () => {
  94. console.log("cita")
  95. }}
  96. >
  97. <List.Item
  98. title='Mes:'
  99. description={item.Month}
  100. titleNumberOfLines={1}
  101. titleStyle={styles.listTitle}
  102. descriptionStyle={styles.listDescription}
  103. descriptionNumberOfLines={1}
  104. />
  105. <List.Item
  106. title='Día'
  107. description={item.Day}
  108. titleNumberOfLines={1}
  109. titleStyle={styles.listTitle}
  110. descriptionStyle={styles.listDescription}
  111. descriptionNumberOfLines={1}
  112. />
  113. <List.Item
  114. title='Hora:'
  115. description={item.Time}
  116. titleNumberOfLines={1}
  117. titleStyle={styles.listTitle}
  118. descriptionStyle={styles.listDescription}
  119. descriptionNumberOfLines={1}
  120. />
  121. </TouchableOpacity>
  122. )}
  123. />
  124. <Button
  125. title ='Ver mapa'
  126. onPress= {() => navigation.navigate('Map', {View_Only: true, Pin: Pin})}
  127. />
  128. <Button
  129. title ='Logout'
  130. onPress= {() => firebase.auth().signOut()}
  131. />
  132. </ImageBackground>
  133. );
  134. }
  135. const mapStateToProps = (store) => ({
  136. currentUser: store.userState.currentUser
  137. })
  138. const mapDispatchProps = (dispatch) => bindActionCreators({fetchUser}, dispatch);
  139. export default connect(mapStateToProps, mapDispatchProps)(Cita);