diff --git a/client/src/actions/search.js b/client/src/actions/search.js index 1a63138..0df46fe 100644 --- a/client/src/actions/search.js +++ b/client/src/actions/search.js @@ -196,13 +196,12 @@ export function handleAllTotalsQuery(year) { dispatch( updateAllTotals({ timelineData: res.speculationByYear - .map(({ year: recYear, count }) => ({ - x: +recYear, - y: +count, + .map((rec) => ({ + ...rec, + x: +rec.year, + y: +rec.count, })) - .sort((a, b) => a.recYear - b.recYear), - totalSpeculators: +yearRecord.speculator_count, - totalParcels: +yearRecord.count, + .sort((a, b) => a.year - b.year), topSpeculators: res.topSpeculators, }) ) diff --git a/client/src/components/Search/AllParcels.jsx b/client/src/components/Search/AllParcels.jsx index d53ad8a..04fca4c 100644 --- a/client/src/components/Search/AllParcels.jsx +++ b/client/src/components/Search/AllParcels.jsx @@ -20,12 +20,21 @@ import infoIcon from "../../assets/img/info-icon.png" function AllParcels(props) { const year = props.queryParams?.year || DEFAULT_YEAR - const { timelineData, totalSpeculators, totalParcels, topSpeculators } = - useSelector((state) => state.searchState.allTotals) + const { timelineData, topSpeculators } = useSelector( + (state) => state.searchState.allTotals + ) const { drawerIsOpen } = useSelector( (state) => state.searchState.detailedSearch ) + const yearRecord = timelineData.find( + ({ year: recYear }) => +year === +recYear + ) + if (!yearRecord) { + return + } + const { speculator_count: totalSpeculators, count: totalParcels } = yearRecord + return ( totalSpeculators && (
diff --git a/client/src/components/Search/DetailedResultsContainer.jsx b/client/src/components/Search/DetailedResultsContainer.jsx index c07b673..eb5c111 100644 --- a/client/src/components/Search/DetailedResultsContainer.jsx +++ b/client/src/components/Search/DetailedResultsContainer.jsx @@ -29,16 +29,14 @@ function DetailedResultsContainer() { const { drawerIsOpen, resultsType } = useSelector( (state) => state.searchState.detailedSearch ) - const { totalSpeculators } = useSelector( - (state) => state.searchState.allTotals - ) + const { timelineData } = useSelector((state) => state.searchState.allTotals) const { details, detailsCount, detailsZip, detailsType } = getDetailsFromGeoJSON(ppraxis) const dispatch = useDispatch() const queryParams = useQueryParams({ searchQuery: window.location.search }) useEffect(() => { - if (!resultsType && !totalSpeculators) { + if (!resultsType && timelineData.length === 0) { dispatch(handleAllTotalsQuery(queryParams?.year || DEFAULT_YEAR)) } else { dispatch( @@ -52,7 +50,7 @@ function DetailedResultsContainer() { } }, [JSON.stringify(details), detailsZip, detailsCount, detailsType]) - if (resultsType || totalSpeculators) { + if (resultsType || timelineData.length > 0) { return (