Skip to content
This repository has been archived by the owner on Jul 24, 2024. It is now read-only.

Commit

Permalink
fix(search): have agency-specific results from agency page
Browse files Browse the repository at this point in the history
If a user is searching from an agency page, the user expects to see
results specific to that agency, so pass this to the SearchResults
component so that the appropriate posts are fetched for searching
  • Loading branch information
LoneRifle committed Sep 1, 2021
1 parent 12f2be1 commit b066a6c
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 8 deletions.
5 changes: 4 additions & 1 deletion client/src/components/SearchBox/SearchBox.component.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,10 @@ const SearchBox = ({ placeholder, value, handleSubmit }) => {
if (!handleSubmit) {
handleSubmit = (data) => {
sendSearchEventToAnalytics(data[name])
history.push(`/questions?search=${data[name]}`)
history.push(
`/questions?search=${data[name]}` +
(agencyShortName ? `&agency=${agencyShortName}` : ''),
)
}
}

Expand Down
17 changes: 11 additions & 6 deletions client/src/pages/SearchResults/SearchResults.component.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,23 @@ import PostItem from '../../components/PostItem/PostItem.component'
import SearchBox from '../../components/SearchBox/SearchBox.component'
import { Spacer } from '@chakra-ui/react'
import Spinner from '../../components/Spinner/Spinner.component'
import { listPosts, LIST_POSTS_QUERY_KEY } from '../../services/PostService'
import {
listPosts,
LIST_POSTS_FOR_SEARCH_QUERY_KEY,
} from '../../services/PostService'
import './SearchResults.styles.scss'
import { sortByCreatedAt } from '../../util/date'

const SearchResults = () => {
const { data, isLoading } = useQuery([LIST_POSTS_QUERY_KEY], () =>
listPosts(),
const { search } = useLocation()
const searchParams = new URLSearchParams(search)
const searchQuery = searchParams.get('search') ?? ''
const agency = searchParams.get('agency')
const { data, isLoading } = useQuery(
[LIST_POSTS_FOR_SEARCH_QUERY_KEY, agency],
listPosts(undefined, agency),
)

let searchQuery =
new URLSearchParams(useLocation().search).get('search') ?? ''

const foundPosts = new Fuse(data?.posts ?? [], {
keys: ['title', 'description'],
})
Expand Down
2 changes: 1 addition & 1 deletion client/src/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const HomePageComponent = withPageTitle({

const SearchResultsComponent = withPageTitle({
component: SearchResults,
title: 'All Questions - AskGov',
title: 'Search Results - AskGov',
})

const LoginComponent = withPageTitle({
Expand Down

0 comments on commit b066a6c

Please sign in to comment.