From 583de6eac1c039da65e1fd59fe3ce6c7c0f49e4e Mon Sep 17 00:00:00 2001 From: Bart Akeley Date: Sun, 29 Mar 2020 14:49:53 -0500 Subject: [PATCH] FavesMap screen --- js/pages/Faves.js | 14 +++++ js/pages/{FavesPage.js => FavesList.js} | 0 js/pages/FavesMap.js | 80 +++++++++++++++++++++++++ js/pages/Nav.js | 6 +- 4 files changed, 97 insertions(+), 3 deletions(-) create mode 100644 js/pages/Faves.js rename js/pages/{FavesPage.js => FavesList.js} (100%) create mode 100644 js/pages/FavesMap.js diff --git a/js/pages/Faves.js b/js/pages/Faves.js new file mode 100644 index 0000000..b75ab81 --- /dev/null +++ b/js/pages/Faves.js @@ -0,0 +1,14 @@ +// @flow +import { compose, branch } from 'recompose'; +import FavesList from './FavesList'; +import FavesMap from './FavesMap'; +import { withRouterContext, withViewMode, withPushRoute } from '../enhancers/routeEnhancers'; + +export default compose( + withRouterContext, + withViewMode, + withPushRoute, + branch(({ viewMode }) => { + return viewMode === 'map'; + }, FavesMap) +)(FavesList); diff --git a/js/pages/FavesPage.js b/js/pages/FavesList.js similarity index 100% rename from js/pages/FavesPage.js rename to js/pages/FavesList.js diff --git a/js/pages/FavesMap.js b/js/pages/FavesMap.js new file mode 100644 index 0000000..eb8a772 --- /dev/null +++ b/js/pages/FavesMap.js @@ -0,0 +1,80 @@ +// @flow +import React from 'react'; +import { View } from 'react-native'; +import { withLocation } from '../enhancers/locationEnhancers'; +import { compose, renderComponent, withState, withProps } from 'recompose'; +import { Map, get } from 'immutable'; +import MapView from 'react-native-maps'; +import { routeWithTitle } from '../helpers/RouteHelpers'; +import FoodItemTile from '../components/FoodItemTile'; +import { getZoomBox } from '../helpers/CoordinatesHelpers'; +import { withFaves } from '../enhancers/favesEnhancer'; +import { type Faves } from '../streams/FavesStream'; + +type Region = { + latitude: number, + longitude: number, + latitudeDelta: number, + longitudeDelta: number, +}; + +type Props = { + faves: Faves, + location: Location, + initialRegion: Region, + region: Region, + onRegionChange: Region => void, + pushRoute: () => {}, +}; + +const FavesMap = ({ faves, region, onRegionChange, pushRoute, initialRegion }: Props) => { + if (!faves) { + return null; + } + return ( + + + {faves.map(fave => ( + + { + pushRoute(routeWithTitle(`/foodItem/${get(fave, 'id', '')}`, get(fave, 'name'))); + }}> + + + + ))} + + + ); +}; + +const withInitialRegionProp = withProps(({ foodItemsMap = Map(), location }) => { + const zoomBox = getZoomBox(foodItemsMap, location.coords); + + return { + initialRegion: { + latitude: (zoomBox.minLat + zoomBox.maxLat) / 2, + longitude: (zoomBox.minLng + zoomBox.maxLng) / 2, + latitudeDelta: zoomBox.maxLat - zoomBox.minLat + 0.02, + longitudeDelta: zoomBox.maxLng - zoomBox.minLng + 0.02, + }, + }; +}); + +export default compose( + renderComponent, + withFaves, + withLocation, + withState('region', 'onRegionChange', null), + withInitialRegionProp +)(FavesMap); diff --git a/js/pages/Nav.js b/js/pages/Nav.js index 4d29c2d..6cd6f50 100644 --- a/js/pages/Nav.js +++ b/js/pages/Nav.js @@ -10,8 +10,8 @@ import { withRouterContext, type routerContext } from '../enhancers/routeEnhance import { pathOr } from 'ramda'; import uiTheme from '../ui-theme'; import ProfilePage from './ProfilePage'; -import AuthManager from '../AuthManager'; -import FavesPage from './FavesPage'; +import Faves from './Faves'; +import { fetchFaves } from '../apis/FavesApi'; type Props = { activeTab: string, @@ -29,7 +29,7 @@ const Nav = (props: Props) => { {activeTab === 'food' && } {activeTab === 'places' && } - {activeTab === 'faves' && } + {activeTab === 'faves' && } {activeTab === 'profile' && }