Skip to content

Commit

Permalink
Merge pull request #142 from wearefuturegov/develop
Browse files Browse the repository at this point in the history
staging deploy
  • Loading branch information
apricot13 authored Jul 27, 2024
2 parents a45803b + bf997a3 commit b9e4939
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 16 deletions.
2 changes: 1 addition & 1 deletion cypress/e2e/results_list.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ describe("Results list page", () => {
cy.wait("@searchForServices")

cy.get("p").contains(
"Showing 1-20 out of ~2805 results for Example within 20 miles of Example2"
"Showing 1-20 out of ~2805 results for Example within 5 miles of Example2"
)
})

Expand Down
3 changes: 2 additions & 1 deletion src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,8 @@ const MainContent = ({
)}{" "}
{coverage && (
<>
within 20 miles of <strong>{coverage}</strong>
within {theme.proximity / 1609.34} miles of{" "}
<strong>{coverage}</strong>
</>
)}
</>
Expand Down
48 changes: 34 additions & 14 deletions src/lib/data-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,21 +95,41 @@ export const removeDuplicateServices = services => {
)
}

export const sortServices = (services, query) => {
/**
* tells us the query type to help with sorting
*/
const getQueryType = query => {
let { keywords, lat, lng, location } = queryString.parse(query)
// sorting
// if there is a location then sort by distance_away
// if there is a keyword and no location then the order matters
// otherwise sort by updated_at
if (!keywords && (lat || lng || location)) {
return services.sort(
(a, b) => new Date(a.distance_away) - new Date(b.distance_away)
)
} else if (keywords && !(lat || lng || location)) {
return services.sort((a, b) => new Date(b.score) - new Date(a.score))
const hasLocation = lat || lng || location
if (keywords && !hasLocation) {
return "keyword"
} else if (keywords === undefined && hasLocation) {
return "location"
} else if (keywords && hasLocation) {
return "keyword_location"
} else {
return services.sort(
(a, b) => new Date(b.updated_at) - new Date(a.updated_at)
)
return undefined
}
}

/**
* We only do this because we're returning multiple queries
* @param {*} services
* @param {*} query
* @returns
*/
export const sortServices = (services, query) => {
const queryType = getQueryType(query)
switch (queryType) {
case "location":
return services.sort((a, b) => a.distance_away - b.distance_away)
case "keyword_location":
return services.sort((a, b) => a.distance_away - b.distance_away)
case "keyword":
return services.sort((a, b) => b.score - a.score)
default:
return services.sort(
(a, b) => new Date(b.updated_at) - new Date(a.updated_at)
)
}
}
1 change: 1 addition & 0 deletions src/themes/theme_generator.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ const generate_theme = (vars, theme_vars) => {
slug: vars.slug,
title: vars.hasOwnProperty("title") ? vars.title : "",
parentTaxonomySlug: process.env.REACT_APP_PARENT_TAXONOMY_SLUG || false,
proximity: vars.hasOwnProperty("proximity") ? vars.proximity : 5 * 1609.34, // miles x 1609.34 = Distance in meters
resultsPerPage: vars.hasOwnProperty("resultsPerPage")
? vars.resultsPerPage
: 20,
Expand Down

0 comments on commit b9e4939

Please sign in to comment.