Skip to content

Instantly share code, notes, and snippets.

@anomaly44
Created November 19, 2015 14:49
Show Gist options
  • Save anomaly44/e513b7015fb3344843fc to your computer and use it in GitHub Desktop.
Save anomaly44/e513b7015fb3344843fc to your computer and use it in GitHub Desktop.
/**
* Created by rob on 11/18/15.
*/
import React, {Component, PropTypes} from 'react';
import {connect} from 'react-redux';
import * as reportActions from 'redux/modules/reporting';
import {isLoaded, load} from 'redux/modules/reporting';
import connectData from 'helpers/connectData';
import { ReportItem } from 'components';
function fetchDataDeferred(getState, dispatch) {
if (!isLoaded(getState())) {
return dispatch(load());
}
}
@connectData(null, fetchDataDeferred)
@connect(
state => ({
items: state.reporting.data,
error: state.reporting.error,
loading: state.reporting.loading
}),
{...reportActions})
export default class Report extends Component {
static propTypes = {
items: PropTypes.array,
error: PropTypes.string,
loading: PropTypes.bool
}
render() {
const {items, error} = this.props;
const styles = require('./Report.scss');
console.log(items);
return (<div className={styles.report}> <h1>test</h1>
{error &&
<div className="alert alert-danger" role="alert">
<span className="glyphicon glyphicon-exclamation-sign" aria-hidden="true"></span>
{' '}
{error}
</div>}
<ul>
{items.map(item =>
<li><button><ReportItem entry={item} key={item.id}/></button></li>
)}
</ul>
</div>);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment