import * as React from 'react'; import { bindActionCreators } from 'redux'; import { connect } from 'react-redux'; import { RouteRow } from '$components/maps/RouteRow'; import { Scroll } from '$components/Scroll'; import { searchSetDistance, searchSetTitle, searchSetTab, setDialogActive, mapsLoadMore, } from '$redux/user/actions'; import { isMobile } from '$utils/window'; import classnames from 'classnames'; import { Range } from 'rc-slider'; import { TABS } from '$constants/dialogs'; import { Icon } from '$components/panels/Icon'; import { pushPath } from '$utils/history'; import { IRootState, IRouteListItem } from '$redux/user/reducer'; interface Props extends IRootState { marks: { [x: number]: string }, routes_sorted: Array, mapsLoadMore: typeof mapsLoadMore, searchSetDistance: typeof searchSetDistance, searchSetTitle: typeof searchSetTitle, searchSetTab: typeof searchSetTab, setDialogActive: typeof setDialogActive, } interface State { editing_item: IRouteListItem['_id'], } class Component extends React.Component { state = { editing_item: null, }; startEditing = editing_item => this.setState({ editing_item }); stopEditing = () => this.setState({ editing_item: null }); setTitle = ({ target: { value } }: { target: { value: string }}): void => { this.props.searchSetTitle(value); }; openRoute = (_id: string): void => { if (isMobile()) this.props.setDialogActive(false); pushPath(`/${_id}/${this.props.editing ? 'edit' : ''}`); }; onScroll = (e: { target: { scrollHeight: number, scrollTop: number, clientHeight: number }}): void => { const { target: { scrollHeight, scrollTop, clientHeight }} = e; const delta = scrollHeight - scrollTop - clientHeight; if ( delta < 500 && this.props.routes.list.length < this.props.routes.limit && !this.props.routes.loading ) { this.props.mapsLoadMore(); } }; render() { const { ready, routes: { list, loading, filter: { min, max, title, distance, tab, } }, marks, }: Props = this.props; const { editing_item } = this.state; return (
{ list.length === 0 && loading &&
} { ready && !loading && list.length === 0 &&
ТУТ ПУСТО
И ОДИНОКО
}
{ Object.keys(TABS).map(item => (
this.props.searchSetTab(item)} key={item} > {TABS[item]}
)) }

{ ready ? = max} /> :
}
{ list.map(route => ( )) }
); } } const mapStateToProps = ({ user: { editing, routes } }) => { if (routes.filter.max >= 9999) { return { routes, editing, marks: {}, ready: false, }; } return ({ routes, editing, ready: true, marks: [...new Array(Math.floor((routes.filter.max - routes.filter.min) / 25) + 1)].reduce((obj, el, i) => ({ ...obj, [routes.filter.min + (i * 25)]: ` ${routes.filter.min + (i * 25)}${(routes.filter.min + (i * 25) >= 200) ? '+' : ''} `, }), {}), }); }; const mapDispatchToProps = dispatch => bindActionCreators({ searchSetDistance, searchSetTitle, searchSetTab, setDialogActive, mapsLoadMore, }, dispatch); export const MapListDialog = connect(mapStateToProps, mapDispatchToProps)(Component);