mirror of
https://gitlab.com/wheres-the-tp/ui-mobile.git
synced 2026-01-25 07:44:54 -06:00
82 lines
2.1 KiB
JavaScript
82 lines
2.1 KiB
JavaScript
// @flow
|
|
import React from 'react';
|
|
import { View } from 'react-native';
|
|
import typeof ProductRecord from '../records/ProductRecord';
|
|
import { compose, renderComponent } from 'recompose';
|
|
import { Map } from 'immutable';
|
|
import MapView from 'react-native-maps';
|
|
import { routeWithTitle } from '../helpers/RouteHelpers';
|
|
import { withPlaces } from '../enhancers/placeEnhancers';
|
|
import PlaceTile from '../components/PlaceTile';
|
|
import { withProductsGroupedByPlace } from '../enhancers/productsEnhancers';
|
|
import { withRegionState } from '../enhancers/mapViewEnhancers';
|
|
import typeof PlaceRecord from '../records/PlaceRecord';
|
|
|
|
type Region = {
|
|
latitude: number,
|
|
longitude: number,
|
|
latitudeDelta: number,
|
|
longitudeDelta: number,
|
|
};
|
|
|
|
type Props = {
|
|
places: Map<string, PlaceRecord>,
|
|
productsByPlace: Map<string, Map<string, ProductRecord>>,
|
|
location: Location,
|
|
region: Region,
|
|
onRegionChange: Region => void,
|
|
pushRoute: () => {},
|
|
};
|
|
|
|
const PlacesMap = ({
|
|
places = Map(),
|
|
productsByPlace = Map(),
|
|
region,
|
|
onRegionChange,
|
|
pushRoute,
|
|
}: Props) => {
|
|
return (
|
|
<View style={{ flex: 1 }}>
|
|
<MapView
|
|
initialRegion={region}
|
|
region={region}
|
|
style={{ position: 'absolute', top: 0, left: 0, right: 0, bottom: 0 }}
|
|
onRegionChange={onRegionChange}>
|
|
{places
|
|
.map((place: PlaceRecord, placeId: string) => {
|
|
const products = productsByPlace.get(placeId, new Map());
|
|
const firstProduct = products.first();
|
|
|
|
if (!firstProduct) {
|
|
return;
|
|
}
|
|
|
|
return (
|
|
<MapView.Marker
|
|
key={placeId}
|
|
title={place.name}
|
|
coordinate={{
|
|
latitude: firstProduct.latitude,
|
|
longitude: firstProduct.longitude,
|
|
}}>
|
|
<MapView.Callout
|
|
onPress={() => {
|
|
pushRoute(routeWithTitle(`/place/${placeId || ''}`, place.name));
|
|
}}>
|
|
<PlaceTile place={place} products={products} />
|
|
</MapView.Callout>
|
|
</MapView.Marker>
|
|
);
|
|
})
|
|
.toList()}
|
|
</MapView>
|
|
</View>
|
|
);
|
|
};
|
|
|
|
export default compose(
|
|
renderComponent,
|
|
withProductsGroupedByPlace,
|
|
withPlaces,
|
|
withRegionState
|
|
)(PlacesMap);
|