import React, { useState } from 'react' import { Text, View, StyleSheet, FlatList, TouchableOpacity, Button, ScrollView } from 'react-native' import SelectBox from 'react-native-multi-selectbox' import { xorBy } from 'lodash' import firebase from 'firebase' import { firebaseConfig } from '../../config/firebaseConfig' //Flag to indicate an IRL appointment. var mapflag = false if (firebase.apps.length === 0) { firebase.initializeApp(firebaseConfig) } require('firebase/firestore') // Options data must contain 'item' & 'id' keys const Tags = [ { item: 'Presencial', id: 'PL', }, { item: 'Online', id: 'ON', }, { item: 'Individual', id: 'IL', }, { item: 'Grupal', id: 'GL', }, { item: 'Esp', id: 'ESP', }, { item: 'Ing', id: 'ING', } ] function Search({route, navigation }) { const u_token = route.params.U_Token; const username = route.params.Username; console.log("U__token: ", u_token) const [users, setUsers] = useState([]) const [selectedTags, setSelectedTags] = useState([]) const fetchUsers = (tags) => { //if the array that have the interpreter tags //and the day tags are empty we dont send the query seeing as the user //is not searching for anything yet if (tags.length === 0) { return } //reset the users usestate to empty const users = [] const db = firebase.firestore() var query = db.collection('Interpreters') for (let i = 0; i < tags.length; i++) { //Reset Flag. mapflag = false //check which tags where called in the search if (tags[i].id === 'PL') { console.log('Presencial') query = query.where('face_to_face', '==', true) mapflag = true } if (tags[i].id == 'ON') { query = query.where('virtual', '==', true) } if (tags[i].id == 'IL') { query = query.where('personal', '==', true) } if (tags[i].id == 'GL') { query = query.where('group', '==', true) } if (tags[i].id == 'ESP') { query = query.where('spanish', '==', true) } if (tags[i].id == 'ING') { query = query.where('english', '==', true) } } query.get().then(querySnapshot => { console.log('Total users: ', querySnapshot.size); //traverse the query snapshot //add the user to the users array querySnapshot.forEach(documentSnapshot => { //save the user id and the user data const user = { id: documentSnapshot.id, data: documentSnapshot.data() } users.push(user) setUsers(users) }); }); console.log('These are the users after the query is executed: ', users) } return ( Busqueda Filtro de Interpretes {/* button that will fetch the users */}