Skip to content

Commit

Permalink
refactor: load search years from constant
Browse files Browse the repository at this point in the history
  • Loading branch information
pjsier committed Nov 11, 2024
1 parent 979eb4e commit aab41ae
Show file tree
Hide file tree
Showing 6 changed files with 6 additions and 38 deletions.
15 changes: 0 additions & 15 deletions client/src/actions/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,21 +134,6 @@ export function handleDetailedSearchQuery(
}
}

export function handleSearchBarYearsAction(route) {
return async (dispatch) => {
try {
const json = await APISearchQueryFromRoute(route)
dispatch(updateSearchBar({ searchYears: json }))
return json
} catch (err) {
dispatch(triggerFetchError(true))
console.error(
`An error occured searching search bar years. Message: ${err}`
)
}
}
}

export function handleGetPraxisYearsAction(route) {
return async (dispatch) => {
try {
Expand Down
7 changes: 0 additions & 7 deletions client/src/components/Search/SearchContainer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,11 @@ import React, { Component } from "react"
import { connect } from "react-redux"
import { withRouter } from "../../utils/router"
import PropTypes from "prop-types"
import { handleSearchBarYearsAction } from "../../actions/search"
import SearchBar from "./SearchBar"

/* The SearchContainer passes the avaialble years
for selection to SearchBar */
class SearchContainer extends Component {
componentDidMount() {
// load the available years
const yearsRoute = "/api/general?type=available-praxis-years"
this.props.dispatch(handleSearchBarYearsAction(yearsRoute))
}

render() {
return (
<SearchBar
Expand Down
4 changes: 2 additions & 2 deletions client/src/reducers/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ import {
UPDATE_SEARCH_BAR,
UPDATE_ALL_TOTALS,
} from "../actions/search"
import { DEFAULT_YEAR } from "../utils/constants"
import { DEFAULT_YEAR, YEARS } from "../utils/constants"

const initialSearchState = {
searchBar: {
searchYears: null,
searchYears: YEARS.map((year) => ({ year })),
},
searchParams: {
searchType: "all",
Expand Down
4 changes: 4 additions & 0 deletions client/src/utils/constants.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
export const MINIMUM_YEAR = "2015"

export const DEFAULT_YEAR = "2024"

export const YEARS = [
2015, 2016, 2017, 2018, 2019, 2020, 2021, 2022, 2023, 2024,
]
6 changes: 0 additions & 6 deletions server/routes/generalDBSearch.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,6 @@ router.get("/", async (req, res) => {
const { type = null, year = null, code = null } = req.query
let pgData, clientData
switch (type) {
case "available-praxis-years":
pgData = await queries.queryPGDB({
PGDBQueryType: queries.AVAILABLE_PRAXIS_YEARS,
})
clientData = pgData.data
break
case "codes-by-speculator":
pgData = await queries.queryPGDB({
PGDBQueryType: queries.ZIPCODE_PARCEL_COUNT,
Expand Down
8 changes: 0 additions & 8 deletions server/utils/queries.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ const GEOJSON_PARCELS_OWNID = "GEOJSON_PARCELS_OWNID"
const GEOJSON_PARCELS_OWNID_CODE = "GEOJSON_PARCELS_OWNID_CODE"
const GEOJSON_PARCELS_CODE_DISTANCE = "GEOJSON_PARCELS_CODE_DISTANCE"
const DETAILED_RECORD_YEARS = "DETAILED_RECORD_YEARS" // years for a praxis record
const AVAILABLE_PRAXIS_YEARS = "AVAILABLE_PRAXIS_YEARS" // all the available search years
const SPECULATORS_BY_CODE = "SPECULATORS_BY_CODE"
const CODES_BY_SPECULATOR = "CODES_BY_SPECULATOR"
const POINT_CODE = "POINT_CODE" // get the zipcode for a specific point
Expand Down Expand Up @@ -228,12 +227,6 @@ async function queryPGDB({
WHERE parcelno = ${parcelno}`
break

// all the years in the DB to search
case AVAILABLE_PRAXIS_YEARS:
query = SQL`SELECT DISTINCT year FROM parcels
ORDER BY year DESC;`
break

case SPECULATORS_BY_CODE:
query = SQL`SELECT DISTINCT p.own_id, COUNT(*) AS count
FROM parcels AS p
Expand Down Expand Up @@ -361,7 +354,6 @@ module.exports = {
GEOJSON_PARCELS_CODE_DISTANCE,
POINT_CODE,
DETAILED_RECORD_YEARS,
AVAILABLE_PRAXIS_YEARS,
GEOCODE,
REVERSE_GEOCODE,
SPECULATORS_BY_CODE,
Expand Down

0 comments on commit aab41ae

Please sign in to comment.