Skip to content

Commit

Permalink
add filter
Browse files Browse the repository at this point in the history
  • Loading branch information
kewitham committed Jan 30, 2024
1 parent c15c0aa commit 7056028
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
7 changes: 4 additions & 3 deletions assets/js/pagination.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,15 @@ let searchParams = {
query: urlParams.get('query'),
offset: urlParams.get('offset') || 0,
limit: NUMBER_OF_RESULTS,
audience: urlParams.get('audience'),
// audience: urlParams.get('audience'),
};
// Add our total number of results DOM node:
const audience = urlParams.get('audience');
const target = document.getElementById('totalResultsTarget');
const hiddenQueryInput = document.getElementById('hiddenQuery');
hiddenQueryInput.value = urlParams.get('query');
document.querySelectorAll('.usa-checkbox__input').forEach((checkbox) => {
if (checkbox.value == urlParams.get('audience')) {
if (checkbox.value == audience) {
checkbox.setAttribute('data-checked', true);
} else {
checkbox.setAttribute('data-checked', false);
Expand All @@ -34,7 +35,7 @@ Object.keys(searchParams).forEach(function (key) {
function reqLoaded() {
if (this.status === 200) {
let resJSON = JSON.parse(this.responseText);
renderSearchPage(resJSON, urlParams, NUMBER_OF_RESULTS);
renderSearchPage(resJSON, urlParams, NUMBER_OF_RESULTS, audience);
} else {
target.innerHTML = totalResults(-1, 'result');
}
Expand Down
9 changes: 6 additions & 3 deletions assets/js/utils/renderSearchPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import searchResultsTemplate from '../templates/search/searchResultsTemplate';
import totalResults from '../templates/search/totalResultsTemplate';
import clickTracking from '../click-tracking';

export default function renderSearchPage(searchResults, urlParams, numberOfResults) {
export default function renderSearchPage(searchResults, urlParams, numberOfResults, audience = null) {
const results = searchResults;
const graphicResults = results.graphic_best_bets;
const textResults = results.text_best_bets;
Expand Down Expand Up @@ -48,8 +48,11 @@ export default function renderSearchPage(searchResults, urlParams, numberOfResul
const pagination_list = document.querySelectorAll('ol.usa-pagination__list')[0];
// Put the fetched results into a list, and render in the DOM:
webResults.forEach(function (item) {
renderSearchResults(searchResultsTemplate(item));
});
if (!audience || item.url.includes(audience)) {
renderSearchResults(searchResultsTemplate(item));
}
return null
}).filter(x => !!x);
// Set up click tracking for search.gov:
clickTracking();
// List the total number of results:
Expand Down

0 comments on commit 7056028

Please sign in to comment.