import React from 'react'; import PropTypes from 'prop-types'; import HisotyListItem from './history-list-item'; import Loading from '../loading'; const propTypes = { hasMore: PropTypes.bool.isRequired, isReloadingData: PropTypes.bool.isRequired, historyList: PropTypes.array.isRequired, reloadMore: PropTypes.func.isRequired, onItemClick: PropTypes.func.isRequired, }; class HistoryListView extends React.Component { constructor(props) { super(props); this.state = { isItemFreezed: false, currentItem: null, }; } componentDidMount = () => { let historyList = this.props.historyList; if (historyList.length > 0) { this.setState({currentItem: historyList[0]}); if (historyList === 1) { this.props.onItemClick(historyList[0]); } else { this.props.onItemClick(historyList[0], historyList[1]); } } } onFreezedItemToggle = () => { this.setState({isItemFreezed: !this.state.isItemFreezed}); } onScrollHandler = (event) => { const clientHeight = event.target.clientHeight; const scrollHeight = event.target.scrollHeight; const scrollTop = event.target.scrollTop; const isBottom = (clientHeight + scrollTop + 1 >= scrollHeight); let hasMore = this.props.hasMore; if (isBottom && hasMore) { this.props.reloadMore(); } } onItemClick = (item, currentIndex) => { this.setState({currentItem: item}); if (currentIndex !== this.props.historyList.length) { let preItem = this.props.historyList[currentIndex + 1]; this.props.onItemClick(item, preItem); } else { this.props.onItemClick(item); } } render() { return (