Skip to content

Commit

Permalink
Final
Browse files Browse the repository at this point in the history
  • Loading branch information
mr-rego committed Feb 18, 2023
1 parent 811c224 commit b4211b7
Show file tree
Hide file tree
Showing 14 changed files with 281 additions and 529 deletions.
Binary file modified app/assets/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
145 changes: 87 additions & 58 deletions app/components/MapDisplay.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { StyleSheet, View, Text, StatusBar, TouchableOpacity } from 'react-native'
import { StyleSheet, View, TouchableOpacity, ActivityIndicator } from 'react-native'
import React, { useState, useContext, useEffect, useRef } from 'react'
import MapView, { Marker } from 'react-native-maps';
import { GooglePlacesAutocomplete } from 'react-native-google-places-autocomplete';
Expand All @@ -25,9 +25,9 @@ const MapDisplay = ({ scrollToItem }) => {
}

const setNewAddress = (data, details) => {
console.log('DATA');
// console.log('DATA');
console.log(JSON.stringify(data));
console.log('DETAILS');
// console.log('DETAILS');
console.log(JSON.stringify(details));

let region = {
Expand All @@ -40,7 +40,7 @@ const MapDisplay = ({ scrollToItem }) => {
setLocation(region);
}

const timerIntervalInSeconds = 60
const timerIntervalInSeconds = 10
useEffect(() => {
const timer = setInterval(() => {
console.log(`This will run after ${timerIntervalInSeconds} seconds!`)
Expand All @@ -49,9 +49,31 @@ const MapDisplay = ({ scrollToItem }) => {
return () => clearInterval(timer);
}, []);

// useEffect(() => {
// console.log("HELLO PUSHCARTS")
// console.log(pushCartList)

// Object.keys(pushCartList).map(
// (item, index) => {
// console.log('item:', item, 'index:', index)
// console.log(pushCartList[item].name)
// console.log(pushCartList[item].latitude)
// console.log(pushCartList[item].longitude)
// })

// return () => {

// }
// }, [pushCartList])


// const drawPushCarts = () => {
// console.log(pushCartList)
// }

let permission;
const getLocation = async () => {
console.log('trying to get locs')
// console.log('trying to get locs')

if (!permission) {
permission = await Location.requestForegroundPermissionsAsync();
Expand All @@ -63,9 +85,9 @@ const MapDisplay = ({ scrollToItem }) => {
}
}

console.log('trying to get locs1')
// console.log('trying to get locs1')
let loc = await Location.getCurrentPositionAsync({});
console.log('trying to get locs2')
// console.log('trying to get locs2')
if (constants.userLocationLat && constants.userLocationLng) {
// setUserData(prevState => ({ ...prevState, loc: { 'lat': constants.userLocationLat, 'lng': constants.userLocationLng } }))
dispatch(addUserEntry({ 'latitude': constants.userLocationLat, 'longitude': constants.userLocationLng }))
Expand All @@ -76,7 +98,7 @@ const MapDisplay = ({ scrollToItem }) => {
longitudeDelta: 0.004,
})
} else {
console.log('LOCATION:');
// console.log('LOCATION:');
console.log(JSON.stringify(loc));

// setUserData(prevState => ({ ...prevState, loc: { 'lat': loc.coords.latitude, 'lng': loc.coords.longitude } }))
Expand All @@ -91,55 +113,62 @@ const MapDisplay = ({ scrollToItem }) => {
}

return (
location
&&
<View style={styles.container}>
<MapView
style={styles.map}
provider={MapView.PROVIDER_GOOGLE}
region={location}
showsUserLocation={true}
mapPadding={{ top: 40 }}
>
{
Object.values(pushCartList).map(
(item, index) =>
<Marker
coordinate={{ latitude: item.latitude, longitude: item.longitude }}
title={item.name}
// pinColor={constants.mapPinColorList[item.id]}
pinColor={'purple'}
key={index}
onPress={(e) => {
console.log('marker onPress:', index)
scrollToItem(index);
}}
/>)
}
</MapView>
<GooglePlacesAutocomplete
ref={ref}
placeholder='Search location'
fetchDetails={true}
onPress={(data, details = null) => setNewAddress(data, details)}
onFail={error => console.log(error)}
onNotFound={() => console.log('no results')}
query={{
key: process.env.GOOGLE_MAPS_API_KEY.toString(),
language: 'en',
}}
styles={styles.searchBar}
// renderLeftButton={() => <FontAwesome5 name="map-marker-alt" size={20} color="black" style={styles.searchButton} />}
renderRightButton={() =>
<TouchableOpacity
onPress={() => {
clearSearch();
}}>
<Ionicons name="close" size={30} color="black" style={styles.clearButton} />
</TouchableOpacity>
}
/>
</View>
<>
{
location
?
<View style={styles.container}>
<MapView
style={styles.map}
provider={MapView.PROVIDER_GOOGLE}
region={location}
showsUserLocation={true}
mapPadding={{ top: 40 }}
>
{
Object.keys(pushCartList).map(
(item, index) =>
<Marker
coordinate={{ latitude: pushCartList[item].latitude, longitude: pushCartList[item].longitude }}
title={pushCartList[item].name}
// pinColor={constants.mapPinColorList[item.id]}
// pinColor={'purple'}
key={index}
onPress={(e) => {
console.log('marker onPress:', index)
scrollToItem(index);
}}
/>
)
}
</MapView>
<GooglePlacesAutocomplete
ref={ref}
placeholder='Search location'
fetchDetails={true}
onPress={(data, details = null) => setNewAddress(data, details)}
onFail={error => console.log(error)}
onNotFound={() => console.log('no results')}
query={{
key: process.env.GOOGLE_MAPS_API_KEY.toString(),
language: 'en',
}}
styles={styles.searchBar}
// renderLeftButton={() => <FontAwesome5 name="map-marker-alt" size={20} color="black" style={styles.searchButton} />}
renderRightButton={() =>
<TouchableOpacity
onPress={() => {
clearSearch();
}}>
<Ionicons name="close" size={30} color="black" style={styles.clearButton} />
</TouchableOpacity>
}
/>
</View>
:
<ActivityIndicator size="large" color="#00ff00" style={styles.container} />
}
</>
)
}

Expand All @@ -150,7 +179,7 @@ const styles = StyleSheet.create({
position: 'relative',
widht: '100%',
height: '100%',
backgroundColor: 'yellow',
backgroundColor: 'grey',
},
map: {
position: 'absolute',
Expand Down
61 changes: 21 additions & 40 deletions app/components/PushCartList.jsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import { StyleSheet, Text, View, TouchableOpacity, FlatList } from 'react-native'
import React, { useCallback, useContext, useEffect, useRef } from 'react'
import { StyleSheet, Text, TouchableOpacity, FlatList } from 'react-native'
import React, { useContext, useEffect, useRef } from 'react'
import Ionicons from 'react-native-vector-icons/Ionicons';
import { useNavigation } from '@react-navigation/native';

import constants from '../config/constants'
import { getVendorsFromDB } from '../../firebase';
import { axGetAllVendorsFromDB } from '../context/axiosAPI';
import { PushCartContext } from '../context/PushCartContext';
import PushCart from './PushCart'

Expand All @@ -13,27 +11,21 @@ const PushCartList = ({ navigateToPushCart, trigger }) => {
const refFlatList = useRef(null)

const scrolltoListItem = () => {
console.log('PushCartList scrolltoListItem')
// console.log('PushCartList scrolltoListItem')
}

// const timerInterval = 30000
// useEffect(() => {
// const timer = setInterval(() => {
// console.log("trying to load all push carts");
// // const data = fetchData()
// getVendorsFromDB()
// .then((data) => setPushCartList(data))
// .catch((error) => console.log('Error in fetching pushcarts:', error))
// }, timerInterval);
// return () => clearInterval(timer);
// }, []);

useEffect(() => {
console.log("trying to load all push carts");
// const data = fetchData()
getVendorsFromDB()
.then((data) => setPushCartList(data))
.catch((error) => console.log('Error in fetching pushcarts:', error))
async function fetchData() {
// console.log("trying to load all push carts");
let response = await axGetAllVendorsFromDB()
// console.log('PushCartList useEffect :', response)
setPushCartList(response.data)
}
fetchData();

return () => {

}
}, []);

useEffect(() => {
Expand All @@ -43,7 +35,7 @@ const PushCartList = ({ navigateToPushCart, trigger }) => {
}, [trigger]);

const log = (trigger) => {
console.log("call from parent");
// console.log("call from parent");

if (trigger < 0)
return;
Expand All @@ -54,18 +46,11 @@ const PushCartList = ({ navigateToPushCart, trigger }) => {
refFlatList.current?.scrollToIndex({ animated: true, index: trigger });
};

const refreshCarts = () => {
// console.log('pressed: ', pushCartList)
// Object.values(pushCartList).map((item, index) => {
// console.log('index:', index)
// console.log('item:', typeof item.latitude)
// })

console.log("trying to load all push carts");
// const data = fetchData()
getVendorsFromDB()
.then((data) => setPushCartList(data))
.catch((error) => console.log('Error in fetching pushcarts:', error))
const refreshCarts = async () => {
// console.log("trying to load all push carts");
let response = await axGetAllVendorsFromDB()
// console.log('PushCartList useEffect :', response)
setPushCartList(response.data)
}

return (
Expand All @@ -91,10 +76,6 @@ const PushCartList = ({ navigateToPushCart, trigger }) => {
</TouchableOpacity>
}
keyExtractor={item => item.name}
// contentContainerStyle={{
// flexGrow: 1,
// paddingBottom: 20,
// }}
style={styles.carts}
/>
}
Expand Down
6 changes: 5 additions & 1 deletion app/config/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,14 @@ export default {

// ONLY FOR TESTING, PLEASE RESET FOR PRODUCTION
defaultUserType: 0,
defaultPhoneNumber: '+919999999999',
// defaultPhoneNumber: '+919999999999',
// defaultPhoneNumber: '+919833242774',

// defaultUserType: 1,
// defaultPhoneNumber: '+11111111111',
// defaultPhoneNumber: '+12222222222',
// defaultPhoneNumber: '+13333333333',
// defaultPhoneNumber: '+14444444444',
// defaultPhoneNumber: '+911111111111',
// defaultPhoneNumber: '+919833242774',
defaultVerificationCode: '654321',
Expand Down
2 changes: 1 addition & 1 deletion app/context/PushCartContext.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { createContext, useState, useEffect, useCallback } from "react";
import { getVendorsFromDB } from '../../firebase';
// import { getVendorsFromDB } from '../../firebase';

export const PushCartContext = createContext();

Expand Down
60 changes: 60 additions & 0 deletions app/context/axiosAPI.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import axios from 'axios';
// const baseUrl = 'http://192.168.1.11:3000';
// const baseUrl = 'http://192.168.1.11:5001/pushcartping/us-central1/app';
const baseUrl = 'https://us-central1-pushcartping.cloudfunctions.net/app';

export const axFetchCustomerData = async (uid) => {
const url = `${baseUrl}/user/${uid}`;
const response = await axios.get(url);
const data = await response.data;
return { status: response.status, data: data };
};

export const axAddCustomerToDatabase = async ({ uid, userName = '', userEmail = '', userPhotoURL = '' }) => {
const url = `${baseUrl}/user/${uid}`;
const response = await axios.post(url, {
userName,
userEmail,
userPhotoURL
});
const data = await response.data;
return { status: response.status, data: data };
}

export const axFetchVendorData = async (uid) => {
const url = `${baseUrl}/vendor/${uid}`;
const response = await axios.get(url);
const data = await response.data;
return { status: response.status, data: data };
};

export const axAddVendorToDatabase = async ({ uid, userName = '', userEmail = '', userPhotoURLs = [], userCategory = '', userTagline = '', userDescription = '' }) => {
const url = `${baseUrl}/vendor/${uid}`;
const response = await axios.post(url, {
userName,
userEmail,
userPhotoURLs,
userCategory,
userTagline,
userDescription,
});
const data = await response.data;
return { status: response.status, data: data };
}

export const axSetCurrentVendorLocation = async ({ uid, latitude, longitude }) => {
const url = `${baseUrl}/vendor/${uid}`;
const response = await axios.patch(url, {
latitude,
longitude,
});
const data = await response.data;
return { status: response.status, data: data };
}

export const axGetAllVendorsFromDB = async () => {
const url = `${baseUrl}/vendor/get/all`;
const response = await axios.get(url);
const data = await response.data;
return { status: response.status, data: data };
}
Loading

0 comments on commit b4211b7

Please sign in to comment.