Skip to content

Commit 8f2378c

Browse files
committed
Merge branch 'release-1.0.56'
2 parents b7ec348 + 2313cbc commit 8f2378c

39 files changed

+1033
-1042
lines changed

client/package-lock.json

+16-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

client/package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "foodoasis-client",
33
"description": "React Client for Food Oasis",
4-
"version": "1.0.55",
4+
"version": "1.0.56",
55
"author": "Hack for LA",
66
"license": "GPL-2.0",
77
"private": true,
@@ -19,6 +19,7 @@
1919
},
2020
"dependencies": {
2121
"@date-io/moment": "^1.3.13",
22+
"@mapbox/geo-viewport": "^0.4.1",
2223
"@material-ui/core": "^4.11.1",
2324
"@material-ui/icons": "^4.11.2",
2425
"@material-ui/lab": "^4.0.0-alpha.57",

client/src/App.js

+14-60
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ import { makeStyles, ThemeProvider } from "@material-ui/core/styles";
99
import { Grid, CssBaseline } from "@material-ui/core";
1010
import theme from "theme/clientTheme";
1111
import { logout } from "services/account-service";
12-
import { tenantId, defaultCoordinates } from "helpers/Configuration";
12+
import { tenantId, defaultViewport } from "helpers/Configuration";
13+
import useGeolocation from "hooks/useGeolocation";
1314

1415
// Components
1516
import { UserContext } from "contexts/user-context";
@@ -48,7 +49,7 @@ import ConfirmEmail from "components/Account/ConfirmEmail";
4849
import FaqEdit from "components/Faq/FaqEdit";
4950
import FaqAdd from "components/Faq/FaqAdd";
5051
import Home from "components/FoodSeeker/Home";
51-
import Results from "components/FoodSeeker/ResultsContainer";
52+
import SearchResults from "components/FoodSeeker/SearchResults";
5253
import Suggestion from "components/FoodSeeker/Suggestion";
5354
import ImportFile from "components/Admin/ImportOrganizations/ImportFile";
5455
import adminTheme from "./theme/adminTheme";
@@ -89,19 +90,17 @@ const useStyles = makeStyles({
8990

9091
function App() {
9192
const [user, setUser] = useState(null);
92-
// userCoordinates is the user's location if location is enabled, or the
93-
// default tenant center location if the browser location is disabled.
94-
const [userCoordinates, setUserCoordinates] = useState({});
95-
const [toast, setToast] = useState({ message: "" });
96-
const [bgImg, setBgImg] = useState("");
93+
9794
// origin is where the map should be centered. It is at the App level
98-
// so it can be passed from leanding pages to the ResultsContainer.
99-
const [origin, setOrigin] = useState({
100-
latitude: defaultCoordinates.lat,
101-
longitude: defaultCoordinates.lon,
102-
});
95+
// so it can be passed from landing pages to the SearchResults.
96+
const [origin, setOrigin] = useState(defaultViewport.center);
10397

104-
const [browserLocation, setBrowserLocation] = useState(false);
98+
// userCoordinates is the user's location if geolocation is enabled,
99+
// otherwise null.
100+
const userCoordinates = useGeolocation();
101+
102+
const [toast, setToast] = useState({ message: "" });
103+
const [bgImg, setBgImg] = useState("");
105104

106105
useEffect(() => {
107106
const imgNum = Math.floor(Math.random() * (21 - 1)) + 1;
@@ -129,49 +128,6 @@ function App() {
129128
}
130129
}, [user]);
131130

132-
useEffect(() => {
133-
const fetchLocation = () => {
134-
let userCoordinates = { latitude: null, longitude: null };
135-
if (navigator.geolocation) {
136-
navigator.geolocation.getCurrentPosition(
137-
(position) => {
138-
if (position) {
139-
const userCoordinates = {
140-
latitude: position.coords.latitude,
141-
longitude: position.coords.longitude,
142-
};
143-
setUserCoordinates(userCoordinates);
144-
setBrowserLocation(true);
145-
}
146-
},
147-
(error) => {
148-
// Ususally because user has blocked location
149-
console.log(`Getting browser location failed: ${error.message}`);
150-
const userCoordinates = {
151-
latitude: defaultCoordinates.lat,
152-
longitude: defaultCoordinates.lon,
153-
};
154-
setUserCoordinates(userCoordinates);
155-
setBrowserLocation(false);
156-
}
157-
);
158-
} else {
159-
console.log(
160-
"Browser does not support getting users location - using default location for area"
161-
);
162-
const userCoordinates = {
163-
latitude: defaultCoordinates.lat,
164-
longitude: defaultCoordinates.lon,
165-
};
166-
setUserCoordinates(userCoordinates);
167-
setBrowserLocation(false);
168-
}
169-
170-
return userCoordinates;
171-
};
172-
fetchLocation();
173-
}, []);
174-
175131
const onLogin = (user) => {
176132
if (user) {
177133
sessionStorage.setItem("user", JSON.stringify(user));
@@ -221,7 +177,6 @@ function App() {
221177
userCoordinates={userCoordinates}
222178
origin={origin}
223179
setOrigin={setOrigin}
224-
browserLocation={browserLocation}
225180
/>
226181
</div>
227182
</div>
@@ -233,12 +188,11 @@ function App() {
233188
*/}
234189
<Redirect from="/search" to="/organizations" />
235190
<Route path="/organizations">
236-
<Results
237-
userCoordinates={userCoordinates}
191+
<SearchResults
238192
origin={origin}
239193
setOrigin={setOrigin}
194+
userCoordinates={userCoordinates}
240195
setToast={setToast}
241-
browserLocation={browserLocation}
242196
/>
243197
</Route>
244198
<Route path="/suggestion">

client/src/components/Admin/SearchCriteria.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import {
2020
import RadioTrueFalseEither from "./ui/RadioTrueFalseEither";
2121
import LocationAutocomplete from "./LocationAutocomplete";
2222
import AccountAutocomplete from "./AccountAutocomplete";
23-
import { defaultCoordinates } from "../../helpers/Configuration";
23+
import { defaultViewport } from "../../helpers/Configuration";
2424

2525
const useStyles = makeStyles(() => ({
2626
card: {
@@ -56,9 +56,11 @@ const SearchCriteria = ({
5656
: "custom"
5757
);
5858

59-
const [customLatitude, setCustomLatitude] = useState(defaultCoordinates.lat);
59+
const [customLatitude, setCustomLatitude] = useState(
60+
defaultViewport.center.latitude
61+
);
6062
const [customLongitude, setCustomLongitude] = useState(
61-
defaultCoordinates.lon
63+
defaultViewport.center.longitude
6264
);
6365
const [customPlaceName, setCustomPlaceName] = useState("");
6466

client/src/components/FoodSeeker/ResultsContainerOld.js renamed to client/src/components/Deprecated/FoodSeeker/ResultsContainerOld.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { useHistory } from "react-router-dom";
66
import { useOrganizationBests } from "hooks/useOrganizationBests";
77
import useCategoryIds from "hooks/useCategoryIds";
88
import { isMobile } from "helpers";
9-
import { defaultCoordinates } from "helpers/Configuration";
9+
import { defaultViewport } from "helpers/Configuration";
1010
import { DEFAULT_CATEGORIES } from "constants/stakeholder";
1111

1212
import Filters from "./ResultsFilters";
@@ -137,12 +137,12 @@ export default function ResultsContainer({
137137
isInactive: "either",
138138
verificationStatusId: 0,
139139
bounds,
140-
radius: defaultCoordinates.radius,
140+
radius: defaultViewport.radius,
141141
});
142142

143143
if (!center) {
144144
setInitViewport({
145-
zoom: defaultCoordinates.zoom,
145+
zoom: defaultViewport.zoom,
146146
latitude: origin.latitude,
147147
longitude: origin.longitude,
148148
});

client/src/components/FoodSeeker/ResultsMapOld.js renamed to client/src/components/Deprecated/FoodSeeker/ResultsMapOld.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { isMobile } from "helpers";
1111
import StakeholderPreview from "components/FoodSeeker/StakeholderPreview";
1212
import StakeholderDetails from "components/FoodSeeker/StakeholderDetails";
1313
import theme from "theme/clientTheme";
14-
import { defaultCoordinates } from "helpers/Configuration";
14+
import { defaultViewport } from "helpers/Configuration";
1515

1616
const styles = {
1717
navigationControl: {
@@ -115,7 +115,7 @@ function Map({
115115
}) {
116116
const [viewport, setViewport] = useState(
117117
initViewport || {
118-
zoom: defaultCoordinates.zoom,
118+
zoom: defaultViewport.zoom,
119119
latitude: origin.latitude,
120120
longitude: origin.longitude,
121121
logoPosition: "top-left",

client/src/components/FoodSeeker/Home.js

+12-26
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
1-
import React, { useEffect } from "react";
1+
import React, { useEffect, useCallback } from "react";
22
import { withRouter } from "react-router";
33
import CssBaseline from "@material-ui/core/CssBaseline";
44
import Typography from "@material-ui/core/Typography";
55
import { makeStyles } from "@material-ui/core/styles";
66
import Container from "@material-ui/core/Container";
77
import Paper from "@material-ui/core/Paper";
88
import Box from "@material-ui/core/Box";
9-
import Search from "components/FoodSeeker/Search";
9+
import SearchBar from "components/FoodSeeker/SearchBar";
1010
// The three tenant logos happen to be the same at the moment
1111
import logo from "images/foodoasis.svg";
1212
import logoCA from "images/foodoasis.svg";
1313
import logoHI from "images/foodoasis.svg";
1414
import { tenantId } from "helpers/Configuration";
15-
import * as analytics from "../../services/analytics";
15+
import * as analytics from "services/analytics";
1616

1717
const useStyles = makeStyles((theme) => ({
1818
container: {
@@ -116,24 +116,23 @@ const useStyles = makeStyles((theme) => ({
116116
},
117117
}));
118118

119-
const Home = (props) => {
119+
const Home = ({ origin, setOrigin, userCoordinates, match, history }) => {
120120
const classes = useStyles();
121-
const { origin, setOrigin, userCoordinates, browserLocation } = props;
122121

123122
useEffect(() => {
124123
analytics.postEvent("visitLandingPage");
125124
}, []);
126125

127-
React.useEffect(() => {
128-
if (props.match.path === "/") {
126+
useEffect(() => {
127+
if (match.path === "/") {
129128
sessionStorage.clear();
130129
}
131-
}, [props.match.path]);
130+
}, [match.path]);
132131

133-
const selectLocation = (origin) => {
132+
const selectLocation = useCallback((origin) => {
134133
setOrigin(origin);
135-
props.history.push("/organizations");
136-
};
134+
history.push("/organizations");
135+
}, [setOrigin, history]);
137136

138137
return (
139138
<Container component="main" maxWidth="sm" className={classes.container}>
@@ -151,7 +150,7 @@ const Home = (props) => {
151150
<Box className={classes.formContainer}>
152151
<form
153152
className={classes.form}
154-
onSubmit={() => props.history.push("/organizations")}
153+
onSubmit={() => history.push("/organizations")}
155154
>
156155
{tenantId === 5 ? (
157156
<Typography variant={"h5"} className={classes.label}>
@@ -178,25 +177,12 @@ const Home = (props) => {
178177
Locate free food in Los Angeles
179178
</Typography>
180179
)}
181-
182180
<Box className={classes.inputContainer}>
183-
<Search
181+
<SearchBar
184182
userCoordinates={userCoordinates}
185183
setOrigin={selectLocation}
186184
origin={origin}
187-
browserLocation={browserLocation}
188185
/>
189-
{/* <Button
190-
type="submit"
191-
disabled={isDefaultOrigin}
192-
variant="contained"
193-
className={classes.submit}
194-
startIcon={
195-
<SearchIcon fontSize="large" className={classes.searchIcon} />
196-
}
197-
>
198-
{""}
199-
</Button>*/}
200186
</Box>
201187
</form>
202188
</Box>

0 commit comments

Comments
 (0)