2016-11-22 16:46:32 +09:00
|
|
|
/*
|
|
|
|
|
|
|
|
List of movies.
|
|
|
|
Wrapped with the "withList" and "withCurrentUser" containers.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
2016-11-18 16:01:27 +09:00
|
|
|
import Telescope from 'meteor/nova:lib';
|
|
|
|
import React, { PropTypes, Component } from 'react';
|
|
|
|
import NovaForm from "meteor/nova:forms";
|
|
|
|
import { Button } from 'react-bootstrap';
|
|
|
|
import { ModalTrigger } from "meteor/nova:core";
|
2016-11-22 16:15:00 +09:00
|
|
|
import MoviesItem from './MoviesItem.jsx';
|
2016-11-18 16:01:27 +09:00
|
|
|
import Movies from '../collection.js';
|
2016-11-22 16:46:32 +09:00
|
|
|
import MoviesNewForm from './MoviesNewForm.jsx';
|
2016-11-19 20:01:17 +01:00
|
|
|
import { compose } from 'react-apollo';
|
2016-11-29 14:08:24 +01:00
|
|
|
import { withList } from 'meteor/nova:core';
|
|
|
|
import { withCurrentUser } from 'meteor/nova:users';
|
2016-11-18 16:01:27 +09:00
|
|
|
|
|
|
|
const LoadMore = props => <a href="#" className="load-more button button--primary" onClick={props.loadMore}>Load More ({props.count}/{props.totalCount})</a>
|
|
|
|
|
|
|
|
class MoviesList extends Component {
|
|
|
|
|
|
|
|
renderNew() {
|
|
|
|
|
|
|
|
const component = (
|
|
|
|
<div className="add-movie">
|
|
|
|
<ModalTrigger
|
|
|
|
title="Add Movie"
|
|
|
|
component={<Button bsStyle="primary">Add Movie</Button>}
|
|
|
|
>
|
2016-11-25 12:22:13 +09:00
|
|
|
<MoviesNewForm refetch={this.props.refetch}/>
|
2016-11-18 16:01:27 +09:00
|
|
|
</ModalTrigger>
|
|
|
|
<hr/>
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
|
2016-11-19 18:01:05 +09:00
|
|
|
return !!this.props.currentUser ? component : null;
|
2016-11-18 16:01:27 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
2016-11-24 15:47:51 +09:00
|
|
|
|
|
|
|
const canCreateNewMovie = Movies.options.mutations.new.check(this.props.currentUser);
|
|
|
|
|
2016-11-25 11:46:31 +09:00
|
|
|
if (this.props.loading) {
|
2016-11-26 11:17:01 +09:00
|
|
|
return <Telescope.components.Loading />
|
2016-11-19 18:01:05 +09:00
|
|
|
} else {
|
2016-11-19 18:14:33 +09:00
|
|
|
const hasMore = this.props.totalCount > this.props.results.length;
|
2016-11-19 18:01:05 +09:00
|
|
|
return (
|
|
|
|
<div className="movies">
|
2016-11-24 15:47:51 +09:00
|
|
|
{canCreateNewMovie ? this.renderNew() : null}
|
2016-11-25 12:22:13 +09:00
|
|
|
{this.props.results.map(movie => <MoviesItem key={movie._id} {...movie} currentUser={this.props.currentUser} refetch={this.props.refetch} />)}
|
2016-11-19 18:14:33 +09:00
|
|
|
{hasMore ? <LoadMore {...this.props}/> : <p>No more movies</p>}
|
2016-11-19 18:01:05 +09:00
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
2016-11-18 16:01:27 +09:00
|
|
|
}
|
2016-11-19 18:01:05 +09:00
|
|
|
|
2016-11-18 16:01:27 +09:00
|
|
|
};
|
|
|
|
|
2016-11-19 19:00:17 +09:00
|
|
|
const listOptions = {
|
2016-11-19 18:01:05 +09:00
|
|
|
collection: Movies,
|
2016-11-21 16:18:08 +09:00
|
|
|
queryName: 'moviesListQuery',
|
2016-11-24 16:58:08 +09:00
|
|
|
fragmentName: MoviesItem.fragmentName,
|
|
|
|
fragment: MoviesItem.fragment,
|
2016-11-19 19:00:17 +09:00
|
|
|
};
|
|
|
|
|
2016-11-22 16:15:00 +09:00
|
|
|
export default compose(withList(listOptions), withCurrentUser)(MoviesList);
|