import React, { useState, useEffect } from 'react'
import { useLocation } from '@reach/router'
import Amplify from 'aws-amplify'
import styled, { ThemeProvider } from 'styled-components'
import { Helmet } from 'react-helmet'
import { graphql, useStaticQuery } from 'gatsby'
import NavBar from '../NavBar'
import theme, { Index } from '../../theme'
import awsmobile from '../../../aws-exports'
import Footer from '../Footer'
Amplify.configure(awsmobile)
type SEOProps = {
title?: string
description?: string
image?: string
article?: boolean
}
const SEO = ({ title, description, image, article }: SEOProps) => {
const { pathname } = useLocation()
const { site } = useStaticQuery(query)
const {
defaultTitle,
titleTemplate,
defaultDescription,
siteUrl,
defaultImage,
twitterUsername,
} = site.siteMetadata
const seo = {
title: title || defaultTitle,
description: description || defaultDescription,
image: `${siteUrl}${image || defaultImage}`,
url: `${siteUrl}${pathname}`,
}
return (
{seo.url && }
{(article ? true : null) && (
)}
{seo.title && }
{seo.description && (
)}
{seo.image && }
{twitterUsername && (
)}
{seo.title && }
{seo.description && (
)}
{seo.image && }
)
}
const query = graphql`
query SEO {
site {
siteMetadata {
defaultTitle: title
titleTemplate
defaultDescription: description
siteUrl: url
defaultImage: image
twitterUsername
}
}
}
`
const TopSpacing = styled.div<{ height: number }>`
min-height: ${({ height }) => height}px;
`
type LayoutProps = {
children: React.ReactNode
seo?: SEOProps
overrideTheme?: Index
removePaddingTop?: boolean
}
const Layout = ({
children,
seo,
overrideTheme,
removePaddingTop = false,
}: LayoutProps) => {
const [navBarHeight, setNavBarHeight] = useState(0)
const [usedTheme, setUsedTheme] = useState(overrideTheme || theme)
useEffect(() => {
setUsedTheme(overrideTheme || theme)
}, [overrideTheme])
return (
{
return
}
: (height) => setNavBarHeight(height)
}
/>
{children}
)
}
export default Layout