Last active
January 17, 2018 03:52
-
-
Save peggyrayzis/a996eb9b2c128d6fdc3707e21b466095 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { Component } from 'react'; | |
import { graphql } from 'react-apollo'; | |
import { MatchSummary, NoDataSummary } from '@mls-digital/react-components'; | |
import MatchSummaryQuery from './match-summary.graphql'; | |
const mapResultsToProps = ({ data }) => { | |
if (!data.match) | |
return { | |
loading: data.loading, | |
}; | |
const { stats, home, away } = data.match; | |
return { | |
loading: data.loading, | |
home: { | |
...home, | |
results: stats.scores.home, | |
}, | |
away: { | |
...away, | |
results: stats.scores.away, | |
}, | |
}; | |
}; | |
const mapPropsToOptions = ({ id, season, shouldPoll }) => { | |
return { | |
variables: { | |
id, | |
season, | |
}, | |
pollInterval: shouldPoll ? 1000 * 60 : undefined, | |
}; | |
}; | |
@graphql(MatchSummaryQuery, { | |
props: mapResultsToProps, | |
options: mapPropsToOptions, | |
}) | |
class MatchSummaryContainer extends Component { | |
render() { | |
const { loading, ...matchSummaryProps } = this.props; | |
if (loading && !matchSummaryProps.home) { | |
return <NoDataSummary />; | |
} | |
return <MatchSummary {...matchSummaryProps} />; | |
} | |
} | |
export default MatchSummaryContainer; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment