Skip to content

Commit

Permalink
Merge branch 'release-1.0.27' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
entrotech committed Oct 27, 2020
2 parents 29319e4 + 709486b commit 206348f
Show file tree
Hide file tree
Showing 18 changed files with 162 additions and 95 deletions.
2 changes: 1 addition & 1 deletion app/services/account-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ const setPermissions = async (userId, permissionName, value) => {
try {
// do a tiny bit of sanity checking on our input
var booleanValue = Boolean(value);
const updateSql = `update login set ${permissionName}=$1} where id = ${userId};`;
const updateSql = `update login set ${permissionName}=$1 where id = ${userId};`;
await pool.query(updateSql, [booleanValue]);
return {
success: true,
Expand Down
2 changes: 1 addition & 1 deletion client/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion client/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "food-oasis-client",
"description": "React Client for Food Oasis",
"version": "1.0.26",
"version": "1.0.27",
"author": "Hack for LA",
"license": "GPL-2.0",
"private": true,
Expand Down
27 changes: 27 additions & 0 deletions client/public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -67,5 +67,32 @@
To begin the development, run `npm start` or `yarn start`.
To create a production bundle, use `npm run build` or `yarn build`.
-->


<!-- Insert these scripts at the bottom of the HTML, but before you use any Firebase services -->

<!-- Firebase App (the core Firebase SDK) is always required and must be listed first -->
<script src="https://www.gstatic.com/firebasejs/7.24.0/firebase-app.js"></script>

<!-- If you enabled Analytics in your project, add the Firebase SDK for Analytics -->
<script src="https://www.gstatic.com/firebasejs/7.24.0/firebase-analytics.js"></script>

<script>
// Your web app's Firebase configuration
// For Firebase JS SDK v7.20.0 and later, measurementId is optional
var firebaseConfig = {
apiKey: "AIzaSyD9P_FtD1_6A3UefslE-DouTjAnjvv89fw",
authDomain: "hack-for-la-firebase-project.firebaseapp.com",
databaseURL: "https://hack-for-la-firebase-project.firebaseio.com",
projectId: "hack-for-la-firebase-project",
storageBucket: "hack-for-la-firebase-project.appspot.com",
messagingSenderId: "901423769273",
appId: "1:901423769273:web:9f2954b9ba134d7e8f1d68",
measurementId: "G-BX2932LS6Y"
};
// Initialize Firebase
firebase.initializeApp(firebaseConfig);
firebase.analytics();
</script>
</body>
</html>
78 changes: 70 additions & 8 deletions client/src/components/Results/ResultsContainer.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import React, { useEffect, useState } from "react";
import React, { useEffect, useState, useCallback } from "react";
import { makeStyles } from "@material-ui/core/styles";
import { Grid } from "@material-ui/core";

import { useOrganizationBests } from "hooks/useOrganizationBests";
import useCategoryIds from "hooks/useCategoryIds";
import { isMobile } from "helpers";
import { originCoordinates } from "../../helpers/Configuration";
import { originCoordinates } from "helpers/Configuration";
import { DEFAULT_CATEGORIES } from "constants/stakeholder";

import Filters from "./ResultsFilters";
import List from "./ResultsList";
Expand All @@ -22,10 +23,13 @@ const useStyles = makeStyles((theme) => ({
},
}));

export default function ResultsContainer(props) {
export default function ResultsContainer({
userCoordinates,
userSearch,
setToast,
}) {
// Component state
const storage = window.sessionStorage;
const { userCoordinates, userSearch, setToast } = props;
const { data, search } = useOrganizationBests();
const [sortedData, setSortedData] = useState([]);
const classes = useStyles();
Expand All @@ -36,7 +40,7 @@ export default function ResultsContainer(props) {
const [selectedStakeholder, onSelectStakeholder] = useState(null);
const [isMapView, setIsMapView] = useState(true);

const doSelectStakeholder = (stakeholder) => {
const doSelectStakeholder = useCallback((stakeholder) => {
if (stakeholder && !isMobile) {
setViewport({
...viewport,
Expand All @@ -45,7 +49,7 @@ export default function ResultsContainer(props) {
});
}
onSelectStakeholder(stakeholder);
};
});

const switchResultsView = () => {
doSelectStakeholder();
Expand Down Expand Up @@ -147,6 +151,63 @@ export default function ResultsContainer(props) {
};
}, []);

const handleSearch = useCallback(
(e, center) => {
if (e) e.preventDefault();
search({
latitude:
(center && center.lat) ||
origin.latitude ||
userCoordinates.latitude ||
JSON.parse(storage.origin).latitude,
longitude:
(center && center.lng) ||
origin.longitude ||
userCoordinates.longitude ||
JSON.parse(storage.origin).longitude,
radius,
categoryIds: categoryIds.length ? categoryIds : DEFAULT_CATEGORIES,
isInactive: "either",
verificationStatusId: 0,
});
if (origin.locationName && origin.latitude && origin.longitude)
storage.origin = JSON.stringify({
locationName: origin.locationName,
latitude: origin.latitude,
longitude: origin.longitude,
});

storage.categoryIds = JSON.stringify(categoryIds);
storage.radius = JSON.stringify(radius);
storage.verified = JSON.stringify(isVerifiedSelected);
if (!center)
setViewport({
zoom: viewPortHash[radius],
latitude: origin.latitude,
longitude: origin.longitude,
});
doSelectStakeholder(null);
},
[
search,
origin.locationName,
origin.latitude,
origin.longitude,
userCoordinates.latitude,
userCoordinates.longitude,
radius,
categoryIds,
isVerifiedSelected,
setViewport,
doSelectStakeholder,
viewPortHash,
storage.categoryIds,
storage.radius,
storage.verified,
storage.origin,
]
);

return (
<>
<Filters
Expand All @@ -159,11 +220,10 @@ export default function ResultsContainer(props) {
isVerifiedSelected={isVerifiedSelected}
selectVerified={selectVerified}
userCoordinates={userCoordinates}
search={search}
handleSearch={handleSearch}
isWindowWide={isWindowWide}
viewport={viewport}
setViewport={setViewport}
doSelectStakeholder={doSelectStakeholder}
viewPortHash={viewPortHash}
isMapView={isMapView}
switchResultsView={switchResultsView}
Expand All @@ -179,6 +239,7 @@ export default function ResultsContainer(props) {
)}
{(!isMobile || (isMobile && isMapView)) && (
<Map
handleSearch={handleSearch}
selectedLatitude={initialCoords.latitude}
selectedLongitude={initialCoords.longitude}
viewport={viewport}
Expand All @@ -189,6 +250,7 @@ export default function ResultsContainer(props) {
categoryIds={categoryIds}
isWindowWide={isWindowWide}
setToast={setToast}
search={search}
/>
)}
</Grid>
Expand Down
59 changes: 3 additions & 56 deletions client/src/components/Results/ResultsFilters.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import SearchIcon from "@material-ui/icons/Search";
import {
MEAL_PROGRAM_CATEGORY_ID,
FOOD_PANTRY_CATEGORY_ID,
DEFAULT_CATEGORIES,
} from "constants/stakeholder";
import { isMobile } from "helpers";

Expand Down Expand Up @@ -68,11 +67,10 @@ const useStyles = makeStyles((theme) => ({
const distanceInfo = [0, 1, 2, 3, 5, 10, 20, 50, 100, 500];

const ResultsFilters = ({
search,
handleSearch,
isWindowWide,
viewport,
setViewport,
doSelectStakeholder,
origin,
setOrigin,
radius,
Expand All @@ -89,57 +87,6 @@ const ResultsFilters = ({
const isMealsSelected = categoryIds.indexOf(MEAL_PROGRAM_CATEGORY_ID) >= 0;
const isPantrySelected = categoryIds.indexOf(FOOD_PANTRY_CATEGORY_ID) >= 0;

const doHandleSearch = useCallback(
(e) => {
if (e) e.preventDefault();
const storage = window.sessionStorage;
search({
latitude:
origin.latitude ||
userCoordinates.latitude ||
JSON.parse(storage.origin).latitude,
longitude:
origin.longitude ||
userCoordinates.longitude ||
JSON.parse(storage.origin).longitude,
radius,
categoryIds: categoryIds.length ? categoryIds : DEFAULT_CATEGORIES,
isInactive: "either",
verificationStatusId: 0,
});
if (origin.locationName && origin.latitude && origin.longitude)
storage.origin = JSON.stringify({
locationName: origin.locationName,
latitude: origin.latitude,
longitude: origin.longitude,
});

storage.categoryIds = JSON.stringify(categoryIds);
storage.radius = JSON.stringify(radius);
storage.verified = JSON.stringify(isVerifiedSelected);
setViewport({
zoom: viewPortHash[radius],
latitude: origin.latitude,
longitude: origin.longitude,
});
doSelectStakeholder(null);
},
[
search,
origin.locationName,
origin.latitude,
origin.longitude,
userCoordinates.latitude,
userCoordinates.longitude,
radius,
categoryIds,
isVerifiedSelected,
setViewport,
doSelectStakeholder,
viewPortHash,
]
);

const toggleMeal = useCallback(() => {
toggleCategory(MEAL_PROGRAM_CATEGORY_ID);
}, [toggleCategory]);
Expand All @@ -149,7 +96,7 @@ const ResultsFilters = ({
}, [toggleCategory]);

useEffect(() => {
doHandleSearch();
handleSearch();
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [origin, radius, categoryIds, isVerifiedSelected, toggleCategory]);

Expand Down Expand Up @@ -281,7 +228,7 @@ const ResultsFilters = ({
>
<form
noValidate
onSubmit={(e) => doHandleSearch(e)}
onSubmit={(e) => handleSearch(e)}
style={{ all: "inherit" }}
>
<Search
Expand Down
Loading

0 comments on commit 206348f

Please sign in to comment.