removed unnecessary action creators

This commit is contained in:
Fedor Katurov 2019-12-30 21:16:04 +07:00
parent b75c028ce1
commit de5726929f
12 changed files with 98 additions and 89 deletions

View file

@ -2,14 +2,15 @@ import * as React from 'react';
import { LOGOS } from '$constants/logos'; import { LOGOS } from '$constants/logos';
import { Icon } from '$components/panels/Icon'; import { Icon } from '$components/panels/Icon';
import classnames from 'classnames'; import classnames from 'classnames';
import { setLogo as setLogoAction } from "$redux/user/actions"; import * as MAP_ACTIONS from "$redux/map/actions"
import { IRootState } from "$redux/user"; import { IMapReducer } from '$redux/map';
interface Props extends IRootState { interface Props {
setLogo: typeof setLogoAction, logo: IMapReducer['logo'],
mapSetLogo: typeof MAP_ACTIONS.mapSetLogo,
} }
export const LogoDialog = ({ logo, setLogo }: Props) => ( export const LogoDialog = ({ logo, mapSetLogo }: Props) => (
<div className="control-dialog top"> <div className="control-dialog top">
<div className="helper logo-helper"> <div className="helper logo-helper">
<div className="helper-back"> <div className="helper-back">
@ -19,7 +20,7 @@ export const LogoDialog = ({ logo, setLogo }: Props) => (
Object.keys(LOGOS).map(item => ( Object.keys(LOGOS).map(item => (
<div <div
className={classnames('helper-menu-item', { active: (item === logo) })} className={classnames('helper-menu-item', { active: (item === logo) })}
onMouseDown={() => setLogo(item)} onMouseDown={() => mapSetLogo(item)}
key={item} key={item}
> >
{LOGOS[item][0]} {LOGOS[item][0]}

View file

@ -11,28 +11,33 @@ import { CancelDialog } from '$components/dialogs/CancelDialog';
import { bindActionCreators } from 'redux'; import { bindActionCreators } from 'redux';
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import { import * as USER_ACTIONS from '$redux/user/actions';
setMode,
setLogo,
routerCancel,
routerSubmit,
setActiveSticker,
clearStickers,
clearPoly,
clearAll,
clearCancel,
stopEditing,
setEditing,
sendSaveRequest,
changeProvider,
} from '$redux/user/actions';
import { ProviderDialog } from '$components/dialogs/ProviderDialog'; import { ProviderDialog } from '$components/dialogs/ProviderDialog';
import { ShotPrefetchDialog } from '$components/dialogs/ShotPrefetchDialog'; import { ShotPrefetchDialog } from '$components/dialogs/ShotPrefetchDialog';
import { IRootState } from "$redux/user"; import * as MAP_ACTIONS from '$redux/map/actions';
import { selectUserMode } from '$redux/user/selectors';
interface Props extends IRootState { const mapStateToProps = state => ({ mode: selectUserMode(state) });
width: number,
} // const mapDispatchToProps = dispatch => bindActionCreators({
// routerCancel: USER_ACTIONS.routerCancel,
// routerSubmit: USER_ACTIONS.routerSubmit,
// setActiveSticker: USER_ACTIONS.setActiveSticker,
// clearStickers: USER_ACTIONS.clearStickers,
// clearPoly: USER_ACTIONS.clearPoly,
// clearAll: USER_ACTIONS.clearAll,
// clearCancel: USER_ACTIONS.clearCancel,
// stopEditing: USER_ACTIONS.stopEditing,
// setEditing: USER_ACTIONS.setEditing,
// setMode: USER_ACTIONS.setMode,
// sendSaveRequest: USER_ACTIONS.sendSaveRequest,
// changeProvider: USER_ACTIONS.changeProvider,
// mapSetLogo: MAP_ACTIONS.mapSetLogo,
// }, dispatch);
type Props = ReturnType<typeof mapStateToProps> & {
width: number;
};
const DIALOG_CONTENTS: { [x: string]: any } = { const DIALOG_CONTENTS: { [x: string]: any } = {
[MODES.ROUTER]: RouterDialog, [MODES.ROUTER]: RouterDialog,
@ -45,32 +50,12 @@ const DIALOG_CONTENTS: { [x: string]: any } = {
[MODES.SHOT_PREFETCH]: ShotPrefetchDialog, [MODES.SHOT_PREFETCH]: ShotPrefetchDialog,
}; };
export const Component = (props: Props) => ( export const Component = (props: Props) =>
props.mode && DIALOG_CONTENTS[props.mode] props.mode && DIALOG_CONTENTS[props.mode]
? React.createElement(DIALOG_CONTENTS[props.mode], { ...props }) ? React.createElement(DIALOG_CONTENTS[props.mode])
: null : null;
);
const mapStateToProps = ({ user }) => ({ ...user });
const mapDispatchToProps = dispatch => bindActionCreators({
routerCancel,
routerSubmit,
setLogo,
setActiveSticker,
clearStickers,
clearPoly,
clearAll,
clearCancel,
stopEditing,
setEditing,
setMode,
sendSaveRequest,
changeProvider,
}, dispatch);
export const EditorDialog = connect( export const EditorDialog = connect(
mapStateToProps, mapStateToProps
mapDispatchToProps // mapDispatchToProps
)(Component); )(Component);

View file

@ -6,7 +6,7 @@ import { Icon } from '$components/panels/Icon';
import { EditorDialog } from '$components/panels/EditorDialog'; import { EditorDialog } from '$components/panels/EditorDialog';
import { bindActionCreators } from 'redux'; import { bindActionCreators } from 'redux';
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import { setMode, startEditing, stopEditing, setLogo, takeAShot, keyPressed } from '$redux/user/actions'; import { setMode, startEditing, stopEditing, takeAShot, keyPressed } from '$redux/user/actions';
import { IRootState } from "$redux/user"; import { IRootState } from "$redux/user";
import { Tooltip } from "$components/panels/Tooltip"; import { Tooltip } from "$components/panels/Tooltip";
@ -159,7 +159,7 @@ function mapStateToProps(state) {
const mapDispatchToProps = dispatch => bindActionCreators({ const mapDispatchToProps = dispatch => bindActionCreators({
setMode, setMode,
setLogo, // setLogo,
startEditing, startEditing,
stopEditing, stopEditing,
takeAShot, takeAShot,

View file

@ -45,8 +45,12 @@ const Component = ({
function mapStateToProps(state) { function mapStateToProps(state) {
const { const {
map: {
provider,
logo,
},
user: { user: {
provider, logo, markers_shown, editing markers_shown, editing
}, },
} = state; } = state;

View file

@ -12,7 +12,8 @@ import {
resetSaveDialog, resetSaveDialog,
setActiveSticker, setActiveSticker,
setAddress, setAddress,
setChanged, setDescription, setChanged,
setDescription,
setDistance, setDistance,
setIsEmpty, setIsRouting, setIsEmpty, setIsRouting,
setLogo, setLogo,

View file

@ -63,3 +63,8 @@ export const mapSetPublic = (is_public: IMapReducer['is_public']) => ({
type: MAP_ACTIONS.SET_PUBLIC, type: MAP_ACTIONS.SET_PUBLIC,
is_public, is_public,
}); });
export const mapSetLogo = (logo: IMapReducer['logo']) => ({
type: MAP_ACTIONS.SET_LOGO,
logo,
});

View file

@ -9,6 +9,7 @@ export const MAP_ACTIONS = {
SET_ADDRESS: `${P}-SET_ADDRESS`, SET_ADDRESS: `${P}-SET_ADDRESS`,
SET_OWNER: `${P}-SET_OWNER`, SET_OWNER: `${P}-SET_OWNER`,
SET_PUBLIC: `${P}-SET_PUBLIC`, SET_PUBLIC: `${P}-SET_PUBLIC`,
SET_LOGO: `${P}-SET_LOGO`,
ADD_STICKER: `${P}-ADD_STICKER`, ADD_STICKER: `${P}-ADD_STICKER`,
SET_STICKER: `${P}-SET_STICKER`, SET_STICKER: `${P}-SET_STICKER`,

View file

@ -11,6 +11,7 @@ import {
mapSetDescription, mapSetDescription,
mapSetOwner, mapSetOwner,
mapSetPublic, mapSetPublic,
mapSetLogo,
} from './actions'; } from './actions';
const setMap = (state: IMapReducer, { map }: ReturnType<typeof mapSet>): IMapReducer => ({ const setMap = (state: IMapReducer, { map }: ReturnType<typeof mapSet>): IMapReducer => ({
@ -80,6 +81,11 @@ const setPublic = (state: IMapReducer, { is_public }: ReturnType<typeof mapSetPu
is_public, is_public,
}); });
const setLogo = (state: IMapReducer, { logo }: ReturnType<typeof mapSetLogo>): IMapReducer => ({
...state,
logo,
});
export const MAP_HANDLERS = { export const MAP_HANDLERS = {
[MAP_ACTIONS.SET_MAP]: setMap, [MAP_ACTIONS.SET_MAP]: setMap,
[MAP_ACTIONS.SET_PROVIDER]: setProvider, [MAP_ACTIONS.SET_PROVIDER]: setProvider,
@ -92,4 +98,5 @@ export const MAP_HANDLERS = {
[MAP_ACTIONS.SET_DESCRIPTION]: setDescription, [MAP_ACTIONS.SET_DESCRIPTION]: setDescription,
[MAP_ACTIONS.SET_OWNER]: setOwner, [MAP_ACTIONS.SET_OWNER]: setOwner,
[MAP_ACTIONS.SET_PUBLIC]: setPublic, [MAP_ACTIONS.SET_PUBLIC]: setPublic,
[MAP_ACTIONS.SET_LOGO]: setLogo,
}; };

View file

@ -3,12 +3,14 @@ import { MAP_HANDLERS } from './handlers';
import { DEFAULT_PROVIDER } from '$constants/providers'; import { DEFAULT_PROVIDER } from '$constants/providers';
import { IMapRoute } from './types'; import { IMapRoute } from './types';
import { IStickerDump } from '$modules/Sticker'; import { IStickerDump } from '$modules/Sticker';
import { DEFAULT_LOGO } from '$constants/logos';
export interface IMapReducer { export interface IMapReducer {
provider: string; provider: string;
route: IMapRoute; route: IMapRoute;
stickers: IStickerDump[]; stickers: IStickerDump[];
title: string; title: string;
logo: string;
address: string; address: string;
description: string; description: string;
owner: { id: string }; owner: { id: string };
@ -17,6 +19,7 @@ export interface IMapReducer {
export const MAP_INITIAL_STATE: IMapReducer = { export const MAP_INITIAL_STATE: IMapReducer = {
provider: DEFAULT_PROVIDER, provider: DEFAULT_PROVIDER,
logo: DEFAULT_LOGO,
route: [], route: [],
stickers: [], stickers: [],
title: '', title: '',

View file

@ -52,15 +52,15 @@ function* onMapClick({ latlng }: ReturnType<typeof mapClicked>) {
// return put(setMode(MODES.NONE)); // return put(setMode(MODES.NONE));
// } // }
function* setLogoSaga({ logo }: { type: string; logo: string }) { // function* setLogoSaga({ logo }: { type: string; logo: string }) {
const { mode } = yield select(selectUser); // const { mode } = yield select(selectUser);
yield put(setChanged(true)); // yield put(setChanged(true));
if (mode === MODES.LOGO) { // if (mode === MODES.LOGO) {
yield put(setMode(MODES.NONE)); // yield put(setMode(MODES.NONE));
} // }
} // }
export function* replaceAddressIfItsBusy(destination, original) { export function* replaceAddressIfItsBusy(destination, original) {
if (original) { if (original) {
@ -303,10 +303,12 @@ function* setSaveSuccessSaga({
} }
export function* mapSaga() { export function* mapSaga() {
// TODO: setChanged on set route, logo, provider, stickers
yield takeEvery(USER_ACTIONS.SET_ACTIVE_STICKER, setActiveStickerSaga); // TODO: move active sticker to maps yield takeEvery(USER_ACTIONS.SET_ACTIVE_STICKER, setActiveStickerSaga); // TODO: move active sticker to maps
yield takeEvery(MAP_ACTIONS.MAP_CLICKED, onMapClick); yield takeEvery(MAP_ACTIONS.MAP_CLICKED, onMapClick);
yield takeEvery(MAP_ACTIONS.SET_TITLE, setTitleSaga); yield takeEvery(MAP_ACTIONS.SET_TITLE, setTitleSaga);
yield takeEvery(USER_ACTIONS.SET_LOGO, setLogoSaga); // yield takeEvery(USER_ACTIONS.SET_LOGO, setLogoSaga);
yield takeLatest(USER_ACTIONS.SEND_SAVE_REQUEST, sendSaveRequestSaga); yield takeLatest(USER_ACTIONS.SEND_SAVE_REQUEST, sendSaveRequestSaga);
yield takeLatest(USER_ACTIONS.SET_SAVE_SUCCESS, setSaveSuccessSaga); yield takeLatest(USER_ACTIONS.SET_SAVE_SUCCESS, setSaveSuccessSaga);

View file

@ -11,12 +11,12 @@ export const setDistance = (distance: IRootState['distance']) => ({ type: USER_A
export const setChanged = (changed: IRootState['changed']) => ({ type: USER_ACTIONS.SET_CHANGED, changed }); export const setChanged = (changed: IRootState['changed']) => ({ type: USER_ACTIONS.SET_CHANGED, changed });
export const setRouterPoints = routerPoints => ({ type: USER_ACTIONS.SET_ROUTER_POINTS, routerPoints }); export const setRouterPoints = routerPoints => ({ type: USER_ACTIONS.SET_ROUTER_POINTS, routerPoints });
export const setActiveSticker = activeSticker => ({ type: USER_ACTIONS.SET_ACTIVE_STICKER, activeSticker }); export const setActiveSticker = activeSticker => ({ type: USER_ACTIONS.SET_ACTIVE_STICKER, activeSticker });
export const setLogo = logo => ({ type: USER_ACTIONS.SET_LOGO, logo }); // export const setLogo = logo => ({ type: USER_ACTIONS.SET_LOGO, logo });
export const setTitle = title => ({ type: USER_ACTIONS.SET_TITLE, title }); // export const setTitle = title => ({ type: USER_ACTIONS.SET_TITLE, title });
export const setDescription = description => ({ type: USER_ACTIONS.SET_DESCRIPTION, description }); // export const setDescription = description => ({ type: USER_ACTIONS.SET_DESCRIPTION, description });
export const setAddress = address => ({ type: USER_ACTIONS.SET_ADDRESS, address }); // export const setAddress = address => ({ type: USER_ACTIONS.SET_ADDRESS, address });
export const setAddressOrigin = address_origin => ({ type: USER_ACTIONS.SET_ADDRESS_ORIGIN, address_origin }); export const setAddressOrigin = address_origin => ({ type: USER_ACTIONS.SET_ADDRESS_ORIGIN, address_origin });
export const setPublic = is_public => ({ type: USER_ACTIONS.SET_PUBLIC, is_public }); // export const setPublic = is_public => ({ type: USER_ACTIONS.SET_PUBLIC, is_public });
export const setStarred = is_published => ({ type: USER_ACTIONS.SET_STARRED, is_published }); export const setStarred = is_published => ({ type: USER_ACTIONS.SET_STARRED, is_published });
export const setSpeed = speed => ({ type: USER_ACTIONS.SET_SPEED, speed }); export const setSpeed = speed => ({ type: USER_ACTIONS.SET_SPEED, speed });

View file

@ -53,25 +53,25 @@ const setActiveSticker: ActionHandler<typeof ActionCreators.setActiveSticker> =
activeSticker: activeSticker || { set: null, sticker: null } activeSticker: activeSticker || { set: null, sticker: null }
}); });
const setLogo: ActionHandler<typeof ActionCreators.setLogo> = (state, { logo }) => ({ // const setLogo: ActionHandler<typeof ActionCreators.setLogo> = (state, { logo }) => ({
...state, // ...state,
logo // logo
}); // });
const setTitle: ActionHandler<typeof ActionCreators.setTitle> = (state, { title }) => ({ // const setTitle: ActionHandler<typeof ActionCreators.setTitle> = (state, { title }) => ({
...state, // ...state,
title // title
}); // });
const setDescription: ActionHandler<typeof ActionCreators.setDescription> = (state, { description }) => ({ // const setDescription: ActionHandler<typeof ActionCreators.setDescription> = (state, { description }) => ({
...state, // ...state,
description // description
}); // });
const setAddress: ActionHandler<typeof ActionCreators.setAddress> = (state, { address }) => ({ // const setAddress: ActionHandler<typeof ActionCreators.setAddress> = (state, { address }) => ({
...state, // ...state,
address // address
}); // });
const setAddressOrigin: ActionHandler<typeof ActionCreators.setAddressOrigin> = (state, { address_origin }) => ({ const setAddressOrigin: ActionHandler<typeof ActionCreators.setAddressOrigin> = (state, { address_origin }) => ({
...state, ...state,
@ -199,7 +199,7 @@ const searchSetLoading: ActionHandler<typeof ActionCreators.searchSetLoading> =
} }
}); });
const setPublic: ActionHandler<typeof ActionCreators.setPublic> = (state, { is_public = false }) => ({ ...state, is_public }); // const setPublic: ActionHandler<typeof ActionCreators.setPublic> = (state, { is_public = false }) => ({ ...state, is_public });
const setStarred: ActionHandler<typeof ActionCreators.setStarred> = (state, { is_published = false }) => ({ ...state, is_published }); const setStarred: ActionHandler<typeof ActionCreators.setStarred> = (state, { is_published = false }) => ({ ...state, is_published });
const setSpeed: ActionHandler<typeof ActionCreators.setSpeed> = (state, { speed = 15 }) => ({ const setSpeed: ActionHandler<typeof ActionCreators.setSpeed> = (state, { speed = 15 }) => ({
@ -254,10 +254,10 @@ export const USER_HANDLERS = ({
[USER_ACTIONS.SET_DISTANCE]: setDistance, [USER_ACTIONS.SET_DISTANCE]: setDistance,
[USER_ACTIONS.SET_ROUTER_POINTS]: setRouterPoints, [USER_ACTIONS.SET_ROUTER_POINTS]: setRouterPoints,
[USER_ACTIONS.SET_ACTIVE_STICKER]: setActiveSticker, [USER_ACTIONS.SET_ACTIVE_STICKER]: setActiveSticker,
[USER_ACTIONS.SET_LOGO]: setLogo, // [USER_ACTIONS.SET_LOGO]: setLogo,
[USER_ACTIONS.SET_TITLE]: setTitle, // [USER_ACTIONS.SET_TITLE]: setTitle,
[USER_ACTIONS.SET_DESCRIPTION]: setDescription, // [USER_ACTIONS.SET_DESCRIPTION]: setDescription,
[USER_ACTIONS.SET_ADDRESS]: setAddress, // [USER_ACTIONS.SET_ADDRESS]: setAddress,
[USER_ACTIONS.SET_ADDRESS_ORIGIN]: setAddressOrigin, [USER_ACTIONS.SET_ADDRESS_ORIGIN]: setAddressOrigin,
[USER_ACTIONS.SET_SAVE_ERROR]: setSaveError, [USER_ACTIONS.SET_SAVE_ERROR]: setSaveError,
@ -282,7 +282,7 @@ export const USER_HANDLERS = ({
[USER_ACTIONS.SEARCH_SET_TAB]: searchSetTab, [USER_ACTIONS.SEARCH_SET_TAB]: searchSetTab,
[USER_ACTIONS.SEARCH_PUT_ROUTES]: searchPutRoutes, [USER_ACTIONS.SEARCH_PUT_ROUTES]: searchPutRoutes,
[USER_ACTIONS.SEARCH_SET_LOADING]: searchSetLoading, [USER_ACTIONS.SEARCH_SET_LOADING]: searchSetLoading,
[USER_ACTIONS.SET_PUBLIC]: setPublic, // [USER_ACTIONS.SET_PUBLIC]: setPublic,
[USER_ACTIONS.SET_STARRED]: setStarred, [USER_ACTIONS.SET_STARRED]: setStarred,
[USER_ACTIONS.SET_SPEED]: setSpeed, [USER_ACTIONS.SET_SPEED]: setSpeed,