1
0
mirror of https://github.com/kremalicious/portfolio.git synced 2024-06-30 05:31:44 +02:00
This commit is contained in:
Matthias Kretschmann 2019-04-28 22:30:20 +02:00
parent 0bc65e3184
commit 27cf2e9012
Signed by: m
GPG Key ID: 606EEEF3C479A91F
5 changed files with 43 additions and 55 deletions

View File

@ -1,7 +1,10 @@
import './src/styles/global.scss'
import React from 'react' import React from 'react'
import AppProvider from './src/store/Provider' import PropTypes from 'prop-types'
import wrapPageElementWithTransition from './src/helpers/wrapPageElement' import AppProvider from './src/store/AppProvider'
import wrapPageElementWithLayout from './src/helpers/wrapPageElement'
// Global styles
import './src/styles/global.scss'
// IntersectionObserver polyfill for gatsby-image (Safari, IE) // IntersectionObserver polyfill for gatsby-image (Safari, IE)
if (typeof window !== 'undefined' && !window.IntersectionObserver) { if (typeof window !== 'undefined' && !window.IntersectionObserver) {
@ -9,10 +12,13 @@ if (typeof window !== 'undefined' && !window.IntersectionObserver) {
} }
// React Context in Browser // React Context in Browser
// eslint-disable-next-line
export const wrapRootElement = ({ element }) => { export const wrapRootElement = ({ element }) => {
return <AppProvider>{element}</AppProvider> return <AppProvider>{element}</AppProvider>
} }
// Page Transitions & Layout wrapRootElement.propTypes = {
export const wrapPageElement = wrapPageElementWithTransition element: PropTypes.any
}
// Layout with Page Transitions
export const wrapPageElement = wrapPageElementWithLayout

View File

@ -1,7 +1,7 @@
import React from 'react' import React from 'react'
import { renderToString } from 'react-dom/server' import { renderToString } from 'react-dom/server'
import AppProvider from './src/store/Provider' import AppProvider from './src/store/AppProvider'
import wrapPageElementWithTransition from './src/helpers/wrapPageElement' import wrapPageElementWithLayout from './src/helpers/wrapPageElement'
export const replaceRenderer = ({ bodyComponent, replaceBodyHTMLString }) => { export const replaceRenderer = ({ bodyComponent, replaceBodyHTMLString }) => {
// React Context in SSR/build // React Context in SSR/build
@ -9,5 +9,5 @@ export const replaceRenderer = ({ bodyComponent, replaceBodyHTMLString }) => {
replaceBodyHTMLString(renderToString(<ConnectedBody />)) replaceBodyHTMLString(renderToString(<ConnectedBody />))
} }
// Page Transitions & Layout // Layout with Page Transitions
export const wrapPageElement = wrapPageElementWithTransition export const wrapPageElement = wrapPageElementWithLayout

View File

@ -14,9 +14,6 @@ import styles from './Layout.module.scss'
// whyDidYouUpdate(React) // whyDidYouUpdate(React)
// } // }
const timeout = 250
const RoutesContainer = posed.div(fadeIn)
const query = graphql` const query = graphql`
query { query {
contentYaml { contentYaml {
@ -25,42 +22,8 @@ const query = graphql`
} }
` `
const LayoutMarkup = ({ children, data, location }) => { const timeout = 200
const { allowedHosts } = data.contentYaml const RoutesContainer = posed.div(fadeIn)
const isHomepage = location.pathname === '/'
return (
<>
<Typekit />
<HostnameCheck allowedHosts={allowedHosts} />
<PoseGroup animateOnMount={true}>
<RoutesContainer
key={location.pathname}
delay={timeout}
delayChildren={timeout}
>
<Header minimal={!isHomepage} />
<main className={styles.screen}>{children}</main>
</RoutesContainer>
</PoseGroup>
<Footer />
</>
)
}
LayoutMarkup.propTypes = {
children: PropTypes.any.isRequired,
data: PropTypes.shape({
contentYaml: PropTypes.shape({
allowedHosts: PropTypes.array.isRequired
}).isRequired
}).isRequired,
location: PropTypes.shape({
pathname: PropTypes.string.isRequired
}).isRequired
}
export default class Layout extends PureComponent { export default class Layout extends PureComponent {
static propTypes = { static propTypes = {
@ -72,15 +35,34 @@ export default class Layout extends PureComponent {
render() { render() {
const { children, location } = this.props const { children, location } = this.props
const isHomepage = location.pathname === '/'
return ( return (
<StaticQuery <StaticQuery
query={query} query={query}
render={data => ( render={data => {
<LayoutMarkup data={data} location={location}> const { allowedHosts } = data.contentYaml
{children}
</LayoutMarkup> return (
)} <>
<Typekit />
<HostnameCheck allowedHosts={allowedHosts} />
<PoseGroup animateOnMount={true}>
<RoutesContainer
key={location.pathname}
delay={timeout}
delayChildren={timeout}
>
<Header minimal={!isHomepage} />
<main className={styles.screen}>{children}</main>
</RoutesContainer>
</PoseGroup>
<Footer />
</>
)
}}
/> />
) )
} }

View File

@ -1,6 +1,6 @@
import React from 'react' import React from 'react'
import { render } from 'react-testing-library' import { render } from 'react-testing-library'
import AppProvider from './Provider.jsx' import AppProvider from './AppProvider.jsx'
describe('AppProvider', () => { describe('AppProvider', () => {
it('renders correctly', () => { it('renders correctly', () => {