mirror of
https://github.com/muerwre/orchidmap-front.git
synced 2025-04-25 02:56:41 +07:00
removed unnecessary action creators
This commit is contained in:
parent
b75c028ce1
commit
de5726929f
12 changed files with 98 additions and 89 deletions
|
@ -2,14 +2,15 @@ import * as React from 'react';
|
|||
import { LOGOS } from '$constants/logos';
|
||||
import { Icon } from '$components/panels/Icon';
|
||||
import classnames from 'classnames';
|
||||
import { setLogo as setLogoAction } from "$redux/user/actions";
|
||||
import { IRootState } from "$redux/user";
|
||||
import * as MAP_ACTIONS from "$redux/map/actions"
|
||||
import { IMapReducer } from '$redux/map';
|
||||
|
||||
interface Props extends IRootState {
|
||||
setLogo: typeof setLogoAction,
|
||||
interface Props {
|
||||
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="helper logo-helper">
|
||||
<div className="helper-back">
|
||||
|
@ -19,7 +20,7 @@ export const LogoDialog = ({ logo, setLogo }: Props) => (
|
|||
Object.keys(LOGOS).map(item => (
|
||||
<div
|
||||
className={classnames('helper-menu-item', { active: (item === logo) })}
|
||||
onMouseDown={() => setLogo(item)}
|
||||
onMouseDown={() => mapSetLogo(item)}
|
||||
key={item}
|
||||
>
|
||||
{LOGOS[item][0]}
|
||||
|
|
|
@ -11,28 +11,33 @@ import { CancelDialog } from '$components/dialogs/CancelDialog';
|
|||
import { bindActionCreators } from 'redux';
|
||||
import { connect } from 'react-redux';
|
||||
|
||||
import {
|
||||
setMode,
|
||||
setLogo,
|
||||
routerCancel,
|
||||
routerSubmit,
|
||||
setActiveSticker,
|
||||
clearStickers,
|
||||
clearPoly,
|
||||
clearAll,
|
||||
clearCancel,
|
||||
stopEditing,
|
||||
setEditing,
|
||||
sendSaveRequest,
|
||||
changeProvider,
|
||||
} from '$redux/user/actions';
|
||||
import * as USER_ACTIONS from '$redux/user/actions';
|
||||
import { ProviderDialog } from '$components/dialogs/ProviderDialog';
|
||||
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 {
|
||||
width: number,
|
||||
}
|
||||
const mapStateToProps = state => ({ mode: selectUserMode(state) });
|
||||
|
||||
// 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 } = {
|
||||
[MODES.ROUTER]: RouterDialog,
|
||||
|
@ -45,32 +50,12 @@ const DIALOG_CONTENTS: { [x: string]: any } = {
|
|||
[MODES.SHOT_PREFETCH]: ShotPrefetchDialog,
|
||||
};
|
||||
|
||||
export const Component = (props: Props) => (
|
||||
export const Component = (props: Props) =>
|
||||
props.mode && DIALOG_CONTENTS[props.mode]
|
||||
? React.createElement(DIALOG_CONTENTS[props.mode], { ...props })
|
||||
: null
|
||||
);
|
||||
|
||||
const mapStateToProps = ({ user }) => ({ ...user });
|
||||
|
||||
const mapDispatchToProps = dispatch => bindActionCreators({
|
||||
routerCancel,
|
||||
routerSubmit,
|
||||
setLogo,
|
||||
setActiveSticker,
|
||||
clearStickers,
|
||||
clearPoly,
|
||||
clearAll,
|
||||
clearCancel,
|
||||
stopEditing,
|
||||
setEditing,
|
||||
setMode,
|
||||
sendSaveRequest,
|
||||
changeProvider,
|
||||
}, dispatch);
|
||||
? React.createElement(DIALOG_CONTENTS[props.mode])
|
||||
: null;
|
||||
|
||||
export const EditorDialog = connect(
|
||||
mapStateToProps,
|
||||
mapDispatchToProps
|
||||
mapStateToProps
|
||||
// mapDispatchToProps
|
||||
)(Component);
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@ import { Icon } from '$components/panels/Icon';
|
|||
import { EditorDialog } from '$components/panels/EditorDialog';
|
||||
import { bindActionCreators } from '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 { Tooltip } from "$components/panels/Tooltip";
|
||||
|
||||
|
@ -159,7 +159,7 @@ function mapStateToProps(state) {
|
|||
|
||||
const mapDispatchToProps = dispatch => bindActionCreators({
|
||||
setMode,
|
||||
setLogo,
|
||||
// setLogo,
|
||||
startEditing,
|
||||
stopEditing,
|
||||
takeAShot,
|
||||
|
|
|
@ -45,8 +45,12 @@ const Component = ({
|
|||
|
||||
function mapStateToProps(state) {
|
||||
const {
|
||||
map: {
|
||||
provider,
|
||||
logo,
|
||||
},
|
||||
user: {
|
||||
provider, logo, markers_shown, editing
|
||||
markers_shown, editing
|
||||
},
|
||||
} = state;
|
||||
|
||||
|
|
|
@ -12,7 +12,8 @@ import {
|
|||
resetSaveDialog,
|
||||
setActiveSticker,
|
||||
setAddress,
|
||||
setChanged, setDescription,
|
||||
setChanged,
|
||||
setDescription,
|
||||
setDistance,
|
||||
setIsEmpty, setIsRouting,
|
||||
setLogo,
|
||||
|
|
|
@ -63,3 +63,8 @@ export const mapSetPublic = (is_public: IMapReducer['is_public']) => ({
|
|||
type: MAP_ACTIONS.SET_PUBLIC,
|
||||
is_public,
|
||||
});
|
||||
|
||||
export const mapSetLogo = (logo: IMapReducer['logo']) => ({
|
||||
type: MAP_ACTIONS.SET_LOGO,
|
||||
logo,
|
||||
});
|
||||
|
|
|
@ -9,6 +9,7 @@ export const MAP_ACTIONS = {
|
|||
SET_ADDRESS: `${P}-SET_ADDRESS`,
|
||||
SET_OWNER: `${P}-SET_OWNER`,
|
||||
SET_PUBLIC: `${P}-SET_PUBLIC`,
|
||||
SET_LOGO: `${P}-SET_LOGO`,
|
||||
|
||||
ADD_STICKER: `${P}-ADD_STICKER`,
|
||||
SET_STICKER: `${P}-SET_STICKER`,
|
||||
|
|
|
@ -11,6 +11,7 @@ import {
|
|||
mapSetDescription,
|
||||
mapSetOwner,
|
||||
mapSetPublic,
|
||||
mapSetLogo,
|
||||
} from './actions';
|
||||
|
||||
const setMap = (state: IMapReducer, { map }: ReturnType<typeof mapSet>): IMapReducer => ({
|
||||
|
@ -80,6 +81,11 @@ const setPublic = (state: IMapReducer, { is_public }: ReturnType<typeof mapSetPu
|
|||
is_public,
|
||||
});
|
||||
|
||||
const setLogo = (state: IMapReducer, { logo }: ReturnType<typeof mapSetLogo>): IMapReducer => ({
|
||||
...state,
|
||||
logo,
|
||||
});
|
||||
|
||||
export const MAP_HANDLERS = {
|
||||
[MAP_ACTIONS.SET_MAP]: setMap,
|
||||
[MAP_ACTIONS.SET_PROVIDER]: setProvider,
|
||||
|
@ -92,4 +98,5 @@ export const MAP_HANDLERS = {
|
|||
[MAP_ACTIONS.SET_DESCRIPTION]: setDescription,
|
||||
[MAP_ACTIONS.SET_OWNER]: setOwner,
|
||||
[MAP_ACTIONS.SET_PUBLIC]: setPublic,
|
||||
[MAP_ACTIONS.SET_LOGO]: setLogo,
|
||||
};
|
||||
|
|
|
@ -3,12 +3,14 @@ import { MAP_HANDLERS } from './handlers';
|
|||
import { DEFAULT_PROVIDER } from '$constants/providers';
|
||||
import { IMapRoute } from './types';
|
||||
import { IStickerDump } from '$modules/Sticker';
|
||||
import { DEFAULT_LOGO } from '$constants/logos';
|
||||
|
||||
export interface IMapReducer {
|
||||
provider: string;
|
||||
route: IMapRoute;
|
||||
stickers: IStickerDump[];
|
||||
title: string;
|
||||
logo: string;
|
||||
address: string;
|
||||
description: string;
|
||||
owner: { id: string };
|
||||
|
@ -17,6 +19,7 @@ export interface IMapReducer {
|
|||
|
||||
export const MAP_INITIAL_STATE: IMapReducer = {
|
||||
provider: DEFAULT_PROVIDER,
|
||||
logo: DEFAULT_LOGO,
|
||||
route: [],
|
||||
stickers: [],
|
||||
title: '',
|
||||
|
|
|
@ -52,15 +52,15 @@ function* onMapClick({ latlng }: ReturnType<typeof mapClicked>) {
|
|||
// return put(setMode(MODES.NONE));
|
||||
// }
|
||||
|
||||
function* setLogoSaga({ logo }: { type: string; logo: string }) {
|
||||
const { mode } = yield select(selectUser);
|
||||
// function* setLogoSaga({ logo }: { type: string; logo: string }) {
|
||||
// const { mode } = yield select(selectUser);
|
||||
|
||||
yield put(setChanged(true));
|
||||
// yield put(setChanged(true));
|
||||
|
||||
if (mode === MODES.LOGO) {
|
||||
yield put(setMode(MODES.NONE));
|
||||
}
|
||||
}
|
||||
// if (mode === MODES.LOGO) {
|
||||
// yield put(setMode(MODES.NONE));
|
||||
// }
|
||||
// }
|
||||
|
||||
export function* replaceAddressIfItsBusy(destination, original) {
|
||||
if (original) {
|
||||
|
@ -303,10 +303,12 @@ function* setSaveSuccessSaga({
|
|||
}
|
||||
|
||||
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(MAP_ACTIONS.MAP_CLICKED, onMapClick);
|
||||
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.SET_SAVE_SUCCESS, setSaveSuccessSaga);
|
||||
|
||||
|
|
|
@ -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 setRouterPoints = routerPoints => ({ type: USER_ACTIONS.SET_ROUTER_POINTS, routerPoints });
|
||||
export const setActiveSticker = activeSticker => ({ type: USER_ACTIONS.SET_ACTIVE_STICKER, activeSticker });
|
||||
export const setLogo = logo => ({ type: USER_ACTIONS.SET_LOGO, logo });
|
||||
export const setTitle = title => ({ type: USER_ACTIONS.SET_TITLE, title });
|
||||
export const setDescription = description => ({ type: USER_ACTIONS.SET_DESCRIPTION, description });
|
||||
export const setAddress = address => ({ type: USER_ACTIONS.SET_ADDRESS, address });
|
||||
// export const setLogo = logo => ({ type: USER_ACTIONS.SET_LOGO, logo });
|
||||
// export const setTitle = title => ({ type: USER_ACTIONS.SET_TITLE, title });
|
||||
// export const setDescription = description => ({ type: USER_ACTIONS.SET_DESCRIPTION, description });
|
||||
// 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 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 setSpeed = speed => ({ type: USER_ACTIONS.SET_SPEED, speed });
|
||||
|
||||
|
|
|
@ -53,25 +53,25 @@ const setActiveSticker: ActionHandler<typeof ActionCreators.setActiveSticker> =
|
|||
activeSticker: activeSticker || { set: null, sticker: null }
|
||||
});
|
||||
|
||||
const setLogo: ActionHandler<typeof ActionCreators.setLogo> = (state, { logo }) => ({
|
||||
...state,
|
||||
logo
|
||||
});
|
||||
// const setLogo: ActionHandler<typeof ActionCreators.setLogo> = (state, { logo }) => ({
|
||||
// ...state,
|
||||
// logo
|
||||
// });
|
||||
|
||||
const setTitle: ActionHandler<typeof ActionCreators.setTitle> = (state, { title }) => ({
|
||||
...state,
|
||||
title
|
||||
});
|
||||
// const setTitle: ActionHandler<typeof ActionCreators.setTitle> = (state, { title }) => ({
|
||||
// ...state,
|
||||
// title
|
||||
// });
|
||||
|
||||
const setDescription: ActionHandler<typeof ActionCreators.setDescription> = (state, { description }) => ({
|
||||
...state,
|
||||
description
|
||||
});
|
||||
// const setDescription: ActionHandler<typeof ActionCreators.setDescription> = (state, { description }) => ({
|
||||
// ...state,
|
||||
// description
|
||||
// });
|
||||
|
||||
const setAddress: ActionHandler<typeof ActionCreators.setAddress> = (state, { address }) => ({
|
||||
...state,
|
||||
address
|
||||
});
|
||||
// const setAddress: ActionHandler<typeof ActionCreators.setAddress> = (state, { address }) => ({
|
||||
// ...state,
|
||||
// address
|
||||
// });
|
||||
|
||||
const setAddressOrigin: ActionHandler<typeof ActionCreators.setAddressOrigin> = (state, { address_origin }) => ({
|
||||
...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 setSpeed: ActionHandler<typeof ActionCreators.setSpeed> = (state, { speed = 15 }) => ({
|
||||
|
@ -254,10 +254,10 @@ export const USER_HANDLERS = ({
|
|||
[USER_ACTIONS.SET_DISTANCE]: setDistance,
|
||||
[USER_ACTIONS.SET_ROUTER_POINTS]: setRouterPoints,
|
||||
[USER_ACTIONS.SET_ACTIVE_STICKER]: setActiveSticker,
|
||||
[USER_ACTIONS.SET_LOGO]: setLogo,
|
||||
[USER_ACTIONS.SET_TITLE]: setTitle,
|
||||
[USER_ACTIONS.SET_DESCRIPTION]: setDescription,
|
||||
[USER_ACTIONS.SET_ADDRESS]: setAddress,
|
||||
// [USER_ACTIONS.SET_LOGO]: setLogo,
|
||||
// [USER_ACTIONS.SET_TITLE]: setTitle,
|
||||
// [USER_ACTIONS.SET_DESCRIPTION]: setDescription,
|
||||
// [USER_ACTIONS.SET_ADDRESS]: setAddress,
|
||||
[USER_ACTIONS.SET_ADDRESS_ORIGIN]: setAddressOrigin,
|
||||
|
||||
[USER_ACTIONS.SET_SAVE_ERROR]: setSaveError,
|
||||
|
@ -282,7 +282,7 @@ export const USER_HANDLERS = ({
|
|||
[USER_ACTIONS.SEARCH_SET_TAB]: searchSetTab,
|
||||
[USER_ACTIONS.SEARCH_PUT_ROUTES]: searchPutRoutes,
|
||||
[USER_ACTIONS.SEARCH_SET_LOADING]: searchSetLoading,
|
||||
[USER_ACTIONS.SET_PUBLIC]: setPublic,
|
||||
// [USER_ACTIONS.SET_PUBLIC]: setPublic,
|
||||
[USER_ACTIONS.SET_STARRED]: setStarred,
|
||||
[USER_ACTIONS.SET_SPEED]: setSpeed,
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue