diff --git a/cypress/e2e/results_list.cy.js b/cypress/e2e/results_list.cy.js
index 3f7a7e7..139a45a 100644
--- a/cypress/e2e/results_list.cy.js
+++ b/cypress/e2e/results_list.cy.js
@@ -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"
)
})
diff --git a/src/App.jsx b/src/App.jsx
index 20812bd..21ec1cf 100644
--- a/src/App.jsx
+++ b/src/App.jsx
@@ -482,7 +482,8 @@ const MainContent = ({
)}{" "}
{coverage && (
<>
- within 20 miles of {coverage}
+ within {theme.proximity / 1609.34} miles of{" "}
+ {coverage}
>
)}
>
diff --git a/src/lib/data-helpers.js b/src/lib/data-helpers.js
index faddfa5..c5c180c 100644
--- a/src/lib/data-helpers.js
+++ b/src/lib/data-helpers.js
@@ -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)
+ )
}
}
diff --git a/src/themes/theme_generator.jsx b/src/themes/theme_generator.jsx
index bd6aad7..095d078 100644
--- a/src/themes/theme_generator.jsx
+++ b/src/themes/theme_generator.jsx
@@ -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,