forwards and backwards drawing

This commit is contained in:
Fedor Katurov 2020-01-22 15:16:34 +07:00
parent bbd7d6a89a
commit ad676d5fde
11 changed files with 119 additions and 21 deletions

View file

@ -146,3 +146,8 @@ export const editorRedo = () => ({
export const editorCaptureHistory = () => ({
type: EDITOR_ACTIONS.CAPTURE_HIPSTORY,
});
export const editorSetDirection = (drawing_direction: IEditorState['drawing_direction']) => ({
type: EDITOR_ACTIONS.SET_DIRECTION,
drawing_direction,
});

View file

@ -1,5 +1,10 @@
const P = 'EDITOR';
export const DRAWING_DIRECTIONS: Record<'FORWARDS' | 'BACKWARDS', 'forward' | 'backward'> = {
FORWARDS: 'forward',
BACKWARDS: 'backward',
};
export const EDITOR_HISTORY_LENGTH = 100;
export const EDITOR_ACTIONS = {
@ -54,4 +59,6 @@ export const EDITOR_ACTIONS = {
UNDO: `${P}-UNDO`,
REDO: `${P}-REDO`,
CAPTURE_HIPSTORY: `${P}-CAPTURE_HIPSTORY`,
SET_DIRECTION: `${P}-SET_DIRECTION`,
};

View file

@ -179,6 +179,14 @@ const setHistory = (
},
});
const setDirection = (
state,
{ drawing_direction }: ReturnType<typeof ACTIONS.editorSetDirection>
): IEditorState => ({
...state,
drawing_direction,
});
export const EDITOR_HANDLERS = {
[EDITOR_ACTIONS.SET_EDITING]: setEditing,
[EDITOR_ACTIONS.SET_CHANGED]: setChanged,
@ -209,4 +217,6 @@ export const EDITOR_HANDLERS = {
[EDITOR_ACTIONS.SET_NOMINATIM]: setNominatim,
[EDITOR_ACTIONS.SET_HISTORY]: setHistory,
[EDITOR_ACTIONS.SET_DIRECTION]: setDirection,
};

View file

@ -5,6 +5,7 @@ import { EDITOR_HANDLERS } from './handlers';
import { ILatLng } from '../map/types';
import { INominatimResult } from '~/redux/types';
import { IMapReducer } from '../map';
import { DRAWING_DIRECTIONS } from './constants';
export interface IEditorHistoryItem {
route: IMapReducer['route'];
@ -35,6 +36,7 @@ export interface IEditorState {
is_empty: boolean;
is_published: boolean;
is_routing: boolean;
drawing_direction: typeof DRAWING_DIRECTIONS[keyof typeof DRAWING_DIRECTIONS];
features: {
routing: boolean;
@ -63,6 +65,7 @@ export interface IEditorState {
processing: boolean;
loading: boolean;
};
history: {
records: IEditorHistoryItem[];
position: number;
@ -84,13 +87,16 @@ export const EDITOR_INITIAL_STATE = {
estimated: 0,
speed: 15,
activeSticker: { set: null, sticker: null },
drawing_direction: DRAWING_DIRECTIONS.FORWARDS,
is_published: false,
is_empty: true,
is_routing: false,
router: {
waypoints: [],
points: [],
},
is_published: false,
is_empty: true,
is_routing: false,
features: {
routing: false,

View file

@ -9,3 +9,4 @@ export const selectEditorRenderer = (state: IState) => state.editor.renderer;
export const selectEditorRouter = (state: IState) => state.editor.router;
export const selectEditorDistance = (state: IState) => state.editor.distance;
export const selectEditorNominatim = (state: IState) => state.editor.nominatim;
export const selectEditorDirection = (state: IState) => state.editor.drawing_direction;