No Description

Search.js 6.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  1. import React, { useState } from 'react'
  2. import { Text, View, StyleSheet, FlatList, TouchableOpacity, Button, ScrollView } from 'react-native'
  3. import SelectBox from 'react-native-multi-selectbox'
  4. import { xorBy } from 'lodash'
  5. import firebase from 'firebase'
  6. import { firebaseConfig } from '../../config/firebaseConfig'
  7. //Flag to indicate an IRL appointment.
  8. var mapflag = false
  9. if (firebase.apps.length === 0) {
  10. firebase.initializeApp(firebaseConfig)
  11. }
  12. require('firebase/firestore')
  13. // Options data must contain 'item' & 'id' keys
  14. const Tags = [
  15. {
  16. item: 'Presencial',
  17. id: 'PL',
  18. },
  19. {
  20. item: 'Online',
  21. id: 'ON',
  22. },
  23. {
  24. item: 'Individual',
  25. id: 'IL',
  26. },
  27. {
  28. item: 'Grupal',
  29. id: 'GL',
  30. },
  31. {
  32. item: 'Esp',
  33. id: 'ESP',
  34. },
  35. {
  36. item: 'Ing',
  37. id: 'ING',
  38. }
  39. ]
  40. const Days = [
  41. {
  42. item: 'Lunes',
  43. id: 'L',
  44. },
  45. {
  46. item: 'Martes',
  47. id: 'M',
  48. },
  49. {
  50. item: 'Miercoles',
  51. id: 'W',
  52. },
  53. {
  54. item: 'Jueves',
  55. id: 'J',
  56. },
  57. {
  58. item: 'Viernes',
  59. id: 'V',
  60. },
  61. {
  62. item: 'Sabado',
  63. id: 'S',
  64. },
  65. {
  66. item: 'Domingo',
  67. id: 'D',
  68. },
  69. {
  70. item: 'Feriados',
  71. id: 'F',
  72. }
  73. ]
  74. function Search({route, navigation }) {
  75. const u_token = route.params.U_Token;
  76. console.log("U__token: ", u_token)
  77. const [users, setUsers] = useState([])
  78. const [selectedTags, setSelectedTags] = useState([])
  79. const [selectedDays, setSelectedDays] = useState([])
  80. const fetchUsers = (tags, days) => {
  81. //if the array that have the interpreter tags
  82. //and the day tags are empty we dont send the query seeing as the user
  83. //is not searching for anything yet
  84. if (tags.length === 0 && days.length === 0) {
  85. return
  86. }
  87. //reset the users usestate to empty
  88. const users = []
  89. const db = firebase.firestore()
  90. var query = db.collection('Interprete')
  91. for (let i = 0; i < tags.length; i++) {
  92. //Reset Flag.
  93. mapflag = false
  94. //check which tags where called in the search
  95. if (tags[i].id === 'PL') {
  96. console.log('Presencial')
  97. query = query.where('face_to_face', '==', true)
  98. mapflag = true
  99. }
  100. if (tags[i].id == 'ON') {
  101. query = query.where('Modalidad.Online', '==', true)
  102. }
  103. if (tags[i].id == 'IL') {
  104. query = query.where('Cantidad.Individual', '==', true)
  105. }
  106. if (tags[i].id == 'GL') {
  107. query = query.where('Cantidad.Grupal', '==', true)
  108. }
  109. if (tags[i].id == 'ESP') {
  110. query = query.where('Lenguaje.Esp', '==', true)
  111. }
  112. if (tags[i].id == 'ING') {
  113. query = query.where('Lenguaje.Ing', '==', true)
  114. }
  115. }
  116. for(let i = 0; i < days.length; i++) {
  117. if (days[i].id === 'L') {
  118. query = query.where('dias.Lunes', '==', true)
  119. }
  120. if (days[i].id === 'M') {
  121. query = query.where('dias.Martes', '==', true)
  122. }
  123. if (days[i].id === 'W') {
  124. query = query.where('dias.Miercoles', '==', true)
  125. }
  126. if (days[i].id === 'J') {
  127. query = query.where('dias.Jueves', '==', true)
  128. }
  129. if (days[i].id === 'V') {
  130. query = query.where('dias.Viernes', '==', true)
  131. }
  132. if (days[i].id === 'S') {
  133. query = query.where('dias.Sabado', '==', true)
  134. }
  135. if (days[i].id === 'D') {
  136. query = query.where('dias.Domingo', '==', true)
  137. }
  138. if (days[i].id === 'F') {
  139. query = query.where('dias.Feriados', '==', true)
  140. }
  141. }
  142. query.get().then(querySnapshot => {
  143. console.log('Total users: ', querySnapshot.size);
  144. //traverse the query snapshot
  145. //add the user to the users array
  146. querySnapshot.forEach(documentSnapshot => {
  147. //save the user id and the user data
  148. const user = {
  149. id: documentSnapshot.id,
  150. data: documentSnapshot.data()
  151. }
  152. users.push(user)
  153. setUsers(users)
  154. });
  155. });
  156. console.log('These are the users after the query is executed: ', users)
  157. }
  158. return (
  159. <ScrollView>
  160. <View style={{ margin: 30 }}>
  161. <View style={{ width: '100%', alignItems: 'center' }}>
  162. <Text style={{ fontSize: 30, paddingBottom: 20 }}>Busqueda</Text>
  163. </View>
  164. <Text style={{ fontSize: 20, paddingBottom: 10 }}>Filtro de Interpretes</Text>
  165. <SelectBox
  166. arrowIconColor='#E4CD05'
  167. toggleIconColor='#E4CD05'
  168. searchIconColor='#E4CD05'
  169. multiOptionContainerStyle = {{
  170. backgroundColor: '#E4CD05',
  171. borderColor: '#E4CD05',
  172. borderWidth: 1,
  173. borderRadius: 5,
  174. marginBottom: 10,
  175. marginTop: 10,
  176. padding: 10,
  177. }}
  178. multiOptionsLabelStyle = {{
  179. color: '#000000',
  180. fontSize: 20,
  181. }}
  182. label="Select multiple"
  183. options={Tags}
  184. selectedValues={selectedTags}
  185. onMultiSelect={onMultiChange()}
  186. onTapClose={onMultiChange()}
  187. isMulti
  188. />
  189. <Text style={{ fontSize: 20, paddingBottom: 10 }}>Dias Disponibles</Text>
  190. <SelectBox
  191. arrowIconColor='#E4CD05'
  192. toggleIconColor='#E4CD05'
  193. searchIconColor='#E4CD05'
  194. multiOptionContainerStyle = {{
  195. backgroundColor: '#E4CD05',
  196. borderColor: '#E4CD05',
  197. borderWidth: 1,
  198. borderRadius: 5,
  199. marginBottom: 10,
  200. marginTop: 10,
  201. padding: 10,
  202. }}
  203. multiOptionsLabelStyle = {{
  204. color: '#000000',
  205. fontSize: 20,
  206. }}
  207. label="Select multiple"
  208. options={Days}
  209. selectedValues={selectedDays}
  210. onMultiSelect={(item) => setSelectedDays(xorBy(selectedDays, [item], 'id'))}
  211. onTapClose={(item) => setSelectedDays(xorBy(selectedDays, [item], 'id'))}
  212. isMulti
  213. />
  214. {/* button that will fetch the users */}
  215. <Button title='Buscar' onPress={() => fetchUsers(selectedTags, selectedDays)}/>
  216. <FlatList
  217. numColumns={1}
  218. horizontal={false}
  219. data={users}
  220. renderItem={({ item, }) => {
  221. return (
  222. <View>
  223. <View style={{ flexDirection: "row", paddingBottom: 20, paddingTop: 20, justifyContent: "space-between" }}>
  224. <Text>{item.data.name}</Text>
  225. <Text>{item.data.Precio}</Text>
  226. <Button title='Buscar' onPress={() => { dothing(item.id, item.data.push_token, u_token) }}/>
  227. </View>
  228. <View style={{ borderBottomColor: 'black', borderBottomWidth: 1 }} />
  229. </View>
  230. )
  231. }}
  232. />
  233. </View>
  234. </ScrollView>
  235. );
  236. function onMultiChange() {
  237. return (item) => setSelectedTags(xorBy(selectedTags, [item], 'id'))
  238. }
  239. function dothing(item, i_token, u_token) {
  240. console.log('This is the item id: ', item, "With i_token: ", i_token, " u_token : ", u_token)
  241. navigation.navigate('Calendar', {Intereprete_id: item, Flag: mapflag, I_Token: i_token, U_Token: u_token})
  242. }
  243. }
  244. const styles = StyleSheet.create({
  245. button: {
  246. alignItems: "center",
  247. backgroundColor: 'transparent'
  248. },
  249. });
  250. export default Search