-
Notifications
You must be signed in to change notification settings - Fork 514
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5707 from caugner/plus-menu-add-faq-link
chore(plus): add FAQ + and move {feature => features}/*
- Loading branch information
Showing
10 changed files
with
309 additions
and
117 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,67 @@ | ||
import React, { ReactElement } from "react"; | ||
import useSWR from "swr"; | ||
import { CRUD_MODE } from "../../constants"; | ||
import { TOC } from "../../document/organisms/toc"; | ||
import { PageNotFound } from "../../page-not-found"; | ||
import "./index.scss"; | ||
|
||
interface StaticPageProps { | ||
locale: string; | ||
slug: string; | ||
initialData?: any; | ||
title?: string; | ||
sidebarHeader?: ReactElement; | ||
} | ||
|
||
function StaticPage({ | ||
locale, | ||
slug, | ||
initialData = undefined, | ||
title = "MDN", | ||
sidebarHeader = <></>, | ||
}: StaticPageProps) { | ||
const baseURL = `/${locale.toLowerCase()}/${slug}`; | ||
const featureJSONUrl = `${baseURL}/index.json`; | ||
const { data: { hyData } = {} } = useSWR<any>( | ||
featureJSONUrl, | ||
async (url) => { | ||
const response = await fetch(url); | ||
if (!response.ok) { | ||
const text = await response.text(); | ||
throw new Error(`${response.status} on ${url}: ${text}`); | ||
} | ||
return await response.json(); | ||
}, | ||
{ | ||
initialData, | ||
revalidateOnFocus: CRUD_MODE, | ||
} | ||
); | ||
React.useEffect(() => { | ||
window.scrollTo(0, 0); | ||
}, []); | ||
React.useEffect(() => { | ||
const pageTitle = hyData && `${hyData.title} | ${title}`; | ||
document.title = pageTitle; | ||
}, [hyData, title]); | ||
|
||
if (!hyData) { | ||
return <PageNotFound />; | ||
} | ||
|
||
return ( | ||
<div className="static-page container"> | ||
<div className="static-sidebar"> | ||
{sidebarHeader || null} | ||
{(hyData.toc?.length && <TOC toc={hyData.toc} />) || null} | ||
</div> | ||
<article className="static-content"> | ||
{hyData.sections.map((section) => ( | ||
<section dangerouslySetInnerHTML={{ __html: section }}></section> | ||
))} | ||
</article> | ||
</div> | ||
); | ||
} | ||
|
||
export default StaticPage; |
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
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,23 @@ | ||
import { useParams } from "react-router-dom"; | ||
import StaticPage from "../../homepage/static-page"; | ||
import { Button } from "../../ui/atoms/button"; | ||
|
||
function StaticPlusPage({ slug, ...props }) { | ||
const { locale } = useParams(); | ||
|
||
return ( | ||
<StaticPage | ||
{...{ | ||
locale, | ||
slug: `plus/${slug}`, | ||
title: "MDN Plus", | ||
sidebarHeader: ( | ||
<Button href={`/${locale}/plus`}>← Back to Overview</Button> | ||
), | ||
initialData: props.hyData ? props : undefined, | ||
}} | ||
/> | ||
); | ||
} | ||
|
||
export default StaticPlusPage; |
Oops, something went wrong.