-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
## Summary Fixes #1382 ### Time to review: 5 min ## Changes proposed - Move search page over to app router
- Loading branch information
Showing
15 changed files
with
398 additions
and
152 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
/// <reference types="next" /> | ||
/// <reference types="next/image-types/global" /> | ||
/// <reference types="next/navigation-types/compat/navigation" /> | ||
|
||
// NOTE: This file should not be edited | ||
// see https://nextjs.org/docs/basic-features/typescript for more information. |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import "src/styles/styles.scss"; | ||
|
||
import Layout from "src/components/AppLayout"; | ||
/** | ||
* Root layout component, wraps all pages. | ||
* @see https://nextjs.org/docs/app/api-reference/file-conventions/layout | ||
*/ | ||
import { Metadata } from "next"; | ||
|
||
export const metadata: Metadata = { | ||
icons: [`${process.env.NEXT_PUBLIC_BASE_PATH ?? ""}/img/favicon.ico`], | ||
}; | ||
|
||
interface LayoutProps { | ||
children: React.ReactNode; | ||
|
||
// TODO: use for i18n when ready | ||
// params: { | ||
// locale: string; | ||
// }; | ||
} | ||
|
||
export default function RootLayout({ children }: LayoutProps) { | ||
return ( | ||
<html lang="en"> | ||
<body> | ||
{/* Separate layout component for the inner-body UI elements since Storybook | ||
and tests trip over the fact that this file renders an <html> tag */} | ||
|
||
{/* TODO: Add locale="english" prop when ready for i18n */} | ||
<Layout>{children}</Layout> | ||
</body> | ||
</html> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
"use client"; | ||
|
||
import React, { useState } from "react"; | ||
import { | ||
SearchFetcher, | ||
fetchSearchOpportunities, | ||
} from "../../services/searchfetcher/SearchFetcher"; | ||
|
||
import { APISearchFetcher } from "../../services/searchfetcher/APISearchFetcher"; | ||
import { MockSearchFetcher } from "../../services/searchfetcher/MockSearchFetcher"; | ||
import { Opportunity } from "../../types/searchTypes"; | ||
import PageNotFound from "../../pages/404"; | ||
import { useFeatureFlags } from "src/hooks/useFeatureFlags"; | ||
|
||
const useMockData = true; | ||
const searchFetcher: SearchFetcher = useMockData | ||
? new MockSearchFetcher() | ||
: new APISearchFetcher(); | ||
|
||
// TODO: use for i18n when ready | ||
// interface RouteParams { | ||
// locale: string; | ||
// } | ||
|
||
// interface SearchProps { | ||
// initialOpportunities: Opportunity[]; | ||
// } | ||
|
||
export default function Search() { | ||
const { featureFlagsManager, mounted } = useFeatureFlags(); | ||
const [searchResults, setSearchResults] = useState<Opportunity[]>([]); | ||
|
||
const handleButtonClick = (event: React.MouseEvent<HTMLButtonElement>) => { | ||
event.preventDefault(); | ||
performSearch().catch((e) => console.log(e)); | ||
}; | ||
|
||
const performSearch = async () => { | ||
const opportunities = await fetchSearchOpportunities(searchFetcher); | ||
setSearchResults(opportunities); | ||
}; | ||
|
||
if (!mounted) return null; | ||
if (!featureFlagsManager.isFeatureEnabled("showSearchV0")) { | ||
return <PageNotFound />; | ||
} | ||
|
||
return ( | ||
<> | ||
<button onClick={handleButtonClick}>Update Results</button> | ||
<ul> | ||
{searchResults.map((opportunity) => ( | ||
<li key={opportunity.id}> | ||
{opportunity.id}, {opportunity.title} | ||
</li> | ||
))} | ||
</ul> | ||
</> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import Footer from "./Footer"; | ||
import GrantsIdentifier from "./GrantsIdentifier"; | ||
import Header from "./Header"; | ||
|
||
type Props = { | ||
children: React.ReactNode; | ||
// TODO: pass locale into Layout when we setup i18n | ||
// locale?: string; | ||
}; | ||
|
||
const Layout = ({ children }: Props) => { | ||
return ( | ||
// Stick the footer to the bottom of the page | ||
<div className="display-flex flex-column minh-viewport"> | ||
<a className="usa-skipnav" href="#main-content"> | ||
{"skip_to_main"} | ||
</a> | ||
<Header /> | ||
<main id="main-content">{children}</main> | ||
<Footer /> | ||
<GrantsIdentifier /> | ||
</div> | ||
); | ||
}; | ||
|
||
export default Layout; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
"use client"; | ||
|
||
import { assetPath } from "src/utils/assetPath"; | ||
|
||
import { useTranslation } from "next-i18next"; | ||
|
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { render, screen } from "@testing-library/react"; | ||
import { axe } from "jest-axe"; | ||
|
||
import AppLayout from "src/components/AppLayout"; | ||
|
||
describe("AppLayout", () => { | ||
it("renders children in main section", () => { | ||
render( | ||
<AppLayout> | ||
<h1>child</h1> | ||
</AppLayout>, | ||
); | ||
|
||
const header = screen.getByRole("heading", { name: /child/i, level: 1 }); | ||
|
||
expect(header).toBeInTheDocument(); | ||
}); | ||
|
||
it("passes accessibility scan", async () => { | ||
const { container } = render( | ||
<AppLayout> | ||
<h1>child</h1> | ||
</AppLayout>, | ||
); | ||
const results = await axe(container); | ||
|
||
expect(results).toHaveNoViolations(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters