1
0
mirror of https://github.com/kremalicious/portfolio.git synced 2025-02-14 21:10:41 +01: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,10 +22,27 @@ const query = graphql`
} }
` `
const LayoutMarkup = ({ children, data, location }) => { const timeout = 200
const { allowedHosts } = data.contentYaml const RoutesContainer = posed.div(fadeIn)
export default class Layout extends PureComponent {
static propTypes = {
children: PropTypes.any.isRequired,
location: PropTypes.shape({
pathname: PropTypes.string.isRequired
}).isRequired
}
render() {
const { children, location } = this.props
const isHomepage = location.pathname === '/' const isHomepage = location.pathname === '/'
return (
<StaticQuery
query={query}
render={data => {
const { allowedHosts } = data.contentYaml
return ( return (
<> <>
<Typekit /> <Typekit />
@ -48,39 +62,7 @@ const LayoutMarkup = ({ children, data, location }) => {
<Footer /> <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 {
static propTypes = {
children: PropTypes.any.isRequired,
location: PropTypes.shape({
pathname: PropTypes.string.isRequired
}).isRequired
}
render() {
const { children, location } = this.props
return (
<StaticQuery
query={query}
render={data => (
<LayoutMarkup data={data} location={location}>
{children}
</LayoutMarkup>
)}
/> />
) )
} }

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', () => {