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

fix(search): have agency-specific results from agency page #192

Merged
merged 1 commit into from
Sep 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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