Skip to content

Commit

Permalink
fix: displayed values for all totals
Browse files Browse the repository at this point in the history
  • Loading branch information
pjsier committed Nov 7, 2024
1 parent 2c94e76 commit e007f61
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 15 deletions.
11 changes: 5 additions & 6 deletions client/src/actions/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
})
)
Expand Down
13 changes: 11 additions & 2 deletions client/src/components/Search/AllParcels.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 && (
<div className="results-inner scroller">
Expand Down
8 changes: 3 additions & 5 deletions client/src/components/Search/DetailedResultsContainer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -52,7 +50,7 @@ function DetailedResultsContainer() {
}
}, [JSON.stringify(details), detailsZip, detailsCount, detailsType])

if (resultsType || totalSpeculators) {
if (resultsType || timelineData.length > 0) {
return (
<CSSTransition
in={drawerIsOpen} //set false on load
Expand Down
2 changes: 0 additions & 2 deletions client/src/reducers/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ const initialSearchState = {
},
allTotals: {
timelineData: [],
totalSpeculators: null,
totalParcels: null,
topSpeculators: [],
},
downloadData: null,
Expand Down

0 comments on commit e007f61

Please sign in to comment.