// @flow import * as React from 'react'; import Button from 'component/button'; import NavigationHistoryItem from 'component/navigationHistoryItem'; import Paginate from 'component/common/paginate'; type HistoryItem = { uri: string, lastViewed: number, }; type Props = { historyItems: Array, pageCount: number, clearHistoryUri: string => void, }; type State = { itemsSelected: {}, }; class UserHistoryPage extends React.PureComponent { constructor() { super(); this.state = { itemsSelected: {}, }; (this: any).selectAll = this.selectAll.bind(this); (this: any).unselectAll = this.unselectAll.bind(this); (this: any).removeSelected = this.removeSelected.bind(this); } onSelect(uri: string) { const { itemsSelected } = this.state; const newItemsSelected = { ...itemsSelected }; if (itemsSelected[uri]) { delete newItemsSelected[uri]; } else { newItemsSelected[uri] = true; } this.setState({ itemsSelected: { ...newItemsSelected }, }); } selectAll() { const { historyItems } = this.props; const newSelectedState = {}; historyItems.forEach(({ uri }) => (newSelectedState[uri] = true)); this.setState({ itemsSelected: newSelectedState }); } unselectAll() { this.setState({ itemsSelected: {}, }); } removeSelected() { const { clearHistoryUri } = this.props; const { itemsSelected } = this.state; Object.keys(itemsSelected).forEach(uri => clearHistoryUri(uri)); this.setState({ itemsSelected: {}, }); } render() { const { historyItems = [], pageCount } = this.props; const { itemsSelected } = this.state; const allSelected = Object.keys(itemsSelected).length === historyItems.length; const selectHandler = allSelected ? this.unselectAll : this.selectAll; return historyItems.length ? (
{Object.keys(itemsSelected).length ? (
{!!historyItems.length && (
{historyItems.map(item => ( { this.onSelect(item.uri); }} /> ))}
)}
) : (

{__('Your history is empty, what are you doing here?')}

); } } export default UserHistoryPage;