import * as React from 'react'; import { bindActionCreators } from 'redux'; import { connect } from 'react-redux'; import { RouteRowWrapper } from '$components/maps/RouteRowWrapper'; import { Scroll } from '$components/Scroll'; import { searchSetDistance, searchSetTitle, searchSetTab, setDialogActive, mapsLoadMore, dropRoute, modifyRoute, } 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'; export interface IMapListDialogProps extends IRootState { marks: { [x: number]: string }, routes_sorted: Array, routes: IRootState['routes'], ready: IRootState['ready'], mapsLoadMore: typeof mapsLoadMore, searchSetDistance: typeof searchSetDistance, searchSetTitle: typeof searchSetTitle, searchSetTab: typeof searchSetTab, setDialogActive: typeof setDialogActive, dropRoute: typeof dropRoute, modifyRoute: typeof modifyRoute, } export interface IMapListDialogState { menu_target: IRouteListItem['_id'], editor_target: IRouteListItem['_id'], is_editing: boolean, is_dropping: boolean, } class Component extends React.Component { state = { menu_target: null, editor_target: null, is_editing: false, is_dropping: false, }; startEditing = (editor_target: IRouteListItem['_id']): void => this.setState({ editor_target, menu_target: null, is_editing: true, is_dropping: false, }); showMenu = (menu_target: IRouteListItem['_id']): void => this.setState({ menu_target, }); showDropCard = (editor_target: IRouteListItem['_id']): void => this.setState({ editor_target, menu_target: null, is_editing: false, is_dropping: true, }); stopEditing = (): void => { console.log('stop it!'); this.setState({ editor_target: 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' : ''}`); pushPath(`/${_id}`); this.stopEditing(); 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(); } }; dropRoute = (_id: string): void => { this.props.dropRoute(_id); }; modifyRoute = ({ _id, title, is_public }: { _id: string, title: string, is_public: boolean }): void => { this.props.modifyRoute(_id, { title, is_public }); this.stopEditing(); }; render() { const { ready, routes: { list, loading, filter: { min, max, title, distance, tab, } }, marks, }: IMapListDialogProps = this.props; const { editor_target, menu_target, is_editing, is_dropping } = 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, dropRoute, modifyRoute, }, dispatch); export const MapListDialog = connect(mapStateToProps, mapDispatchToProps)(Component);