Skip to content

Instantly share code, notes, and snippets.

@trezy
Last active September 14, 2017 20:37
Show Gist options
  • Save trezy/e78d0efd6c53340046808ed1daa41928 to your computer and use it in GitHub Desktop.
Save trezy/e78d0efd6c53340046808ed1daa41928 to your computer and use it in GitHub Desktop.
// Module imports
import React from 'react'
import { bindActionCreators } from 'redux'
import { Provider } from 'react-redux'
import withRedux from 'next-redux-wrapper'
// Component imports
import {
actions,
initStore,
} from '../store'
import Dialog from './Dialog'
import LoginDialog from './LoginDialog'
import Head from './Head'
import Header from './Header'
import Reminders from './Reminders'
import UserMenu from './UserMenu'
// Component constants
const store = initStore()
export default (Component, title = 'Untitled', mapStateToProps = null, mapDispatchToProps = null) => {
class Page extends React.Component {
static async getInitialProps(ctx) {
let {
asPath,
isServer,
query,
} = ctx
let props = {}
if (typeof Component.getInitialProps === 'function') {
props = await Component.getInitialProps(ctx)
}
return {
asPath,
isServer,
query,
...props
}
}
render() {
let {
isServer,
path,
} = this.props
let mainClasses = ['fade-in', 'page', title.toLowerCase().replace(' ', '-')].join(' ')
return (
<Provider store={store}>
<div role="application">
<Head title={title} />
<Header
isServer={isServer}
path={path} />
<UserMenu />
<Reminders />
<main className={mainClasses}>
<Component {...this.props} />
</main>
<Dialog />
</div>
</Provider>
)
}
}
if (mapStateToProps || mapDispatchToProps) {
return withRedux(initStore, mapStateToProps, mapDispatchToProps)(Page)
}
return Page
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment