From 9ee5fb86b011947f493d60fac3d5378d18a787d5 Mon Sep 17 00:00:00 2001 From: tarnas14 Date: Sun, 27 Mar 2016 17:57:18 +0200 Subject: [PATCH] moved getting orders for dashboard to App component this way the orders are downloaded only once at the start of the application instead of every time when the user navigates to `/` --- src/components/app.jsx | 22 ++++++++++++++++++++++ src/components/dashboard.jsx | 24 +----------------------- 2 files changed, 23 insertions(+), 23 deletions(-) diff --git a/src/components/app.jsx b/src/components/app.jsx index 2292d9a..10ab79f 100644 --- a/src/components/app.jsx +++ b/src/components/app.jsx @@ -13,6 +13,7 @@ import OrderDetails from './orderDetails'; import {orders, activeOrder} from '../store/orders'; import localization from '../store/localization'; import changeLocale from '../store/localizationActions'; +import {hydrateOrders} from '../store/ordersActions'; // Add the reducer to your store on the `routing` key const store = createStore( @@ -31,9 +32,30 @@ const App = connect(state => ({resources: state.localization.resources.app}))( React.createClass({ propTypes: { children: React.PropTypes.object, + dispatch: React.PropTypes.func.isRequired, resources: React.PropTypes.object.isRequired }, + componentDidMount () { + fetch('/api/orders') + .then(response => response.json()) + .then(orders => { + const ordersToday = orders.map(orderWithStringDates => { + return { + ...orderWithStringDates, + deadline: new Date(orderWithStringDates.deadline) + } + }).filter(order => { + const today = new Date(); + return today.getFullYear() === order.deadline.getFullYear() && + today.getMonth() === order.deadline.getMonth() && + today.getDate() === order.deadline.getDate(); + }); + + this.props.dispatch(hydrateOrders(ordersToday)); + }); + }, + render () { return ( diff --git a/src/components/dashboard.jsx b/src/components/dashboard.jsx index 6a68547..6dd2e4b 100644 --- a/src/components/dashboard.jsx +++ b/src/components/dashboard.jsx @@ -3,40 +3,18 @@ import {Row, Col, Alert, Button} from 'react-bootstrap'; import {Link} from 'react-router'; import OrderTile from './orderTile'; import {connect} from 'react-redux'; -import {hydrateOrders} from '../store/ordersActions'; const Dashboard = React.createClass({ propTypes: { - dispatch: React.PropTypes.func.isRequired, orders: React.PropTypes.array.isRequired, resources: React.PropTypes.object.isRequired }, - componentDidMount () { - fetch('/api/orders') - .then(response => response.json()) - .then(orders => { - const ordersToday = orders.map(orderWithStringDates => { - return { - ...orderWithStringDates, - deadline: new Date(orderWithStringDates.deadline) - } - }).filter(order => { - const today = new Date(); - return today.getFullYear() === order.deadline.getFullYear() && - today.getMonth() === order.deadline.getMonth() && - today.getDate() === order.deadline.getDate(); - }); - - this.props.dispatch(hydrateOrders(ordersToday)); - }); - }, - _renderOrderTiles () { return this.props.orders.map(order => ); }, - _getTileContainerStyles() { + _getTileContainerStyles () { return { marginTop: '1em' };