Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VACMS-16986 Resources & Support landing and taxonomy pages - add web components #28236

Merged
merged 4 commits into from
Mar 4, 2024
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
// Node modules.
import React, { useEffect, useState, useCallback } from 'react';
import { VaPagination } from '@department-of-veterans-affairs/component-library/dist/react-bindings';
import URLSearchParams from 'url-search-params';
import { focusElement } from 'platform/utilities/ui';

Check warning on line 4 in src/applications/resources-and-support/components/ResourcesAndSupportSearchApp.jsx

View workflow job for this annotation

GitHub Actions / Linting (Files Changed)

src/applications/resources-and-support/components/ResourcesAndSupportSearchApp.jsx:4:1:Importing from platform via platform/utilities is deprecated. Import from @department-of-veterans-affairs/platform-utilities instead or check babel.config.json for an alias to the import.
import { getAppUrl } from 'platform/utilities/registry-helpers';

Check warning on line 5 in src/applications/resources-and-support/components/ResourcesAndSupportSearchApp.jsx

View workflow job for this annotation

GitHub Actions / Linting (Files Changed)

src/applications/resources-and-support/components/ResourcesAndSupportSearchApp.jsx:5:1:Importing from platform via platform/utilities is deprecated. Import from @department-of-veterans-affairs/platform-utilities instead or check babel.config.json for an alias to the import.
// Relative imports.
import SearchBar from './SearchBar';
import SearchResultList from './SearchResultList';
import useArticleData from '../hooks/useArticleData';
Expand All @@ -17,6 +15,14 @@
const [query, setQuery] = useState('');
const [page, setPage] = useState(1);
const [results] = useGetSearchResults(articles, query, page);
const [previousValue, setPreviousValue] = useState('');

useEffect(
() => {
setPreviousValue(userInput);
},
[userInput],
);

const totalPages = Math.ceil(results.length / RESULTS_PER_PAGE);

Expand All @@ -29,6 +35,7 @@

const searchParams = new URLSearchParams(window.location.search);
const queryFromUrl = searchParams.get('query');

if (queryFromUrl) {
setUserInput(queryFromUrl);
setQuery(queryFromUrl);
Expand All @@ -39,14 +46,8 @@
[articles, setUserInput, setQuery],
);

const onSearch = useCallback(
const setSearchData = useCallback(
() => {
const queryParams = new URLSearchParams();
queryParams.set('query', userInput);

const newUrl = `${window.location.pathname}?${queryParams}`;
history.replaceState({}, '', newUrl);

setPage(1);
setQuery(userInput);
focusElement('#pagination-summary');
Expand Down Expand Up @@ -84,9 +85,10 @@
We didn’t find any resources and support articles for "
<strong>{query}</strong>
." Try using different words or{' '}
<a href={`${getAppUrl('search')}/?query=${encodeURIComponent(query)}`}>
search all of VA.gov
</a>
<va-link
href={`${getAppUrl('search')}/?query=${encodeURIComponent(query)}`}
text="search all of VA.gov"
/>
.
</>
);
Expand All @@ -96,7 +98,7 @@
<div className="usa-grid usa-grid-full">
<div className="usa-content vads-u-margin-bottom--0 medium-screen:vads-u-margin-bottom--3">
{errorMessage && (
<va-alert status="error">
<va-alert status="error" uswds>
<h3 slot="headline">Something went wrong</h3>
{errorMessage}
</va-alert>
Expand All @@ -108,12 +110,13 @@
Resources and Support Search Results
</h1>
<SearchBar
onSearch={onSearch}
userInput={userInput}
onInputChange={setUserInput}
previousValue={previousValue}
setSearchData={setSearchData}
/>
<h2
className="vads-u-padding-x--1 vads-u-font-family--sans large-screen:vads-u-padding-x--0 vads-u-font-size--base vads-u-margin-top--0 vads-u-margin-bottom--2p5 vads-u-font-weight--normal"
className="vads-u-max-width--full vads-u-margin-x--1 vads-u-font-family--sans vads-u-margin-top--2 medium-screen:vads-u-margin-top--0 large-screen:vads-u-padding-x--0 vads-u-font-size--base vads-u-margin-bottom--2p5 vads-u-font-weight--normal"
id="pagination-summary"
>
{paginationSummary}
Expand Down