Vulcan/packages/framework-demo/lib/components/MoviesDetails.jsx
2016-12-12 09:54:16 +09:00

51 lines
No EOL
1.2 KiB
JavaScript

/*
A component that shows a detailed view of a single movie.
Wrapped with the "withDocument" container.
*/
import Telescope from 'meteor/nova:lib';
import React, { PropTypes, Component } from 'react';
import Movies from '../collection.js';
import { withDocument } from 'meteor/nova:core';
import { compose } from 'react-apollo';
import gql from 'graphql-tag';
const MoviesDetails = props => {
const movie = props.document;
if (props.loading) {
return <p>Loading</p>
} else {
return (
<div>
<h2>{movie.name} ({movie.year})</h2>
<p>Reviewed by <strong>{movie.user && movie.user.__displayName}</strong> on {movie.createdAt}</p>
<p>{movie.review}</p>
{movie.privateComments ? <p><strong>PRIVATE</strong>: {movie.privateComments}</p>: null}
</div>
)
}
}
MoviesDetails.fragment = gql`
fragment moviesDetailsFragment on Movie {
_id
name
createdAt
year
review
privateComments
user {
__displayName
}
}
`;
const options = {
collection: Movies,
queryName: 'moviesSingleQuery',
fragment: MoviesDetails.fragment,
};
export default compose(withDocument(options))(MoviesDetails);