Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2019
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.57 KB | None | 0 0
  1. import React from 'react';
  2. import { Button, Text, View, SafeAreaView, Linking, ImageBackground, Alert } from 'react-native';
  3. import { Ionicons } from '@expo/vector-icons'; // 6.2.2
  4. import { StackNavigator, TabNavigator, TabBarBottom } from 'react-navigation';
  5. import Touchable from 'react-native-platform-touchable';
  6. import firebase from 'firebase';
  7.  
  8.  
  9. import styles from '.././styles/styles';
  10.  
  11. /* Class is used for Maps Details screen */
  12.  
  13. export default class DetailsScreen extends React.Component {
  14.  
  15. static navigationOptions = ({ navigation }) => {
  16. const { params } = navigation.state;
  17.  
  18. return {
  19. tabBarLabel: '',
  20. headerTitle: <Text style={styles.headertitle}>{params ? params.title : 'null'}</Text>,
  21. headerStyle: {
  22. elevation: 0.4,
  23. shadowOpacity: 0.4
  24. }
  25. };
  26. };
  27.  
  28. //params ? params.title.length <= 30 ? params.title : params.title.substring(0, 31)+ "..."
  29.  
  30. /*static navigationOptions = {
  31. tabBarLabel: '',
  32. headerTitle: <Text style={ styles.headertitle }>Details</Text>,
  33. headerStyle: {
  34. elevation: 0.4,
  35. shadowOpacity: 0.4
  36. }
  37. };*/
  38.  
  39. render() {
  40. const { params } = this.props.navigation.state;
  41. const title = params ? params.title : null;
  42. const location = params ? params.location : null;
  43. const description = params ? params.description : null;
  44. const image = params ? params.image : null;
  45.  
  46. return (
  47. <View style={{ backgroundColor: 'white', paddingTop: 20, flex: 1, flexDirection: 'column', justifyContent: 'flex-start' }}>
  48. <Text style={styles.cardtitleBlack}>{location}</Text>
  49. <ImageBackground
  50. style={{ flex: 1, margin: 10, marginTop: 20 }}
  51. source={image}
  52. >
  53. <View style={{ flex: 1 }} />
  54. </ImageBackground>
  55. <Text style={[styles.cardtitleBlack, { marginTop: 20 }]}>{description}</Text>
  56.  
  57.  
  58. <View style={{ backgroundColor: 'white', paddingTop: 20, flex: 1, flexDirection: 'column', justifyContent: 'flex-end' }}>
  59. <Touchable
  60. onPress={() => { Linking.openURL(`https://www.google.com/maps/dir/?api=1&origin&destination=${description}`); }}
  61. style={[styles.button, { backgroundColor: '#888888' }]}
  62. >
  63. <View>
  64. <Text style={styles.cardtext}>
  65. Open in Google Maps
  66. </Text>
  67. </View>
  68. </Touchable>
  69. </View>
  70.  
  71.  
  72. <View style={{ backgroundColor: 'white', paddingTop: 5, flex: 1, flexDirection: 'column', justifyContent: 'flex-end' }}>
  73. <Touchable
  74. onPress={this.getETA(location)}
  75. style={[styles.button, { backgroundColor: '#888888' }]}
  76. >
  77. <View>
  78. <Text style={styles.cardtext}>
  79. Get Estimated Wait Time
  80. </Text>
  81. </View>
  82. </Touchable>
  83. </View>
  84.  
  85. </View>
  86. );
  87. }
  88.  
  89. getETA = (currentLocation) => {
  90. let compDate = '';
  91. console.log('TESTING')
  92. //first get the current date
  93. let curdate = new Date()
  94. let strdate = curdate.toString()
  95. let indext = strdate.indexOf(" ")
  96. let day = strdate.substring(indext + 1)
  97. indext = strdate.indexOf(" ")
  98. day = day.substring(indext + 1)
  99. indext = day.indexOf(" ")
  100. day = day.substring(0, indext)
  101.  
  102. if(curdate.getMonth() + 1 < 10)
  103. {
  104. compDate = '0'
  105. }
  106.  
  107. compDate += (curdate.getMonth() + 1)
  108. compDate += '/'
  109. compDate += day
  110. compDate += '/'
  111. compDate += (curdate.getFullYear() - 2000)
  112. //now we have a date that matches what we have in the firebase
  113. //compDate should contain: mm/dd/yyyy
  114.  
  115.  
  116. /*this code is important, we create a queary
  117. firebase.database().ref("customers") filters out everything that isnt the customer
  118. .orderbychild("apptDate_time") filters by a property called "apptDate_time" which is just the location
  119. combined with the date */
  120.  
  121. compDate += '_'
  122. compDate += currentLocation;
  123. console.log(compDate);
  124. //now compdate holds the currentLocation and the date
  125. let i = 0;
  126. var ref = firebase.database().ref("/customers/")
  127. .orderByChild("apptDate_Time")
  128. .equalTo(compDate).on('child_added', function(snapshot) {
  129.  
  130. //add a way to filter by time
  131. var customer = snapshot.val();
  132. console.log(customer);
  133. i++;
  134. });
  135.  
  136. Alert.alert('Number of Customers: ' + i);
  137. }
  138. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement