Last active
June 24, 2018 02:55
-
-
Save zapkub/d8c8f88f88a1e7d720f633b1b6d8a29b 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
export const REVIEW_HIGHLIGHT_QUERY = gql` | |
${BookHighlighReview.fragments.review} | |
query($bookId: MongoID!) { | |
reviews: bookReviewConnection( | |
filter: { bookId: $bookId } | |
first: 3 | |
sort: CREATED_AT_DESC | |
) { | |
count | |
edges { | |
node { | |
...BookHighlighReview__BookReview | |
} | |
} | |
} | |
} | |
` | |
type ReviewEdges = Array<{ node: BookReviewItemData }> | |
type ReviewHighlightDataPropTypes = { | |
children: (reviews: ReviewEdges, loading: boolean) => JSX.Element | |
bookId: string | |
} | |
export const ReviewHighlightData: React.SFC<ReviewHighlightDataPropTypes> = ({ | |
children, | |
bookId | |
}) => ( | |
bookId ? <Query query={REVIEW_HIGHLIGHT_QUERY} variables={{bookId}}> | |
{({ loading, data }) => { | |
if (data && data.reviews) { | |
return children(data.reviews.edges, loading) | |
} else { | |
return children([], loading) | |
} | |
}} | |
</Query> : <div data-message="no-book-id" /> | |
) | |
// usage | |
<ReviewHighlightData bookId={book._id}> | |
{(reviews) => ( | |
<BookHighlighReview onWriteReviewClick={this.onWriteReviewClick} bookId={book._id} review={reviews} /> | |
)} | |
</ReviewHighlightData> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment