import React from 'react' import {findDOMNode} from 'react-dom' import {formatPrice, listingImageUrl} from '../lib/helpers' import {loadListing} from '../lib/api' export default class Listings extends React.Component { constructor (props) { super(props) this.handleTouchMove = e => { const node = e.target const offset = node.scrollHeight - node.scrollTop - node.clientHeight console.log('HANDLE TOUCH MOVE OFFSET', offset) } this.handleScroll = e => { console.log('scrolling'); const node = e.target const offset = node.scrollHeight - node.scrollTop - node.clientHeight if (this.props && this.props.loadingMore) { return } if (offset < 50) { this.props.dispatch({type: 'LOAD_MORE_LISTINGS'}) } } } onListingClick (id) { loadListing(id).then(l => l.text()).then(l => { this.props.dispatch({ type: 'UPDATE_ROUTE', action: { toDispatch: { type: 'VIEW_LISTING_DETAILS', action: { id, listing: JSON.parse(l) } }, params: { listingId: id } } }) this.props.dispatch({ type: 'VIEW_LISTING_DETAILS', action: { id, listing: JSON.parse(l) } }) }) } onMouseEnter (id) { this.props.dispatch({ type: 'ON_LISTING_MOUSE_OVER', action: { id } }) } renderListings () { const {listings = new Map()} = this.props if (listings.size === 0) { return (