From 7056028434b06c8e9a5a8c906181a0cbf1151388 Mon Sep 17 00:00:00 2001 From: kewitham Date: Tue, 30 Jan 2024 12:41:08 -0600 Subject: [PATCH] add filter --- assets/js/pagination.js | 7 ++++--- assets/js/utils/renderSearchPage.js | 9 ++++++--- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/assets/js/pagination.js b/assets/js/pagination.js index 7e375cb40..67d70a07c 100644 --- a/assets/js/pagination.js +++ b/assets/js/pagination.js @@ -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); @@ -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'); } diff --git a/assets/js/utils/renderSearchPage.js b/assets/js/utils/renderSearchPage.js index 8660ed2e0..de04447db 100644 --- a/assets/js/utils/renderSearchPage.js +++ b/assets/js/utils/renderSearchPage.js @@ -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; @@ -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: