Skip to content

Commit

Permalink
VACMS-16986 Resources & Support landing page web components
Browse files Browse the repository at this point in the history
  • Loading branch information
randimays committed Feb 28, 2024
1 parent 2911a0c commit f5d1673
Show file tree
Hide file tree
Showing 4 changed files with 138 additions and 214 deletions.
@@ -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.

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.

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,11 @@ const ResourcesAndSupportSearchApp = () => {
const [query, setQuery] = useState('');
const [page, setPage] = useState(1);
const [results] = useGetSearchResults(articles, query, page);
const [previousValue, setPreviousValue] = useState('');

useEffect(() => {

Check warning on line 20 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:20:3:React Hook useEffect contains a call to 'setPreviousValue'. Without a list of dependencies, this can lead to an infinite chain of updates. To fix this, pass [userInput] as a second argument to the useEffect Hook.

Check warning on line 20 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:20:3:React Hook useEffect contains a call to 'setPreviousValue'. Without a list of dependencies, this can lead to an infinite chain of updates. To fix this, pass [userInput] as a second argument to the useEffect Hook.
setPreviousValue(userInput);
});

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

Expand All @@ -29,6 +32,7 @@ const ResourcesAndSupportSearchApp = () => {

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

if (queryFromUrl) {
setUserInput(queryFromUrl);
setQuery(queryFromUrl);
Expand All @@ -39,14 +43,8 @@ const ResourcesAndSupportSearchApp = () => {
[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 +82,10 @@ const ResourcesAndSupportSearchApp = () => {
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 +95,7 @@ const ResourcesAndSupportSearchApp = () => {
<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 +107,13 @@ const ResourcesAndSupportSearchApp = () => {
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

0 comments on commit f5d1673

Please sign in to comment.