From f8d2b6a5bd66bba65ae8c03395234a6aac187922 Mon Sep 17 00:00:00 2001 From: muerwre Date: Wed, 6 Mar 2019 17:27:19 +0700 Subject: [PATCH] added actions --- src/components/dialogs/MapListDialog.tsx | 19 +++++++++++++++++-- src/components/maps/RouteRowDrop.tsx | 2 +- src/components/maps/RouteRowEditor.tsx | 13 +++++++++++-- src/components/maps/RouteRowWrapper.tsx | 4 +++- src/redux/user/actions.ts | 5 +++++ src/redux/user/constants.ts | 3 +++ 6 files changed, 40 insertions(+), 6 deletions(-) diff --git a/src/components/dialogs/MapListDialog.tsx b/src/components/dialogs/MapListDialog.tsx index e6ae4a4..13f68e9 100644 --- a/src/components/dialogs/MapListDialog.tsx +++ b/src/components/dialogs/MapListDialog.tsx @@ -7,7 +7,10 @@ import { searchSetDistance, searchSetTitle, searchSetTab, - setDialogActive, mapsLoadMore, + setDialogActive, + mapsLoadMore, + dropRoute, + modifyRoute, } from '$redux/user/actions'; import { isMobile } from '$utils/window'; import classnames from 'classnames'; @@ -29,6 +32,8 @@ export interface IMapListDialogProps extends IRootState { searchSetTitle: typeof searchSetTitle, searchSetTab: typeof searchSetTab, setDialogActive: typeof setDialogActive, + dropRoute: typeof dropRoute, + modifyRoute: typeof modifyRoute, } export interface IMapListDialogState { @@ -98,7 +103,14 @@ class Component extends React.Component null; + 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 { @@ -201,6 +213,7 @@ class Component extends React.Component )) @@ -239,6 +252,8 @@ const mapDispatchToProps = dispatch => bindActionCreators({ searchSetTab, setDialogActive, mapsLoadMore, + dropRoute, + modifyRoute, }, dispatch); export const MapListDialog = connect(mapStateToProps, mapDispatchToProps)(Component); diff --git a/src/components/maps/RouteRowDrop.tsx b/src/components/maps/RouteRowDrop.tsx index 41fe59e..2a909ce 100644 --- a/src/components/maps/RouteRowDrop.tsx +++ b/src/components/maps/RouteRowDrop.tsx @@ -21,7 +21,7 @@ export const RouteRowDrop = ({ className="route-row" >
-
dropRoute(_id)}>Удалить
+
Удалить
Отмена
diff --git a/src/components/maps/RouteRowEditor.tsx b/src/components/maps/RouteRowEditor.tsx index 9eea74e..eb08ff5 100644 --- a/src/components/maps/RouteRowEditor.tsx +++ b/src/components/maps/RouteRowEditor.tsx @@ -2,11 +2,13 @@ import * as React from 'react'; import { Icon } from '$components/panels/Icon'; import { Switch } from '$components/Switch'; +import { MapListDialog } from "$components/dialogs/MapListDialog"; interface Props { title: string; _id: string; is_public: boolean, + modifyRoute: typeof MapListDialog.modifyRoute, } interface State { @@ -24,14 +26,21 @@ export class RouteRowEditor extends React.Component { }; } - stopEditing = () => console.log(); + stopEditing = () => { + const { + state: { title, is_public }, + props: { _id } + } = this; + + this.props.modifyRoute({ _id, title, is_public }) + }; + setPublic = () => this.setState({ is_public: !this.state.is_public }); setTitle = ({ target: { value } }: { target: { value: string } }) => this.setState({ title: value }); render() { const { state: { title, is_public }, - props: { _id } } = this; return ( diff --git a/src/components/maps/RouteRowWrapper.tsx b/src/components/maps/RouteRowWrapper.tsx index e8ab8ad..77580ff 100644 --- a/src/components/maps/RouteRowWrapper.tsx +++ b/src/components/maps/RouteRowWrapper.tsx @@ -22,6 +22,7 @@ interface Props { showMenu: typeof MapListDialog.showMenu, showDropCard: typeof MapListDialog.showDropCard, dropRoute: typeof MapListDialog.dropRoute, + modifyRoute: typeof MapListDialog.modifyRoute, is_editing_mode: 'edit' | 'drop', } @@ -29,7 +30,7 @@ interface Props { export const RouteRowWrapper = ({ title, distance, _id, openRoute, tab, startEditing, showMenu, showDropCard, is_public, is_editing_target, is_menu_target, is_editing_mode, - dropRoute, stopEditing, + dropRoute, stopEditing, modifyRoute, }: Props): ReactElement => (
} { diff --git a/src/redux/user/actions.ts b/src/redux/user/actions.ts index f434755..60ab5f2 100644 --- a/src/redux/user/actions.ts +++ b/src/redux/user/actions.ts @@ -71,3 +71,8 @@ export const mapsSetShift = (shift: number) => ({ type: ACTIONS.MAPS_SET_SHIFT, export const setFeature = (features: { [x: string]: boolean }) => ({ type: ACTIONS.SET_FEATURE, features }); export const setIsRouting = (is_routing: boolean) => ({ type: ACTIONS.SET_IS_ROUTING, is_routing }); + +export const dropRoute = (_id: string) => ({ type: ACTIONS.DROP_ROUTE, _id }); +export const modifyRoute = (_id: string, { title, is_public }: { title: string, is_public: boolean }) => ({ + type: ACTIONS.MODIFY_ROUTE, _id, title, is_public +}); diff --git a/src/redux/user/constants.ts b/src/redux/user/constants.ts index 61ceed7..d5dfad9 100644 --- a/src/redux/user/constants.ts +++ b/src/redux/user/constants.ts @@ -78,4 +78,7 @@ export const ACTIONS: IActions = { SET_FEATURE: 'SET_FEATURE', SET_IS_ROUTING: 'SET_IS_ROUTING', + + DROP_ROUTE: 'DROP_ROUTE', + MODIFY_ROUTE: 'MODIFY_ROUTE', };