-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Sergio Reyes
committed
Jun 8, 2022
1 parent
c217cd7
commit 9aba27c
Showing
33 changed files
with
1,057 additions
and
99 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import axios from 'axios'; | ||
|
||
const directionsApi = axios.create({ | ||
baseURL: 'https://api.mapbox.com/directions/v5/mapbox/driving', | ||
params: { | ||
alternatives: false, | ||
geometries: 'geojson', | ||
overview: 'simplified', | ||
steps: false, | ||
language: 'es', | ||
access_token: | ||
'pk.eyJ1IjoiY2hlY2hvcmV5ZXMiLCJhIjoiY2w0MnJpd2N6MDJqdjNpcXg2ZWl0bGNmeCJ9.3xcJBowECq6wnZ4xxYCUPg', | ||
}, | ||
}); | ||
|
||
export default directionsApi; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export { default as searchApi } from "./searchAPI"; | ||
export { default as directionsApi } from "./directionsAPI"; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import axios from 'axios'; | ||
|
||
const searchApi = axios.create({ | ||
baseURL: 'https://api.mapbox.com/geocoding/v5/mapbox.places', | ||
params: { | ||
limit: 5, | ||
language: 'es', | ||
access_token: | ||
'pk.eyJ1IjoiY2hlY2hvcmV5ZXMiLCJhIjoiY2w0MnJpd2N6MDJqdjNpcXg2ZWl0bGNmeCJ9.3xcJBowECq6wnZ4xxYCUPg', | ||
}, | ||
}); | ||
|
||
|
||
export default searchApi; |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import React from 'react'; | ||
import { PlacesProvider, MapProvider } from './context'; | ||
import { HomeSceen } from './screens'; | ||
import './styles.css'; | ||
|
||
export const MapApp = () => { | ||
return ( | ||
<PlacesProvider> | ||
<MapProvider> | ||
<HomeSceen /> | ||
</MapProvider> | ||
</PlacesProvider> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { useContext } from 'react'; | ||
import { MapContext, PlacesContext } from '../context'; | ||
|
||
export const BtnMyLocation = () => { | ||
const { isMapReady, map } = useContext(MapContext); | ||
const { userLocation } = useContext(PlacesContext); | ||
|
||
const onClick = () => { | ||
if(!isMapReady) throw new Error('Mapa no está listo'); | ||
if(!userLocation) throw new Error('No hay ubicación de usuario'); | ||
|
||
map?.flyTo({ | ||
zoom: 14, | ||
center: userLocation | ||
}) | ||
}; | ||
|
||
return ( | ||
<button | ||
className='btn btn-primary' | ||
onClick={onClick} | ||
style={{ | ||
position: 'fixed', | ||
top: '20px', | ||
right: '20px', | ||
zIndex: 999, | ||
}} | ||
> | ||
Mi ubicación | ||
</button> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
export const Loading = () => { | ||
return ( | ||
<div className="loading-map d-flex justify-content-center align-items-center"> | ||
<div className="text-center"> | ||
<h3>Espere por favor</h3> | ||
<span>Localizando...</span> | ||
</div> | ||
</div> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import React from 'react' | ||
|
||
export const LoadingPlaces = () => { | ||
return ( | ||
<div className='alert alert-primary mt-2 text-center '> | ||
<h6>Buscando</h6> | ||
<p>Espere por favor</p> | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import React, { useContext, useLayoutEffect, useRef } from 'react'; | ||
import { PlacesContext, MapContext } from '../context'; | ||
import { Loading } from './'; | ||
import mapboxgl from 'mapbox-gl'; | ||
|
||
export const MapView = () => { | ||
const { isLoading, userLocation } = useContext(PlacesContext); | ||
const {setMap } = useContext(MapContext) | ||
const mapDiv = useRef<HTMLDivElement>(null); | ||
|
||
useLayoutEffect(() => { | ||
if (!isLoading){ | ||
const map = new mapboxgl.Map({ | ||
container: mapDiv.current!, | ||
style: 'mapbox://styles/mapbox/streets-v11', | ||
center: userLocation, | ||
zoom: 14 | ||
}); | ||
|
||
setMap(map) | ||
} | ||
}, [isLoading]) | ||
|
||
if (isLoading) { | ||
return <Loading />; | ||
} | ||
|
||
return ( | ||
<div | ||
ref={mapDiv} | ||
style={{ | ||
backgroundColor: 'red', | ||
height: '100vh', | ||
left: 0, | ||
position: 'fixed', | ||
top: 0, | ||
width: '100vw', | ||
}} | ||
> | ||
{userLocation?.join(',')} | ||
</div> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import React from 'react'; | ||
import reactlogo from '../logo.svg'; | ||
|
||
export const ReactLogo = () => { | ||
return ( | ||
<img | ||
src={reactlogo} | ||
alt='React Logo' | ||
style={{ | ||
position: 'fixed', | ||
bottom: '20px', | ||
right: '20px', | ||
width: '130px', | ||
}} | ||
/> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import React, { ChangeEvent, useContext, useRef } from 'react'; | ||
import { PlacesContext } from '../context/places/PlacesContext'; | ||
import { SearchResults } from './SearchResults'; | ||
|
||
export const SearchBar = () => { | ||
const { searchPlacesByTerm } = useContext(PlacesContext); | ||
|
||
const debounceRef = useRef<NodeJS.Timeout>(); | ||
|
||
const onQueryChanged = (event: ChangeEvent<HTMLInputElement>) => { | ||
if (debounceRef.current) clearTimeout(debounceRef.current); | ||
|
||
debounceRef.current = setTimeout(() => { | ||
console.log(event.target.value); | ||
searchPlacesByTerm(event.target.value); | ||
}, 350); | ||
}; | ||
|
||
return ( | ||
<div className='search-container'> | ||
<input | ||
type='text' | ||
className='form-control' | ||
placeholder='Buscar lugar...' | ||
onChange={onQueryChanged} | ||
/> | ||
<SearchResults /> | ||
</div> | ||
); | ||
}; |
Oops, something went wrong.