// App component : represents the whole app. App = React.createClass({ // This mixin makes the getMeteorData work. mixins: [ReactMeteorData], getInitialState() { return { hideCompleted: false }; }, // Loads items from the Tasks collection and puts them on this.data.tasks. getMeteorData() { let query = {}; const uncheckedQuery = { checked: { $ne: true} }; if (this.state.hideCompleted) { // If hideCompleted is checked, filter tasks. query = uncheckedQuery; } let result = { tasks: Tasks.find(query, { sort: { createdAt: -1 }}).fetch(), // Since we already have the data in the client-side Minimongo collection, // adding this extra count doesn't involve asking the server for anything. incompleteCount: Tasks.find(uncheckedQuery).count(), currentUser: Meteor.user() }; // Meteor._debug("result", result); return result; }, renderTasks() { // Get tasks from this.data.tasks. return this.data.tasks.map((task) => { const currentUserId = this.data.currentUser && this.data.currentUser._id; const showPrivateButton = task.owner === currentUserId; // Meteor._debug(task._id); return ; }); }, handleSubmit(event) { event.preventDefault(); // Meteor._debug('refs', this.refs); // Find the text field via the React ref. var text = ReactDOM.findDOMNode(this.refs.textInput).value.trim(); Meteor.call("addTask", text); // Clear form to allow a new input. ReactDOM.findDOMNode(this.refs.textInput).value = ''; }, toggleHideCompleted() { this.setState({ hideCompleted: !this.state.hideCompleted }); }, render() { return (

Todo list ({this.data.incompleteCount})

{/* These are JSX comments. */} { this.data.currentUser ? // Beware: for React, onsubmit is not the same as onSubmit, the former doesn't work.
: '' }
); } });