Skip to content

Commit 1547c1b

Browse files
authored
Merge pull request #2498 from hackforla/1115-org-name-search-update
1115 add stakeholders to search by address or zipcode
2 parents 9b8adae + e6651b1 commit 1547c1b

File tree

3 files changed

+70
-12
lines changed

3 files changed

+70
-12
lines changed

client/src/components/FoodSeeker/AddressDropDown.jsx

Lines changed: 51 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import * as analytics from "services/analytics";
1212
import {
1313
useAppDispatch,
1414
useSearchCoordinates,
15+
useStakeholders,
1516
useUserCoordinates,
1617
useWidget,
1718
} from "../../appReducer";
@@ -24,13 +25,13 @@ export default function AddressDropDown({ autoFocus }) {
2425
const [inputVal, setInputVal] = useState(
2526
searchCoordinates?.locationName || ""
2627
);
27-
const [open, setOpen] = useState(true);
28+
const [open, setOpen] = useState(false);
2829
const { mapboxResults, fetchMapboxResults, isLoading } = useMapboxGeocoder();
2930
const dispatch = useAppDispatch();
3031
const navigate = useNavigate();
3132
const { flyTo } = useMapbox();
3233
const [highlightedOption, setHighlightedOption] = useState(null);
33-
34+
const stakeholders = useStakeholders();
3435
useEffect(() => {
3536
if (userCoordinates) {
3637
setInputVal("");
@@ -50,8 +51,27 @@ export default function AddressDropDown({ autoFocus }) {
5051
const result = mapboxResults.find(
5152
(item) => item.place_name === selectedResult
5253
);
54+
const stakeholderResult = stakeholders.find(
55+
(stakeholder) => getNameAndAddress(stakeholder) === selectedResult
56+
);
5357
setOpen(false);
5458
setInputVal(selectedResult);
59+
if (stakeholderResult) {
60+
const { longitude, latitude } = stakeholderResult;
61+
62+
flyTo({
63+
latitude,
64+
longitude,
65+
});
66+
dispatch({
67+
type: "SEARCH_COORDINATES_UPDATED",
68+
coordinates: { latitude, longitude, locationName: selectedResult },
69+
});
70+
navigate(isWidget ? "/widget" : "/organizations");
71+
72+
analytics.postEvent("changeOrigin", {});
73+
}
74+
5575
if (result) {
5676
const [longitude, latitude] = result.center;
5777

@@ -77,7 +97,7 @@ export default function AddressDropDown({ autoFocus }) {
7797
}}
7898
variant="outlined"
7999
{...params}
80-
label="Search by address or zip code"
100+
label="Search by name, address, or zip code"
81101
margin="none"
82102
fullWidth
83103
name="address"
@@ -117,11 +137,11 @@ export default function AddressDropDown({ autoFocus }) {
117137
};
118138

119139
const renderOption = (props, option) => {
120-
const { key } = props;
140+
const { id } = props;
121141
return (
122142
<MenuItem
123143
{...props}
124-
key={key}
144+
key={id}
125145
component="div"
126146
onClick={() => handleAutocompleteOnChange(option)}
127147
>
@@ -155,7 +175,18 @@ export default function AddressDropDown({ autoFocus }) {
155175
onChange={(_event, newValue) => {
156176
setInputVal(newValue ?? "");
157177
}}
158-
options={mapboxResults.slice(0, 10).map((item) => item.place_name)}
178+
options={[
179+
...stakeholders?.map((stakeholder) => getNameAndAddress(stakeholder)),
180+
...mapboxResults.slice(0, 10).map((item) => item.place_name),
181+
]}
182+
filterOptions={(options, { inputValue }) => {
183+
return options.filter((option) =>
184+
inputValue
185+
.toLowerCase()
186+
.split(" ")
187+
.every((word) => option.toLowerCase().includes(word))
188+
);
189+
}}
159190
sx={{
160191
width: 600,
161192
backgroundColor: "#F0F0F0",
@@ -178,9 +209,23 @@ export default function AddressDropDown({ autoFocus }) {
178209
},
179210
},
180211
}}
212+
ListboxProps={{
213+
style: {
214+
maxHeight: "160px",
215+
},
216+
}}
181217
renderInput={(params) => renderInput(params)}
182218
renderOption={(props, option) => renderOption(props, option)}
183219
/>
184220
</>
185221
);
186222
}
223+
224+
function getNameAndAddress(stakeholder) {
225+
return (
226+
(stakeholder.name ?? "") +
227+
(stakeholder.address1 ? `, ${stakeholder.address1}` : "") +
228+
(stakeholder.city ? `, ${stakeholder.city}` : "") +
229+
(stakeholder.zip ? `, ${stakeholder.zip}` : "")
230+
);
231+
}

client/src/components/FoodSeeker/Home.jsx

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { LocationOn } from "@mui/icons-material";
22
import {
3-
Alert,
43
Box,
54
Button,
65
CircularProgress,
@@ -12,22 +11,36 @@ import {
1211
Typography,
1312
} from "@mui/material";
1413
import AddressDropDown from "components/FoodSeeker/AddressDropDown";
14+
import {
15+
FOOD_PANTRY_CATEGORY_ID,
16+
MEAL_PROGRAM_CATEGORY_ID,
17+
} from "constants/stakeholder";
18+
import { useSiteContext } from "contexts/siteContext";
19+
import { TENANT_LOGO_URL } from "helpers/Constants";
20+
import useCategoryIds from "hooks/useCategoryIds";
1521
import useGeolocation, { useLocationPermission } from "hooks/useGeolocation";
22+
import useOrganizationBests from "hooks/useOrganizationBests";
1623
import { useEffect, useState } from "react";
17-
import { Link as RouterLink, useNavigate } from "react-router-dom";
24+
import { Link as RouterLink } from "react-router-dom";
1825
import * as analytics from "services/analytics";
19-
import { useSiteContext } from "contexts/siteContext";
20-
import { TENANT_LOGO_URL } from "helpers/Constants";
2126
import SEO from "../SEO";
2227

2328
const Home = () => {
24-
const navigate = useNavigate();
2529
const { tenantId, tenantDetails } = useSiteContext();
2630
const { taglineText } = tenantDetails;
2731
const [bgImg, setBgImg] = useState(`url("/landing-page/bg-LA.jpeg")`);
2832
const { getUserLocation, isLoading: isGettingLocation } = useGeolocation();
2933
const [error, setError] = useState("");
3034
const locationPermission = useLocationPermission();
35+
const { categoryIds } = useCategoryIds([
36+
FOOD_PANTRY_CATEGORY_ID,
37+
MEAL_PROGRAM_CATEGORY_ID,
38+
]);
39+
const { selectAll } = useOrganizationBests();
40+
41+
useEffect(() => {
42+
selectAll({ categoryIds });
43+
}, []);
3144

3245
useEffect(() => {
3346
if (error && locationPermission === "granted") {

client/tests/app.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ test.describe("App", () => {
1919
"href",
2020
"/about"
2121
);
22-
page.getByLabel("Search by address or zip code").fill("90001");
22+
page.getByLabel("Search by name, address, or zip code").fill("90001");
2323
await page
2424
.getByText("Los Angeles, California 90001, United States")
2525
.click();

0 commit comments

Comments
 (0)