all files / containers/Home/ Home.js

98.44% Statements 63/64
97.14% Branches 34/35
100% Functions 13/13
94.12% Lines 16/17
4 statements, 11 branches Ignored     
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60                                                                                          
import React from 'react'
import Transmit from 'react-transmit'
import { Link } from 'react-router'
import { injectIntl, FormattedDate } from 'react-intl'
 
import { ButtonGroup, Button } from 'react-bootstrap'
import { CommentBox, NavBar, Utils } from 'components'
import dataService from 'apis/dataService'
 
import { Msg } from './messages'
import styles from './styles.css'
 
const fetchInitialData = (id) => {
  return dataService.read(['posts', id], {}).catch(error => { throw error })
}
const fragmentArr = [
  { data: [fetchInitialData, 3] },
  { commentBoxData: [CommentBox.fetchInitialData, 3] }
]
 
class Home extends React.Component {
  state = { data: {}, commentBoxData: {} }
 
  componentWillMount () {
    // after routing back to this component, manually fetch data:
    Eif (__CLIENT__ && !this.props.data) {
      Utils.fetchFragmentsToState(fragmentArr, this)
    } else {
      this.setState(this.props)
    }
  }
 
  render () {
    return (
      <section className={styles.home}>
        <NavBar />
 
        <h3>Home</h3>
        <p><Msg s="welcome" values={{ page: 'Home Page' }}/></p>
        <p><Msg s="today"/> <FormattedDate value={ new Date() } day="numeric" month="numeric" year="numeric" /></p>
        <ul>
          <li><a href="/?locale=en-US">English en-US</a></li>
          <li><a href="/?locale=ja-JP">Japanese ja-JP</a></li>
        </ul>
        <ButtonGroup>
          <Button><Msg s="rateMeh" /></Button>
          <Button><Msg s="rateOk" /></Button>
          <Button><Msg s="rateGreat" /></Button>
        </ButtonGroup>
        <hr />
        <div>Post 1 - Title: "{this.state.data.title}"</div>
 
        <CommentBox data={this.state.commentBoxData}/>
      </section>
    )
  }
}
 
export default Utils.createTransmitContainer(Home, fragmentArr)