Pass config as prop
This commit is contained in:
parent
7e059b42c7
commit
9b427f086a
|
@ -1,17 +1,21 @@
|
||||||
import React, { Component } from 'react'
|
import React, { Component } from 'react'
|
||||||
import { Link } from 'react-router-dom'
|
import { Link } from 'react-router-dom'
|
||||||
import config from '../../config/config.json'
|
import PropTypes from 'prop-types'
|
||||||
import '../stylesheets/globals.scss'
|
import '../stylesheets/globals.scss'
|
||||||
import styles from './Home.scss'
|
import styles from './Home.scss'
|
||||||
|
|
||||||
export default class Home extends Component {
|
export default class Home extends Component {
|
||||||
|
static propTypes = {
|
||||||
|
config: PropTypes.object.isRequired
|
||||||
|
}
|
||||||
|
|
||||||
render () {
|
render () {
|
||||||
let key = 0
|
let key = 0
|
||||||
const objKeys = Object.keys(config.social)
|
const objKeys = Object.keys(this.props.config.social)
|
||||||
|
|
||||||
const socialLinks = objKeys.map((val) => {
|
const socialLinks = objKeys.map((val) => {
|
||||||
const link = (
|
const link = (
|
||||||
<a key={key} href={config.social[val]}>
|
<a key={key} href={this.props.config.social[val]}>
|
||||||
<i className={`fa fa-${val} fa-3x`} aria-hidden="true" />
|
<i className={`fa fa-${val} fa-3x`} aria-hidden="true" />
|
||||||
<span className="sr-only">{val}</span>
|
<span className="sr-only">{val}</span>
|
||||||
</a>
|
</a>
|
||||||
|
@ -21,7 +25,7 @@ export default class Home extends Component {
|
||||||
})
|
})
|
||||||
|
|
||||||
socialLinks.push(
|
socialLinks.push(
|
||||||
<a key={key} href={`mailto:${config.email}`}>
|
<a key={key} href={`mailto:${this.props.config.email}`}>
|
||||||
<i className="fa fa-envelope-o fa-3x" aria-hidden="true" />
|
<i className="fa fa-envelope-o fa-3x" aria-hidden="true" />
|
||||||
<span className="sr-only">e-mail</span>
|
<span className="sr-only">e-mail</span>
|
||||||
</a>
|
</a>
|
||||||
|
@ -31,7 +35,7 @@ export default class Home extends Component {
|
||||||
<div id={styles.coverPage} className={styles.coverPageFull}>
|
<div id={styles.coverPage} className={styles.coverPageFull}>
|
||||||
<div id={styles.coverPageContent}>
|
<div id={styles.coverPageContent}>
|
||||||
<div>
|
<div>
|
||||||
<h1 id={styles.coverPageName}><Link to="/">{ config.name }</Link></h1>
|
<h1 id={styles.coverPageName}><Link to="/">{ this.props.config.name }</Link></h1>
|
||||||
</div>
|
</div>
|
||||||
<div className={styles.social}>
|
<div className={styles.social}>
|
||||||
{socialLinks}
|
{socialLinks}
|
||||||
|
|
|
@ -1,16 +1,21 @@
|
||||||
import React, { Component } from 'react'
|
import React, { Component } from 'react'
|
||||||
import config from '../../config/config.json'
|
import PropTypes from 'prop-types'
|
||||||
import '../stylesheets/globals.scss'
|
import '../stylesheets/globals.scss'
|
||||||
import styles from './Navbar.scss'
|
import styles from './Navbar.scss'
|
||||||
|
|
||||||
export default class Navbar extends Component {
|
export default class Navbar extends Component {
|
||||||
|
|
||||||
|
static propTypes = {
|
||||||
|
config: PropTypes.object.isRequired
|
||||||
|
}
|
||||||
|
|
||||||
render () {
|
render () {
|
||||||
let key = 0
|
let key = 0
|
||||||
const objKeys = Object.keys(config.social)
|
const objKeys = Object.keys(this.props.config.social)
|
||||||
|
|
||||||
const socialLinks = objKeys.map((val) => {
|
const socialLinks = objKeys.map((val) => {
|
||||||
const link = (
|
const link = (
|
||||||
<a key={key} href={config.social[val]}>
|
<a key={key} href={this.props.config.social[val]}>
|
||||||
<i className={`fa fa-${val}`} aria-hidden="true" />
|
<i className={`fa fa-${val}`} aria-hidden="true" />
|
||||||
<span className="sr-only">{val}</span>
|
<span className="sr-only">{val}</span>
|
||||||
</a>
|
</a>
|
||||||
|
@ -21,7 +26,7 @@ export default class Navbar extends Component {
|
||||||
})
|
})
|
||||||
|
|
||||||
socialLinks.push(
|
socialLinks.push(
|
||||||
<a key={key} href={`mailto:${config.email}`}>
|
<a key={key} href={`mailto:${this.props.config.email}`}>
|
||||||
<i className="fa fa-envelope-o" aria-hidden="true" />
|
<i className="fa fa-envelope-o" aria-hidden="true" />
|
||||||
<span className="sr-only">e-mail</span>
|
<span className="sr-only">e-mail</span>
|
||||||
</a>
|
</a>
|
||||||
|
@ -33,7 +38,7 @@ export default class Navbar extends Component {
|
||||||
<ul>
|
<ul>
|
||||||
<li>
|
<li>
|
||||||
<a href='/'>
|
<a href='/'>
|
||||||
<span className={styles.nameLink}>{config.name} |</span>
|
<span className={styles.nameLink}>{this.props.config.name} |</span>
|
||||||
</a>
|
</a>
|
||||||
</li>
|
</li>
|
||||||
<li>
|
<li>
|
||||||
|
|
|
@ -3,7 +3,7 @@ import { Navbar, Header } from '.'
|
||||||
import '../stylesheets/globals.scss'
|
import '../stylesheets/globals.scss'
|
||||||
import contentStyle from '../stylesheets/content.scss'
|
import contentStyle from '../stylesheets/content.scss'
|
||||||
|
|
||||||
export const NotFoundPage = (props) => {
|
export const NotFoundPage = () => {
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<Navbar />
|
<Navbar />
|
||||||
|
|
|
@ -11,7 +11,8 @@ import moment from 'moment'
|
||||||
export default class Post extends Component {
|
export default class Post extends Component {
|
||||||
static propTypes = {
|
static propTypes = {
|
||||||
isLoading: PropTypes.bool.isRequired,
|
isLoading: PropTypes.bool.isRequired,
|
||||||
post: PropTypes.object.isRequired
|
post: PropTypes.object.isRequired,
|
||||||
|
config: PropTypes.object.isRequired
|
||||||
}
|
}
|
||||||
|
|
||||||
render () {
|
render () {
|
||||||
|
@ -31,7 +32,7 @@ export default class Post extends Component {
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<Navbar />
|
<Navbar config={this.props.config} />
|
||||||
<div className={contentStyle.contentWrapper}>
|
<div className={contentStyle.contentWrapper}>
|
||||||
<Header header={title} />
|
<Header header={title} />
|
||||||
<div className={contentStyle.content}>
|
<div className={contentStyle.content}>
|
||||||
|
|
|
@ -22,15 +22,16 @@ export default class MainContainer extends Component {
|
||||||
this.state = {
|
this.state = {
|
||||||
isLoadingBlog: !data.posts,
|
isLoadingBlog: !data.posts,
|
||||||
isLoadingAbout: !data.other.about,
|
isLoadingAbout: !data.other.about,
|
||||||
about: data.other.about,
|
about: data[0].other.about,
|
||||||
posts: data.posts
|
posts: data[0].posts,
|
||||||
|
config: data[1]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
render () {
|
render () {
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<Home/>
|
<Home config={this.state.config} />
|
||||||
<Wrapper flex={true}>
|
<Wrapper flex={true}>
|
||||||
<About isLoading={this.state.isLoadingAbout}
|
<About isLoading={this.state.isLoadingAbout}
|
||||||
about={this.state.about}/>
|
about={this.state.about}/>
|
||||||
|
|
|
@ -10,19 +10,20 @@ export default class PostContainer extends Component {
|
||||||
constructor (props) {
|
constructor (props) {
|
||||||
super(props)
|
super(props)
|
||||||
|
|
||||||
let post
|
let data
|
||||||
// eslint-disable-next-line no-undef
|
// eslint-disable-next-line no-undef
|
||||||
if (__isBrowser__) {
|
if (__isBrowser__) {
|
||||||
post = window.__INITIAL_DATA__
|
data = window.__INITIAL_DATA__
|
||||||
delete window.__INITIAL_DATA__
|
delete window.__INITIAL_DATA__
|
||||||
} else {
|
} else {
|
||||||
post = props.staticContext.data
|
data = props.staticContext.data
|
||||||
}
|
}
|
||||||
|
|
||||||
this.state = {
|
this.state = {
|
||||||
isLoading: !post,
|
isLoading: !post,
|
||||||
error: false,
|
error: false,
|
||||||
post: post
|
post: data[0],
|
||||||
|
config: data[1]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -36,7 +37,7 @@ export default class PostContainer extends Component {
|
||||||
return (
|
return (
|
||||||
<Wrapper>
|
<Wrapper>
|
||||||
<Post isLoading={this.state.isLoading}
|
<Post isLoading={this.state.isLoading}
|
||||||
post={this.state.post} />
|
post={this.state.post} config={this.state.config} />
|
||||||
</Wrapper>
|
</Wrapper>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue