Skip to content

Commit

Permalink
fix: update panel loading logic
Browse files Browse the repository at this point in the history
  • Loading branch information
pjsier committed Oct 30, 2024
1 parent 7667307 commit 05c5fff
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 16 deletions.
26 changes: 11 additions & 15 deletions client/src/components/Search/DetailedSearchResults.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ function useSpeculationByCode(results, { code, year }) {
return { data, topCount, topPer }
}

function useCodesBySpeculator({ code, ownid, year }) {
function useCodesBySpeculator({ ownid, year }) {
const [speculatorData, setSpeculatorData] = useState(null)
const [propCount, setPropCount] = useState(null)
const [zipsBySpeculator, setZipsBySpeculator] = useState(null)
Expand All @@ -92,18 +92,16 @@ function useCodesBySpeculator({ code, ownid, year }) {

useEffect(() => {
;(async () => {
if (code) {
const route = `/api/detailed-search?type=codes-by-speculator&ownid=${ownid}&year=${year}`
const data = await APISearchQueryFromRoute(route)
setSpeculatorData(data)
const route = `/api/detailed-search?type=codes-by-speculator&ownid=${ownid}&year=${year}`
const data = await APISearchQueryFromRoute(route)
setSpeculatorData(data)

const { propCount, speculatorZips } = calulateSpeculatorTotals(data)
setPropCount(propCount)
setZipsBySpeculator(speculatorZips)
}
const { propCount, speculatorZips } = calulateSpeculatorTotals(data)
setPropCount(propCount)
setZipsBySpeculator(speculatorZips)
})()
return () => null
}, [ownid, year, code])
}, [ownid, year])

return { speculatorData, propCount, zipsBySpeculator }
}
Expand Down Expand Up @@ -289,12 +287,12 @@ function DumbPaginator({ data, itemsPerPage = 10, queryParams, children }) {
data properties, ids, and data return type (details type) are.
They also use internal state in most cases. */
function ContentSwitch({ detailsType, queryParams }) {
const { results, resultsType } = useSelector(
const { results, resultsCount, resultsType } = useSelector(
(state) => state.searchState.detailedSearch
)

// TODO: Don't worry as much about single vs multiple
if (results && results.length > 0 && resultsType) {
if (results && resultsCount > 0 && resultsType) {
switch (detailsType) {
case "parcels-by-geocode:single-parcel":
return <SingleParcel result={results[0]} queryParams={queryParams} />
Expand Down Expand Up @@ -416,13 +414,11 @@ function CodeParcels(props) {
function SpeculatorParcels(props) {
const { ownid, year } = props.queryParams

const { drawerIsOpen, results } = useSelector(
const { drawerIsOpen } = useSelector(
(state) => state.searchState.detailedSearch
)
const code = results[0].properties.propzip // need some error handling

const { speculatorData, propCount, zipsBySpeculator } = useCodesBySpeculator({
code,
ownid,
year,
})
Expand Down
9 changes: 8 additions & 1 deletion client/src/utils/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ export function flattenPrimaryResults(primaryResults) {

// Hacking this a bit to handle different response types
export function getDetailsFromGeoJSON(geojson) {
if (geojson?.type === "FeatureCollection") {
if (geojson?.type === "FeatureCollection" && geojson?.features?.length > 0) {
const details = geojson.features.map((feature) => {
const { centroid, properties } = feature
return { centroid, properties }
Expand All @@ -240,6 +240,13 @@ export function getDetailsFromGeoJSON(geojson) {
detailsCount: +geojson.count,
detailsType: geojson.praxisDataType,
}
} else if (geojson?.praxisDataType) {
return {
details: [],
detailsZip: geojson.code || null,
detailsCount: geojson.count,
detailsType: geojson.praxisDataType,
}
} else {
return {
details: null,
Expand Down

0 comments on commit 05c5fff

Please sign in to comment.