From c01aef866ebccbe36e1bd50d424d799d0f9c731d Mon Sep 17 00:00:00 2001 From: Jerel Miller Date: Wed, 2 Dec 2020 22:32:06 -0800 Subject: [PATCH] fix: update main layout to use new layout components --- src/components/Sidebar.js | 69 ----------------- src/layouts/MainLayout.js | 157 +++++++++++++------------------------- src/layouts/index.js | 2 +- 3 files changed, 56 insertions(+), 172 deletions(-) delete mode 100644 src/components/Sidebar.js diff --git a/src/components/Sidebar.js b/src/components/Sidebar.js deleted file mode 100644 index 3307416c6..000000000 --- a/src/components/Sidebar.js +++ /dev/null @@ -1,69 +0,0 @@ -import React, { useState } from 'react'; -import PropTypes from 'prop-types'; -import { css } from '@emotion/core'; -import { Link } from 'gatsby'; -import Navigation from './Navigation'; -import { Logo, SearchInput } from '@newrelic/gatsby-theme-newrelic'; - -const Sidebar = ({ className }) => { - const [searchTerm, setSearchTerm] = useState(''); - - return ( - - ); -}; - -Sidebar.propTypes = { - className: PropTypes.string, -}; - -export default Sidebar; diff --git a/src/layouts/MainLayout.js b/src/layouts/MainLayout.js index 6e8ca43f4..b4f40d9f5 100644 --- a/src/layouts/MainLayout.js +++ b/src/layouts/MainLayout.js @@ -4,68 +4,31 @@ import { css } from '@emotion/core'; import { CookieConsentDialog, GlobalHeader, - GlobalFooter, + Layout, + Logo, + SearchInput, + useLayout, } from '@newrelic/gatsby-theme-newrelic'; -import { graphql, useStaticQuery } from 'gatsby'; import MobileHeader from '../components/MobileHeader'; -import Sidebar from '../components/Sidebar'; +import { Link } from 'gatsby'; +import Navigation from '../components/Navigation'; import '../components/styles.scss'; -import usePageContext from '../hooks/usePageContext'; import { useLocation } from '@reach/router'; -import { useMeasure } from 'react-use'; - -const MainLayout = ({ children }) => { - const { - site: { layout, siteMetadata }, - } = useStaticQuery(graphql` - query { - site { - layout { - contentPadding - maxWidth - } - siteMetadata { - repository - } - } - } - `); +const MainLayout = ({ children, pageContext }) => { + const { contentPadding, maxWidth } = useLayout(); const location = useLocation(); - const { fileRelativePath } = usePageContext(); - const [headerRef, { height }] = useMeasure(); + const [searchTerm, setSearchTerm] = useState(''); + const { fileRelativePath } = pageContext; const [isMobileNavOpen, setIsMobileNavOpen] = useState(false); - const isComponentDoc = fileRelativePath.includes( - 'src/markdown-pages/components' - ); - const editUrl = isComponentDoc - ? null - : `${siteMetadata.repository}/blob/main/${fileRelativePath}`; useEffect(() => { setIsMobileNavOpen(false); }, [location.pathname]); return ( -
-
- -
+ <> + { isOpen={isMobileNavOpen} toggle={() => setIsMobileNavOpen(!isMobileNavOpen)} /> -
- +
+ + -
-
- {children} -
- -
+ @media screen and (max-width: 760px) { + width: 160px; + } + `} + /> + + setSearchTerm('')} + onChange={(e) => setSearchTerm(e.target.value)} + value={searchTerm} + /> +
+ + + {children} + + -
+ ); }; MainLayout.propTypes = { children: PropTypes.node.isRequired, + pageContext: PropTypes.object.isRequired, }; export default MainLayout; diff --git a/src/layouts/index.js b/src/layouts/index.js index d002b0d68..6f1c7ad57 100644 --- a/src/layouts/index.js +++ b/src/layouts/index.js @@ -6,7 +6,7 @@ const Layout = ({ children, pageContext }) => { if (pageContext.fileRelativePath.match(/404/)) { return children; } - return {children}; + return {children}; }; Layout.propTypes = {