Guest User

product_list

a guest
Nov 4th, 2016
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import React, { Component } from 'react';
  2. // React mixin for reactively tracking Meteor data
  3. import { createContainer } from 'meteor/react-meteor-data';
  4. import { Products } from '../../imports/collections/products';
  5. import ProductDetail from './product_detail';
  6. import {Search} from './search';
  7.  
  8. const PER_PAGE = 20;
  9.  
  10.  
  11. class ProductList extends Component {
  12.    componentWillMount() {
  13.      this.page = 1;
  14.    }
  15.  
  16.     handleInput(event){
  17.      event.preventDefault();
  18.      let queryValue=this.refs.inputValue.value;
  19.     Meteor.call('search.receive',queryValue);
  20.    
  21.  
  22.   }
  23.    handleButtonClick() {
  24.      Meteor.subscribe('products', PER_PAGE * (this.page+1));
  25.      this.page += 1;
  26.    }
  27.  
  28.    
  29.  
  30.    render() {
  31.      // props.products => returns an array of products objects
  32.      
  33.      return (
  34.  
  35.        <div>
  36.        
  37.        <form onSubmit={this.handleInput.bind(this)} >
  38.        <input ref="inputValue" />
  39.  
  40.        </form>
  41.         {this.props.queryValue}
  42.          <div className="product-list">
  43.            {this.props.products.map(product =><ProductDetail key={product._id} product={product} />    
  44.               )
  45.             }
  46.          </div>
  47.          <button onClick={this.handleButtonClick.bind(this)}
  48.            className="btn btn-primary">
  49.            Load More...
  50.          </button>
  51.          
  52.          
  53.        </div>
  54.      );
  55.    }
  56. };
  57.  
  58. export default createContainer (() => {
  59.    // set up our subscription
  60.    Meteor.subscribe('products', PER_PAGE);
  61.  
  62.    
  63.      return {products: Products.find({}).fetch()};}, ProductList);
Add Comment
Please, Sign In to add comment