1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-09-10 19:29:56 +00:00
Files
seahub/frontend/src/components/history-list-view/history-list-view.js

88 lines
2.4 KiB
JavaScript
Raw Normal View History

2018-09-12 17:01:48 +08:00
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,
2018-12-25 10:39:57 +08:00
onItemClick: PropTypes.func.isRequired,
onItemRestore: PropTypes.func.isRequired,
2018-09-12 17:01:48 +08:00
};
class HistoryListView extends React.Component {
2018-12-25 10:39:57 +08:00
constructor(props) {
super(props);
this.state = {
isItemFreezed: false,
currentItem: null,
};
}
componentDidMount = () => {
let historyList = this.props.historyList;
if (historyList.length > 0) {
2024-07-18 11:58:42 +08:00
this.setState({ currentItem: historyList[0] });
2018-12-25 10:39:57 +08:00
if (historyList === 1) {
this.props.onItemClick(historyList[0]);
} else {
this.props.onItemClick(historyList[0], historyList[1]);
}
}
};
2018-12-25 10:39:57 +08:00
onFreezedItemToggle = () => {
2024-07-18 11:58:42 +08:00
this.setState({ isItemFreezed: !this.state.isItemFreezed });
};
2018-12-25 10:39:57 +08:00
2018-09-12 17:01:48 +08:00
onScrollHandler = (event) => {
const clientHeight = event.target.clientHeight;
const scrollHeight = event.target.scrollHeight;
2024-07-18 11:58:42 +08:00
const scrollTop = event.target.scrollTop;
2018-09-12 17:01:48 +08:00
const isBottom = (clientHeight + scrollTop + 1 >= scrollHeight);
let hasMore = this.props.hasMore;
if (isBottom && hasMore) {
this.props.reloadMore();
}
};
2018-09-12 17:01:48 +08:00
2018-12-25 10:39:57 +08:00
onItemClick = (item, currentIndex) => {
2024-07-18 11:58:42 +08:00
this.setState({ currentItem: item });
2018-12-25 10:39:57 +08:00
if (currentIndex !== this.props.historyList.length) {
let preItem = this.props.historyList[currentIndex + 1];
this.props.onItemClick(item, preItem);
2018-09-26 02:27:14 -07:00
} else {
2018-12-25 10:39:57 +08:00
this.props.onItemClick(item);
2018-09-26 02:27:14 -07:00
}
};
2018-09-26 02:27:14 -07:00
2018-09-12 17:01:48 +08:00
render() {
return (
<ul className="history-list-container" onScroll={this.onScrollHandler}>
2018-12-25 10:39:57 +08:00
{this.props.historyList.map((item, index) => {
2018-09-12 17:01:48 +08:00
return (
<HisotyListItem
key={index}
2018-09-12 17:01:48 +08:00
item={item}
2018-12-25 10:39:57 +08:00
index={index}
currentItem={this.state.currentItem}
isItemFreezed={this.state.isItemFreezed}
onItemClick={this.onItemClick}
onItemRestore={this.props.onItemRestore}
onFreezedItemToggle={this.onFreezedItemToggle}
2018-09-12 17:01:48 +08:00
/>
);
})}
{this.props.isReloadingData && <li><Loading /></li>}
</ul>
);
}
}
HistoryListView.propTypes = propTypes;
export default HistoryListView;