Files
freeCodeCamp/client/utils/gatsby/layout-selector.tsx

46 lines
1.1 KiB
TypeScript
Raw Permalink Normal View History

2019-02-28 15:44:35 +00:00
import React from 'react';
2019-02-28 15:44:35 +00:00
import {
CertificationLayout,
DefaultLayout
2019-02-28 15:44:35 +00:00
} from '../../src/components/layouts';
import FourOhFourPage from '../../src/pages/404';
import { isChallenge } from '../../src/utils/path-parsers';
2019-02-28 15:44:35 +00:00
interface LayoutSelectorProps {
element: JSX.Element;
props: { location: { pathname: string } };
}
export default function layoutSelector({
element,
props
}: LayoutSelectorProps): JSX.Element {
2019-02-28 15:44:35 +00:00
const {
location: { pathname }
} = props;
if (element.type === FourOhFourPage) {
return (
<DefaultLayout pathname={pathname} showFooter={true}>
{element}
</DefaultLayout>
);
} else if (/\/certification\//.test(pathname)) {
return (
<CertificationLayout pathname={pathname}>{element}</CertificationLayout>
);
} else if (isChallenge(pathname)) {
2019-02-28 15:44:35 +00:00
return (
<DefaultLayout pathname={pathname} showFooter={false}>
{element}
</DefaultLayout>
);
} else {
return (
<DefaultLayout pathname={pathname} showFooter={true}>
{element}
</DefaultLayout>
);
2019-02-28 15:44:35 +00:00
}
}