mirror of
https://github.com/muerwre/orchidmap-front.git
synced 2025-04-25 02:56:41 +07:00
adding stickers on click
This commit is contained in:
parent
e0048d1fc3
commit
6db2809de5
11 changed files with 83 additions and 20 deletions
|
@ -1,11 +1,12 @@
|
||||||
import * as React from 'react';
|
import * as React from 'react';
|
||||||
import { Icon } from '$components/panels/Icon';
|
import { Icon } from '$components/panels/Icon';
|
||||||
import { IModes, MODES } from '$constants/modes';
|
import { MODES } from '$constants/modes';
|
||||||
import { IStickerPack, STICKERS } from '$constants/stickers';
|
import { IStickerPack, STICKERS } from '$constants/stickers';
|
||||||
import { StickerIcon } from '$components/StickerIcon';
|
import { StickerIcon } from '$components/StickerIcon';
|
||||||
|
import { IRootReducer } from '$redux/user';
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
mode: keyof IModes,
|
mode: IRootReducer['mode'],
|
||||||
sticker: string,
|
sticker: string,
|
||||||
set: keyof IStickerPack,
|
set: keyof IStickerPack,
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,5 @@
|
||||||
export interface IModes {
|
|
||||||
[x: string]: string,
|
|
||||||
}
|
|
||||||
|
|
||||||
export const MODES: IModes = {
|
export const MODES = {
|
||||||
POLY: 'POLY',
|
POLY: 'POLY',
|
||||||
STICKERS: 'STICKERS',
|
STICKERS: 'STICKERS',
|
||||||
STICKERS_SELECT: 'STICKERS_SELECT',
|
STICKERS_SELECT: 'STICKERS_SELECT',
|
||||||
|
|
|
@ -17,16 +17,15 @@ import { TopRightPanel } from '$components/panels/TopRightPanel';
|
||||||
import { LogoPreview } from '$components/logo/LogoPreview';
|
import { LogoPreview } from '$components/logo/LogoPreview';
|
||||||
import { IStickerPack } from "$constants/stickers";
|
import { IStickerPack } from "$constants/stickers";
|
||||||
import { IDialogs } from "$constants/dialogs";
|
import { IDialogs } from "$constants/dialogs";
|
||||||
import { IModes } from "$constants/modes";
|
|
||||||
|
|
||||||
import { Map } from "$containers/map/Map"
|
import { Map } from "$containers/map/Map"
|
||||||
import { TileLayer } from '$containers/map/TileLayer';
|
import { IRootReducer } from '$redux/user';
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
sticker: string,
|
sticker: string,
|
||||||
renderer_active: boolean,
|
renderer_active: boolean,
|
||||||
|
|
||||||
mode: keyof IModes,
|
mode: IRootReducer['mode'],
|
||||||
dialog: keyof IDialogs,
|
dialog: keyof IDialogs,
|
||||||
dialog_active: boolean,
|
dialog_active: boolean,
|
||||||
set: keyof IStickerPack,
|
set: keyof IStickerPack,
|
||||||
|
|
|
@ -24,7 +24,8 @@ const mapStateToProps = state => ({
|
||||||
const mapDispatchToProps = {
|
const mapDispatchToProps = {
|
||||||
mapSetRoute: MAP_ACTIONS.mapSetRoute,
|
mapSetRoute: MAP_ACTIONS.mapSetRoute,
|
||||||
mapDropSticker: MAP_ACTIONS.mapDropSticker,
|
mapDropSticker: MAP_ACTIONS.mapDropSticker,
|
||||||
mapSetSticker: MAP_ACTIONS.mapSetSticker
|
mapSetSticker: MAP_ACTIONS.mapSetSticker,
|
||||||
|
mapClicked: MAP_ACTIONS.mapClicked
|
||||||
};
|
};
|
||||||
|
|
||||||
type IProps = React.HTMLAttributes<HTMLDivElement> &
|
type IProps = React.HTMLAttributes<HTMLDivElement> &
|
||||||
|
@ -37,26 +38,41 @@ const MapUnconnected: React.FC<IProps> = ({
|
||||||
stickers,
|
stickers,
|
||||||
editing,
|
editing,
|
||||||
|
|
||||||
|
mapClicked,
|
||||||
mapSetRoute,
|
mapSetRoute,
|
||||||
mapSetSticker,
|
mapSetSticker,
|
||||||
mapDropSticker
|
mapDropSticker
|
||||||
}) => {
|
}) => {
|
||||||
const ref = React.useRef(null);
|
const ref = React.useRef(null);
|
||||||
const [maps, setMaps] = React.useState<MapInterface>(null);
|
const [layer, setLayer] = React.useState<MapInterface>(null);
|
||||||
|
|
||||||
|
const onClick = React.useCallback(event => {
|
||||||
|
mapClicked(event.latlng);
|
||||||
|
}, [mapClicked]);
|
||||||
|
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
if (!ref.current) return;
|
if (!ref.current) return;
|
||||||
|
|
||||||
setMaps(map(ref.current).setView([55.0153275, 82.9071235], 13));
|
setLayer(map(ref.current).setView([55.0153275, 82.9071235], 13));
|
||||||
}, [ref]);
|
}, [ref]);
|
||||||
|
|
||||||
|
React.useEffect(() => {
|
||||||
|
if (!layer) return;
|
||||||
|
|
||||||
|
layer.addEventListener("click", onClick)
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
layer.removeEventListener("click", onClick)
|
||||||
|
}
|
||||||
|
}, [layer, onClick]);
|
||||||
|
|
||||||
return createPortal(
|
return createPortal(
|
||||||
<div ref={ref}>
|
<div ref={ref}>
|
||||||
<TileLayer provider={provider} map={maps} />
|
<TileLayer provider={provider} map={layer} />
|
||||||
<Route route={route} mapSetRoute={mapSetRoute} map={maps} is_editing={editing} />
|
<Route route={route} mapSetRoute={mapSetRoute} map={layer} is_editing={editing} />
|
||||||
<Stickers
|
<Stickers
|
||||||
stickers={stickers}
|
stickers={stickers}
|
||||||
map={maps}
|
map={layer}
|
||||||
mapSetSticker={mapSetSticker}
|
mapSetSticker={mapSetSticker}
|
||||||
mapDropSticker={mapDropSticker}
|
mapDropSticker={mapDropSticker}
|
||||||
is_editing={editing}
|
is_editing={editing}
|
||||||
|
|
|
@ -59,11 +59,9 @@ const Route: FC<IProps> = memo(({ route, is_editing, mapSetRoute, map }) => {
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!layer) return;
|
if (!layer) return;
|
||||||
|
|
||||||
console.log('route use effect!')
|
|
||||||
|
|
||||||
const points = (route && route.length > 0 && route) || [];
|
const points = (route && route.length > 0 && route) || [];
|
||||||
|
|
||||||
layer.setPoints(points as LatLng[]); // TODO: refactor this
|
layer.setPoints(points as LatLng[]);
|
||||||
}, [route, layer]);
|
}, [route, layer]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
import { MAP_ACTIONS } from "./constants";
|
import { MAP_ACTIONS } from "./constants";
|
||||||
import { IMapReducer } from "./";
|
import { IMapReducer } from "./";
|
||||||
import { IStickerDump } from "$modules/Sticker";
|
import { IStickerDump } from "$modules/Sticker";
|
||||||
|
import { ILatLng } from "./types";
|
||||||
|
|
||||||
export const mapSet = (map: Partial<IMapReducer>) => ({
|
export const mapSet = (map: Partial<IMapReducer>) => ({
|
||||||
type: MAP_ACTIONS.SET_MAP,
|
type: MAP_ACTIONS.SET_MAP,
|
||||||
|
@ -27,3 +28,8 @@ export const mapDropSticker = (index: number) => ({
|
||||||
type: MAP_ACTIONS.DROP_STICKER,
|
type: MAP_ACTIONS.DROP_STICKER,
|
||||||
index,
|
index,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
export const mapClicked = (latlng: ILatLng) => ({
|
||||||
|
type: MAP_ACTIONS.MAP_CLICKED,
|
||||||
|
latlng,
|
||||||
|
});
|
||||||
|
|
|
@ -7,4 +7,6 @@ export const MAP_ACTIONS = {
|
||||||
|
|
||||||
SET_STICKER: `${P}-SET_STICKER`,
|
SET_STICKER: `${P}-SET_STICKER`,
|
||||||
DROP_STICKER: `${P}-DROP_STICKER`,
|
DROP_STICKER: `${P}-DROP_STICKER`,
|
||||||
|
|
||||||
|
MAP_CLICKED: `${P}-MAP_CLICKED`
|
||||||
}
|
}
|
40
src/redux/map/sagas.ts
Normal file
40
src/redux/map/sagas.ts
Normal file
|
@ -0,0 +1,40 @@
|
||||||
|
import { takeEvery, select, put } from "redux-saga/effects";
|
||||||
|
import { MAP_ACTIONS } from "./constants";
|
||||||
|
import { mapClicked, mapSet } from "./actions";
|
||||||
|
import { selectUserMode, selectUserActiveSticker } from "$redux/user/selectors";
|
||||||
|
import { IRootReducer } from "$redux/user";
|
||||||
|
import { MODES } from "$constants/modes";
|
||||||
|
import { selectMapStickers } from "./selectors";
|
||||||
|
import { setActiveSticker, setMode } from "$redux/user/actions";
|
||||||
|
|
||||||
|
function* onMapClick({ latlng }: ReturnType<typeof mapClicked>) {
|
||||||
|
const mode = yield select(selectUserMode);
|
||||||
|
const { set, sticker } = yield select(selectUserActiveSticker);
|
||||||
|
const stickers = yield select(selectMapStickers);
|
||||||
|
|
||||||
|
switch (mode) {
|
||||||
|
case MODES.STICKERS:
|
||||||
|
yield put(
|
||||||
|
mapSet({
|
||||||
|
stickers: [
|
||||||
|
...stickers,
|
||||||
|
{
|
||||||
|
latlng,
|
||||||
|
set,
|
||||||
|
sticker,
|
||||||
|
text: "",
|
||||||
|
angle: 0,
|
||||||
|
}
|
||||||
|
]
|
||||||
|
})
|
||||||
|
);
|
||||||
|
yield put(setMode(MODES.NONE))
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export function* mapSaga() {
|
||||||
|
yield takeEvery(MAP_ACTIONS.MAP_CLICKED, onMapClick);
|
||||||
|
}
|
|
@ -6,6 +6,7 @@ import createSagaMiddleware from 'redux-saga';
|
||||||
|
|
||||||
import { userReducer, IRootReducer } from '$redux/user';
|
import { userReducer, IRootReducer } from '$redux/user';
|
||||||
import { userSaga } from '$redux/user/sagas';
|
import { userSaga } from '$redux/user/sagas';
|
||||||
|
import { mapSaga } from '$redux/map/sagas';
|
||||||
import { createBrowserHistory } from 'history';
|
import { createBrowserHistory } from 'history';
|
||||||
import { locationChanged } from '$redux/user/actions';
|
import { locationChanged } from '$redux/user/actions';
|
||||||
import { PersistConfig, Persistor } from "redux-persist/es/types";
|
import { PersistConfig, Persistor } from "redux-persist/es/types";
|
||||||
|
@ -42,6 +43,7 @@ export const store = createStore(
|
||||||
|
|
||||||
export function configureStore(): { store: Store<any>, persistor: Persistor } {
|
export function configureStore(): { store: Store<any>, persistor: Persistor } {
|
||||||
sagaMiddleware.run(userSaga);
|
sagaMiddleware.run(userSaga);
|
||||||
|
sagaMiddleware.run(mapSaga);
|
||||||
|
|
||||||
const persistor = persistStore(store);
|
const persistor = persistStore(store);
|
||||||
|
|
||||||
|
|
|
@ -37,7 +37,7 @@ export interface IRootReducer {
|
||||||
ready: boolean,
|
ready: boolean,
|
||||||
user: IUser,
|
user: IUser,
|
||||||
editing: boolean,
|
editing: boolean,
|
||||||
mode: keyof typeof MODES,
|
mode: typeof MODES[keyof typeof MODES],
|
||||||
logo: keyof typeof LOGOS,
|
logo: keyof typeof LOGOS,
|
||||||
routerPoints: number,
|
routerPoints: number,
|
||||||
distance: number,
|
distance: number,
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
import { IState } from '$redux/store'
|
import { IState } from '$redux/store'
|
||||||
|
|
||||||
export const selectUserEditing = (state: IState) => state.user.editing;
|
export const selectUserEditing = (state: IState) => state.user.editing;
|
||||||
|
export const selectUserMode = (state: IState) => state.user.mode;
|
||||||
|
export const selectUserActiveSticker = (state: IState) => state.user.activeSticker;
|
Loading…
Add table
Add a link
Reference in a new issue