From b6bf3176499c446f37547de64c91561a1fd577b5 Mon Sep 17 00:00:00 2001 From: Fedor Katurov Date: Thu, 16 Jan 2020 11:04:43 +0700 Subject: [PATCH] map dialog optimizations --- src/components/dialogs/MapListDialog.tsx | 63 +++------- src/components/maps/RouteRowWrapper.tsx | 132 ++++++++++---------- src/components/search/MapListDialogHead.tsx | 61 +++++++++ 3 files changed, 146 insertions(+), 110 deletions(-) create mode 100644 src/components/search/MapListDialogHead.tsx diff --git a/src/components/dialogs/MapListDialog.tsx b/src/components/dialogs/MapListDialog.tsx index bc6328b..66d296d 100644 --- a/src/components/dialogs/MapListDialog.tsx +++ b/src/components/dialogs/MapListDialog.tsx @@ -1,4 +1,4 @@ -import React from 'react'; +import React, { PureComponent } from 'react'; import { connect } from 'react-redux'; import { RouteRowWrapper } from '~/components/maps/RouteRowWrapper'; import { Scroll } from '~/components/Scroll'; @@ -17,14 +17,13 @@ import { editorSetDialogActive } from '~/redux/editor/actions'; import { isMobile } from '~/utils/window'; import classnames from 'classnames'; -import Range from 'rc-slider/lib/Range'; import { TABS, TABS_TITLES } from '~/constants/dialogs'; import { Icon } from '~/components/panels/Icon'; import { pushPath } from '~/utils/history'; import { IRouteListItem } from '~/redux/user'; import { ROLES } from '~/constants/auth'; import { IState } from '~/redux/store'; - +import { MapListDialogHead } from '~/components/search/MapListDialogHead'; const mapStateToProps = ({ editor: { editing }, @@ -37,7 +36,6 @@ const mapStateToProps = ({ return { routes, editing, - marks: {}, ready: false, role, }; @@ -48,16 +46,6 @@ const mapStateToProps = ({ 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 ? '+' : '' - } - `, - }), - {} - ), }; }; @@ -72,7 +60,7 @@ const mapDispatchToProps = { toggleRouteStarred, }; -type Props = ReturnType & typeof mapDispatchToProps & {} +type Props = ReturnType & typeof mapDispatchToProps & {}; export interface State { menu_target: IRouteListItem['address']; @@ -82,7 +70,7 @@ export interface State { is_dropping: boolean; } -class MapListDialogUnconnected extends React.Component { +class MapListDialogUnconnected extends PureComponent { state = { menu_target: null, editor_target: null, @@ -178,8 +166,8 @@ class MapListDialogUnconnected extends React.Component { loading, filter: { min, max, title, distance, tab }, }, - marks, - }: Props = this.props; + }: // marks, + Props = this.props; const { editor_target, menu_target, is_editing, is_dropping } = this.state; @@ -192,6 +180,7 @@ class MapListDialogUnconnected extends React.Component { )} + {ready && !loading && list.length === 0 && (
@@ -200,6 +189,7 @@ class MapListDialogUnconnected extends React.Component { ТУТ ПУСТО
И ОДИНОКО
)} +
{Object.values(TABS).map( item => @@ -214,32 +204,16 @@ class MapListDialogUnconnected extends React.Component { ) )}
-
-
- -
- {ready && Object.keys(marks).length > 2 ? ( - = max} - /> - ) : ( -
- )} -
-
+ +
@@ -276,7 +250,6 @@ class MapListDialogUnconnected extends React.Component { } } - const MapListDialog = connect(mapStateToProps, mapDispatchToProps)(MapListDialogUnconnected); export { MapListDialog }; diff --git a/src/components/maps/RouteRowWrapper.tsx b/src/components/maps/RouteRowWrapper.tsx index 0bd8c06..f02ed56 100644 --- a/src/components/maps/RouteRowWrapper.tsx +++ b/src/components/maps/RouteRowWrapper.tsx @@ -1,10 +1,10 @@ -import React from "react"; -import classnames from "classnames"; -import { MapListDialog } from "~/components/dialogs/MapListDialog"; -import { RouteRowView } from "~/components/maps/RouteRowView"; -import { RouteRowEditor } from "~/components/maps/RouteRowEditor"; -import { RouteRowDrop } from "~/components/maps/RouteRowDrop"; -import { ReactElement } from "react"; +import React, { FC, memo } from 'react'; +import classnames from 'classnames'; +import { MapListDialog } from '~/components/dialogs/MapListDialog'; +import { RouteRowView } from '~/components/maps/RouteRowView'; +import { RouteRowEditor } from '~/components/maps/RouteRowEditor'; +import { RouteRowDrop } from '~/components/maps/RouteRowDrop'; +import { ReactElement } from 'react'; interface Props { address: string; @@ -28,64 +28,66 @@ interface Props { modifyRoute: typeof MapListDialog.modifyRoute; toggleStarred: typeof MapListDialog.toggleStarred; - is_editing_mode: "edit" | "drop"; + is_editing_mode: 'edit' | 'drop'; } -export const RouteRowWrapper = ({ - title, - distance, - address, - openRoute, - tab, - startEditing, - showMenu, - showDropCard, - is_public, - is_editing_target, - is_menu_target, - is_editing_mode, - dropRoute, - stopEditing, - modifyRoute, - hideMenu, - is_admin, - is_published, - toggleStarred -}: Props): ReactElement => ( -
- {is_editing_target && is_editing_mode === "edit" && ( - - )} - {is_editing_target && is_editing_mode === "drop" && ( - - )} - {!is_editing_target && ( - - )} -
+export const RouteRowWrapper: FC = memo( + ({ + title, + distance, + address, + openRoute, + tab, + startEditing, + showMenu, + showDropCard, + is_public, + is_editing_target, + is_menu_target, + is_editing_mode, + dropRoute, + stopEditing, + modifyRoute, + hideMenu, + is_admin, + is_published, + toggleStarred, + }) => ( +
+ {is_editing_target && is_editing_mode === 'edit' && ( + + )} + {is_editing_target && is_editing_mode === 'drop' && ( + + )} + {!is_editing_target && ( + + )} +
+ ) ); diff --git a/src/components/search/MapListDialogHead.tsx b/src/components/search/MapListDialogHead.tsx new file mode 100644 index 0000000..409abc8 --- /dev/null +++ b/src/components/search/MapListDialogHead.tsx @@ -0,0 +1,61 @@ +import React, { FC, memo, useMemo, ChangeEvent, ChangeEventHandler } from 'react'; +import Range from 'rc-slider/lib/Range'; + +interface Props { + ready: boolean; + min: number; + max: number; + search: string; + distance: [number, number]; + onDistanceChange: (val: [number, number]) => void; + onSearchChange: ChangeEventHandler; +} + +const MapListDialogHead: FC = memo( + ({ min, max, ready, distance, search, onSearchChange, onDistanceChange }) => { + const marks = useMemo( + () => + [...new Array(Math.floor((max - min) / 25) + 1)].reduce( + (obj, el, i) => ({ + ...obj, + [min + i * 25]: min + i * 25 < 200 ? ` ${min + i * 25}` : ` ${min + i * 25}+`, + }), + {} + ), + [] + ); + + return ( +
+
+ + +
+ + {ready && Object.keys(marks).length > 2 ? ( + = max} + /> + ) : ( +
+ )} +
+
+ ); + } +); + +export { MapListDialogHead };