-
-
Notifications
You must be signed in to change notification settings - Fork 229
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
188 additions
and
88 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
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,49 @@ | ||
import * as React from "react" | ||
import { useState, useRef, useEffect } from "react" | ||
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome" | ||
import { faSearch, faCircleXmark } from "@fortawesome/free-solid-svg-icons" | ||
|
||
export default function NotFoundPageForm() { | ||
const [searchQuery, setSearchQuery] = useState("") | ||
const inputRef = useRef<HTMLInputElement>(null) | ||
|
||
useEffect(() => { | ||
// Browser keeps the DOM input value on page refresh. | ||
const domValue = inputRef.current?.value | ||
if (domValue) setSearchQuery(domValue) | ||
}, []) | ||
|
||
return ( | ||
<form className="NotFoundPageForm" action="/search" method="GET"> | ||
<input | ||
id="search_q" | ||
className="NotFoundPageForm__input" | ||
ref={inputRef} | ||
type="search" | ||
placeholder="Search..." | ||
name="q" | ||
value={searchQuery} | ||
onChange={(e) => setSearchQuery(e.target.value)} | ||
required | ||
autoFocus | ||
/> | ||
{searchQuery && ( | ||
<button | ||
className="NotFoundPageForm__button NotFoundPageForm__reset-button" | ||
type="reset" | ||
title="Clear search" | ||
onClick={() => setSearchQuery("")} | ||
> | ||
<FontAwesomeIcon icon={faCircleXmark} /> | ||
</button> | ||
)} | ||
<button | ||
className="NotFoundPageForm__button NotFoundPageForm__submit-button" | ||
type="submit" | ||
title="Search" | ||
> | ||
<FontAwesomeIcon icon={faSearch} /> | ||
</button> | ||
</form> | ||
) | ||
} |
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,14 +1,14 @@ | ||
import * as React from "react" | ||
import { hydrate } from "react-dom" | ||
import NotFoundPageForm from "./NotFoundPageForm.js" | ||
import { SiteAnalytics } from "./SiteAnalytics.js" | ||
|
||
const analytics = new SiteAnalytics() | ||
|
||
export function runNotFoundPage() { | ||
const query = window.location.pathname.split("/") | ||
const searchInput = document.getElementById("search_q") as HTMLInputElement | ||
if (searchInput && query.length) | ||
searchInput.value = decodeURIComponent(query[query.length - 1]).replace( | ||
/[\-_\+|]/g, | ||
" " | ||
) | ||
analytics.logPageNotFoundError(window.location.href) | ||
hydrate( | ||
<NotFoundPageForm />, | ||
document.getElementById("not-found-page-form") | ||
) | ||
} |
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