import React, { PropTypes, } from 'react'
import { gql, graphql, compose, } from 'react-apollo'
const QUERY_SERIES_DETAIL_VIEW = gql`
query seriesDetailData($seriesId: Int!) {
oneSeries(id: $seriesId) {
id
title
description
cover
}
}
`
const QUERY_SERIES_EPISODES = gql`
query seriesEpisodes($seriesId: Int!) {
oneSeries(id: $seriesId) {
id
episodes {
id
title
cover
}
}
}
`
const options = ({ seriesId, }) => ({ variables: { seriesId, }, })
const withSeriesDetailData = graphql(QUERY_SERIES_DETAIL_VIEW, {
name: `seriesDetailData`,
options,
})
const withSeriesEpisodes = graphql(QUERY_SERIES_EPISODES, {
name: `seriesWithEpisodesData`,
options,
})
const withData = compose(
withSeriesDetailData,
withSeriesEpisodes
)
function SeriesDetailView({
seriesDetailData: {
loading: seriesLoading,
oneSeries,
},
seriesWithEpisodesData: {
loading: episodesLoading,
oneSeries: { episodes } = {},
}
}) {
return (
<div>
<h1>{seriesLoading ? `Loading...` : oneSeries.title}</h1>
<img src={seriesLoading ? `/dummy.jpg` : oneSeries.cover} />
<h2>Episodes</h2>
<ul>
{episodesLoading ? <li>Loading...</li> : episodes.map(episode => (
<li key={episode.id}>
<img src={episode.cover} />
<a href={`/episode/${episode.id}`}>{episode.title}</a>
</li>
))}
</ul>
</div>
)
}
const SeriesDetailViewWithData = withData(SeriesDetailView)
SeriesDetailViewWithData.propTypes = {
seriesId: PropTypes.number.isRequired,
}
export default SeriesDetailView