Skip to content

Commit

Permalink
Tweaks for sort order
Browse files Browse the repository at this point in the history
  • Loading branch information
apricot13 committed Jul 9, 2024
1 parent fb1b47a commit 1d6287d
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 12 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 near Example2"
"Showing 1-20 out of ~2805 results for Example within 20 miles of Example2"
)
})

Expand Down
2 changes: 1 addition & 1 deletion src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,7 @@ const MainContent = ({
)}{" "}
{coverage && (
<>
near <strong>{coverage}</strong>
within 20 miles of <strong>{coverage}</strong>
</>
)}
</>
Expand Down
4 changes: 2 additions & 2 deletions src/components/ServiceCard/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ const Description = styled.p`
`

const ServiceCard = React.forwardRef(
({ id, name, description, ...service }, ref) => {
({ id, name, description, score, ...service }, ref) => {
const { search } = useLocation()
// const [hasRef, setHasRef] = useState(false)

Expand All @@ -71,7 +71,7 @@ const ServiceCard = React.forwardRef(

// <Outer ref={ref} hasRef={hasRef}>
return (
<Outer ref={ref}>
<Outer ref={ref} data-score={score}>
<StyledLink to={`/service/${id}${search}`}>
<Name>{name}</Name>
</StyledLink>
Expand Down
11 changes: 3 additions & 8 deletions src/lib/data-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,16 +96,11 @@ export const removeDuplicateServices = services => {
}

export const sortServices = (services, query) => {
let { keywords, lat, lng, location } = queryString.parse(query)
let { keywords } = 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
// if there is a keyword sort by score
// 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)) {
if (keywords) {
return services.sort((a, b) => new Date(b.score) - new Date(a.score))
} else {
return services.sort(
Expand Down

0 comments on commit 1d6287d

Please sign in to comment.