mirror of
https://github.com/muerwre/orchidmap-front.git
synced 2025-04-25 11:06:40 +07:00
fixed typescript errors
This commit is contained in:
parent
9a7a038032
commit
fe311e7839
41 changed files with 786 additions and 777 deletions
|
@ -41,7 +41,7 @@ export interface IEditorState {
|
|||
distance: number;
|
||||
estimated: number;
|
||||
speed: number;
|
||||
activeSticker: { set?: string; sticker?: string };
|
||||
activeSticker: { set: string; sticker: string };
|
||||
is_empty: boolean;
|
||||
is_published: boolean;
|
||||
is_routing: boolean;
|
||||
|
@ -134,7 +134,7 @@ export const EDITOR_INITIAL_STATE = {
|
|||
},
|
||||
|
||||
save: {
|
||||
error: null,
|
||||
error: '',
|
||||
finished: false,
|
||||
overwriting: false,
|
||||
processing: false,
|
||||
|
|
|
@ -69,8 +69,14 @@ import uuid from 'uuid';
|
|||
import { getRandomColor, getAdaptiveScale } from '~/utils/dom';
|
||||
|
||||
const hideLoader = () => {
|
||||
document.getElementById('loader').style.opacity = String(0);
|
||||
document.getElementById('loader').style.pointerEvents = 'none';
|
||||
const el = document.getElementById('loader');
|
||||
|
||||
if (!el) {
|
||||
return true;
|
||||
}
|
||||
|
||||
el.style.opacity = String(0);
|
||||
el.style.pointerEvents = 'none';
|
||||
|
||||
return true;
|
||||
};
|
||||
|
@ -125,6 +131,10 @@ function* getRenderData() {
|
|||
canvas.height = window.innerHeight;
|
||||
const ctx = canvas.getContext('2d');
|
||||
|
||||
if (!ctx) {
|
||||
return
|
||||
}
|
||||
|
||||
const geometry = getTilePlacement();
|
||||
const points = getPolyPlacement(route);
|
||||
const sticker_points = getStickersPlacement(stickers);
|
||||
|
@ -184,6 +194,11 @@ function* getCropData({ x, y, width, height }) {
|
|||
canvas.width = width;
|
||||
canvas.height = height;
|
||||
const ctx = canvas.getContext('2d');
|
||||
|
||||
if (!ctx) {
|
||||
return
|
||||
}
|
||||
|
||||
const image = yield imageFetcher(data);
|
||||
|
||||
ctx.drawImage(image, -x, -y);
|
||||
|
@ -281,7 +296,7 @@ function* mapClick({ latlng }: ReturnType<typeof mapClicked>) {
|
|||
|
||||
function* routerSubmit() {
|
||||
const route: ReturnType<typeof selectMapRoute> = yield select(selectMapRoute);
|
||||
const latlngs: LatLng[] = path(['_routes', 0, 'coordinates'], OsrmRouter);
|
||||
const latlngs: LatLng[] = path(['_routes', 0, 'coordinates'], OsrmRouter) || [];
|
||||
|
||||
const coordinates = simplify(latlngs);
|
||||
|
||||
|
|
|
@ -28,9 +28,9 @@ export const MAP_INITIAL_STATE: IMapReducer = {
|
|||
address: '',
|
||||
address_origin: '',
|
||||
description: '',
|
||||
owner: { id: null },
|
||||
owner: { id: '' },
|
||||
is_public: false,
|
||||
zoom: 13,
|
||||
}
|
||||
|
||||
export const map = createReducer(MAP_INITIAL_STATE, MAP_HANDLERS)
|
||||
export const map = createReducer(MAP_INITIAL_STATE, MAP_HANDLERS)
|
||||
|
|
|
@ -1,40 +1,30 @@
|
|||
import {
|
||||
takeEvery,
|
||||
select,
|
||||
put,
|
||||
call,
|
||||
TakeEffect,
|
||||
race,
|
||||
take,
|
||||
takeLatest,
|
||||
delay,
|
||||
} from 'redux-saga/effects';
|
||||
import { call, delay, put, race, select, take, TakeEffect, takeEvery, takeLatest } from 'redux-saga/effects';
|
||||
import { MAP_ACTIONS } from './constants';
|
||||
import {
|
||||
mapClicked,
|
||||
mapAddSticker,
|
||||
mapSetProvider,
|
||||
mapClicked,
|
||||
mapSet,
|
||||
mapSetTitle,
|
||||
mapSetAddressOrigin,
|
||||
mapSetProvider,
|
||||
mapSetRoute,
|
||||
mapSetStickers,
|
||||
mapSetTitle,
|
||||
} from './actions';
|
||||
import { selectUser, selectUserUser } from '~/redux/user/selectors';
|
||||
import { selectUser } from '~/redux/user/selectors';
|
||||
import { MODES } from '~/constants/modes';
|
||||
import {
|
||||
editorCaptureHistory,
|
||||
editorChangeMode,
|
||||
editorClearAll,
|
||||
editorSendSaveRequest,
|
||||
editorSetActiveSticker,
|
||||
editorSetChanged,
|
||||
editorSetEditing,
|
||||
editorSetReady,
|
||||
editorSetActiveSticker,
|
||||
editorSendSaveRequest,
|
||||
editorSetSave,
|
||||
editorClearAll,
|
||||
editorSetHistory,
|
||||
editorCaptureHistory,
|
||||
editorSetReady,
|
||||
editorSetSave,
|
||||
} from '~/redux/editor/actions';
|
||||
import { pushLoaderState, getUrlData, pushPath } from '~/utils/history';
|
||||
import { getUrlData, pushLoaderState, pushPath } from '~/utils/history';
|
||||
import { getStoredMap, postMap } from '~/utils/api';
|
||||
import { Unwrap } from '~/utils/middleware';
|
||||
import { selectMap, selectMapProvider, selectMapRoute, selectMapStickers } from './selectors';
|
||||
|
@ -70,29 +60,36 @@ export function* replaceAddressIfItsBusy(destination, original) {
|
|||
}
|
||||
|
||||
export function* loadMapSaga(path) {
|
||||
const {
|
||||
data: { route, error, random_url },
|
||||
}: Unwrap<typeof getStoredMap> = yield call(getStoredMap, { name: path });
|
||||
try {
|
||||
const {
|
||||
data: {
|
||||
route, error, random_url,
|
||||
},
|
||||
}: Unwrap<typeof getStoredMap> = yield call(getStoredMap, { name: path });
|
||||
|
||||
if (route && !error) {
|
||||
yield put(
|
||||
mapSet({
|
||||
provider: route.provider,
|
||||
route: route.route,
|
||||
stickers: route.stickers,
|
||||
title: route.title,
|
||||
address: route.address,
|
||||
description: route.description,
|
||||
is_public: route.is_public,
|
||||
logo: route.logo,
|
||||
})
|
||||
);
|
||||
if (route && !error) {
|
||||
yield put(
|
||||
mapSet({
|
||||
provider: route.provider,
|
||||
route: route.route,
|
||||
stickers: route.stickers,
|
||||
title: route.title,
|
||||
address: route.address,
|
||||
description: route.description,
|
||||
is_public: route.is_public,
|
||||
logo: route.logo,
|
||||
}),
|
||||
);
|
||||
|
||||
yield put(editorSetHistory({ records: [{ route: route.route, stickers: route.stickers }] }));
|
||||
return { route, random_url };
|
||||
yield put(editorSetHistory({ records: [{ route: route.route, stickers: route.stickers }] }));
|
||||
return { route, random_url };
|
||||
}
|
||||
|
||||
return null;
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
yield call(startEmptyEditorSaga);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
export function* startEmptyEditorSaga() {
|
||||
|
@ -142,10 +139,10 @@ export function* mapInitSaga() {
|
|||
yield put(mapSetProvider(provider));
|
||||
|
||||
if (hash && /^#map/.test(hash)) {
|
||||
const [, newUrl] = hash.match(/^#map[:/?!](.*)$/);
|
||||
const matches = hash.match(/^#map[:/?!](.*)$/);
|
||||
|
||||
if (newUrl) {
|
||||
yield pushPath(`/${newUrl}`);
|
||||
if (matches && matches[1]) {
|
||||
yield pushPath(`/${matches[1]}`);
|
||||
yield call(setReadySaga);
|
||||
return;
|
||||
}
|
||||
|
@ -161,7 +158,7 @@ function* setActiveStickerSaga() {
|
|||
yield put(editorChangeMode(MODES.STICKERS));
|
||||
}
|
||||
|
||||
function* setTitleSaga({ title }: ReturnType<typeof mapSetTitle>) {
|
||||
function setTitleSaga({ title }: ReturnType<typeof mapSetTitle>) {
|
||||
if (title) {
|
||||
document.title = `${title} | Редактор маршрутов`;
|
||||
}
|
||||
|
@ -216,7 +213,7 @@ function* clearSaga({ type }) {
|
|||
const { mode, activeSticker }: ReturnType<typeof selectEditor> = yield select(selectEditor);
|
||||
|
||||
if (activeSticker && activeSticker.set && activeSticker.sticker) {
|
||||
yield put(editorSetActiveSticker(null));
|
||||
yield put(editorSetActiveSticker({ set: '', sticker: '' }));
|
||||
}
|
||||
|
||||
if (mode !== MODES.NONE) {
|
||||
|
@ -231,94 +228,96 @@ function* sendSaveRequestSaga({
|
|||
is_public,
|
||||
description,
|
||||
}: ReturnType<typeof editorSendSaveRequest>) {
|
||||
const { route, stickers, provider }: ReturnType<typeof selectMap> = yield select(selectMap);
|
||||
try {
|
||||
const { route, stickers, provider }: ReturnType<typeof selectMap> = yield select(selectMap);
|
||||
|
||||
if (!route.length && !stickers.length) {
|
||||
return yield put(
|
||||
editorSetSave({ error: TIPS.SAVE_EMPTY, loading: false, overwriting: false, finished: false })
|
||||
if (!route.length && !stickers.length) {
|
||||
return yield put(
|
||||
editorSetSave({ error: TIPS.SAVE_EMPTY, loading: false, overwriting: false, finished: false }),
|
||||
);
|
||||
}
|
||||
|
||||
const { logo }: ReturnType<typeof selectMap> = yield select(selectMap);
|
||||
const { distance }: ReturnType<typeof selectEditor> = yield select(selectEditor);
|
||||
|
||||
yield put(editorSetSave({ loading: true, overwriting: false, finished: false, error: '' }));
|
||||
|
||||
const {
|
||||
result,
|
||||
timeout,
|
||||
cancel,
|
||||
}: {
|
||||
result: Unwrap<typeof postMap>;
|
||||
timeout: boolean;
|
||||
cancel: TakeEffect;
|
||||
} = yield race({
|
||||
result: postMap({
|
||||
route,
|
||||
stickers,
|
||||
title,
|
||||
force,
|
||||
address,
|
||||
logo,
|
||||
distance,
|
||||
provider,
|
||||
is_public,
|
||||
description,
|
||||
}),
|
||||
timeout: delay(10000),
|
||||
cancel: take(EDITOR_ACTIONS.RESET_SAVE_DIALOG),
|
||||
});
|
||||
|
||||
yield put(editorSetSave({ loading: false }));
|
||||
|
||||
if (cancel) return yield put(editorChangeMode(MODES.NONE));
|
||||
|
||||
if (result && result.data.code === 'already_exist')
|
||||
return yield put(editorSetSave({ overwriting: true }));
|
||||
|
||||
if (result && result.data.code === 'conflict')
|
||||
return yield put(
|
||||
editorSetSave({
|
||||
error: TIPS.SAVE_EXISTS,
|
||||
loading: false,
|
||||
overwriting: false,
|
||||
finished: false,
|
||||
}),
|
||||
);
|
||||
|
||||
if (timeout || !result || !result.data.route || !result.data.route.address)
|
||||
return yield put(
|
||||
editorSetSave({
|
||||
error: TIPS.SAVE_TIMED_OUT,
|
||||
loading: false,
|
||||
overwriting: false,
|
||||
finished: false,
|
||||
}),
|
||||
);
|
||||
|
||||
yield put(
|
||||
mapSet({
|
||||
address: result.data.route.address,
|
||||
title: result.data.route.title,
|
||||
is_public: result.data.route.is_public,
|
||||
description: result.data.route.description,
|
||||
}),
|
||||
);
|
||||
|
||||
yield put(editorSetReady(false));
|
||||
pushPath(`/${address}/edit`);
|
||||
yield put(editorSetReady(true));
|
||||
|
||||
yield put(
|
||||
editorSetSave({
|
||||
error: TIPS.SAVE_SUCCESS,
|
||||
loading: false,
|
||||
overwriting: false,
|
||||
finished: true,
|
||||
}),
|
||||
);
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
}
|
||||
|
||||
const { logo }: ReturnType<typeof selectMap> = yield select(selectMap);
|
||||
const { distance }: ReturnType<typeof selectEditor> = yield select(selectEditor);
|
||||
const { token }: ReturnType<typeof selectUserUser> = yield select(selectUserUser);
|
||||
|
||||
yield put(editorSetSave({ loading: true, overwriting: false, finished: false, error: null }));
|
||||
|
||||
const {
|
||||
result,
|
||||
timeout,
|
||||
cancel,
|
||||
}: {
|
||||
result: Unwrap<typeof postMap>;
|
||||
timeout: boolean;
|
||||
cancel: TakeEffect;
|
||||
} = yield race({
|
||||
result: postMap({
|
||||
token,
|
||||
route,
|
||||
stickers,
|
||||
title,
|
||||
force,
|
||||
address,
|
||||
logo,
|
||||
distance,
|
||||
provider,
|
||||
is_public,
|
||||
description,
|
||||
}),
|
||||
timeout: delay(10000),
|
||||
cancel: take(EDITOR_ACTIONS.RESET_SAVE_DIALOG),
|
||||
});
|
||||
|
||||
yield put(editorSetSave({ loading: false }));
|
||||
|
||||
if (cancel) return yield put(editorChangeMode(MODES.NONE));
|
||||
|
||||
if (result && result.data.code === 'already_exist')
|
||||
return yield put(editorSetSave({ overwriting: true }));
|
||||
|
||||
if (result && result.data.code === 'conflict')
|
||||
return yield put(
|
||||
editorSetSave({
|
||||
error: TIPS.SAVE_EXISTS,
|
||||
loading: false,
|
||||
overwriting: false,
|
||||
finished: false,
|
||||
})
|
||||
);
|
||||
|
||||
if (timeout || !result || !result.data.route || !result.data.route.address)
|
||||
return yield put(
|
||||
editorSetSave({
|
||||
error: TIPS.SAVE_TIMED_OUT,
|
||||
loading: false,
|
||||
overwriting: false,
|
||||
finished: false,
|
||||
})
|
||||
);
|
||||
|
||||
yield put(
|
||||
mapSet({
|
||||
address: result.data.route.address,
|
||||
title: result.data.route.title,
|
||||
is_public: result.data.route.is_public,
|
||||
description: result.data.route.description,
|
||||
})
|
||||
);
|
||||
|
||||
yield put(editorSetReady(false));
|
||||
pushPath(`/${address}/edit`);
|
||||
yield put(editorSetReady(true));
|
||||
|
||||
yield put(
|
||||
editorSetSave({
|
||||
error: TIPS.SAVE_SUCCESS,
|
||||
loading: false,
|
||||
overwriting: false,
|
||||
finished: true,
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
function* setChanged() {
|
||||
|
@ -328,14 +327,10 @@ function* setChanged() {
|
|||
yield put(editorSetChanged(true));
|
||||
}
|
||||
|
||||
function* onZoomChange() {
|
||||
|
||||
}
|
||||
|
||||
export function* mapSaga() {
|
||||
yield takeEvery(
|
||||
[MAP_ACTIONS.SET_ROUTE, MAP_ACTIONS.SET_STICKER, MAP_ACTIONS.SET_STICKERS],
|
||||
setChanged
|
||||
setChanged,
|
||||
);
|
||||
|
||||
yield takeEvery(EDITOR_ACTIONS.START_EDITING, startEditingSaga);
|
||||
|
@ -351,6 +346,6 @@ export function* mapSaga() {
|
|||
EDITOR_ACTIONS.CLEAR_ALL,
|
||||
EDITOR_ACTIONS.CLEAR_CANCEL,
|
||||
],
|
||||
clearSaga
|
||||
clearSaga,
|
||||
);
|
||||
}
|
||||
|
|
|
@ -18,9 +18,12 @@ import { map, IMapReducer } from '~/redux/map';
|
|||
import { mapSaga } from '~/redux/map/sagas';
|
||||
import { watchLocation, getLocation } from '~/utils/window';
|
||||
import { LatLngLiteral } from 'leaflet';
|
||||
import { setUserLocation } from './user/actions';
|
||||
import { setUserLocation, userLogout } from './user/actions';
|
||||
import { MainMap } from '~/constants/map';
|
||||
import { mapZoomChange } from './map/actions';
|
||||
import { assocPath } from 'ramda';
|
||||
import { AxiosError } from 'axios';
|
||||
import { api } from '~/utils/api/instance';
|
||||
|
||||
const userPersistConfig: PersistConfig = {
|
||||
key: 'user',
|
||||
|
@ -64,6 +67,28 @@ export function configureStore(): { store: Store<any>; persistor: Persistor } {
|
|||
|
||||
const persistor = persistStore(store);
|
||||
|
||||
// Pass token to axios
|
||||
api.interceptors.request.use(options => {
|
||||
const token = store.getState().user.token;
|
||||
|
||||
if (!token) {
|
||||
return options;
|
||||
}
|
||||
|
||||
return assocPath(['headers', 'authorization'], `Bearer ${token}`, options);
|
||||
});
|
||||
|
||||
// Logout on 401
|
||||
api.interceptors.response.use(undefined, (error: AxiosError<{ error: string }>) => {
|
||||
if (error.response?.status === 401) {
|
||||
store.dispatch(userLogout());
|
||||
}
|
||||
|
||||
error.message = error?.response?.data?.error || error?.response?.statusText || error.message;
|
||||
|
||||
throw error;
|
||||
});
|
||||
|
||||
return { store, persistor };
|
||||
}
|
||||
|
||||
|
@ -74,5 +99,5 @@ history.listen((location, action) => {
|
|||
store.dispatch(editorLocationChanged(location.pathname));
|
||||
});
|
||||
|
||||
watchLocation((location: LatLngLiteral) => store.dispatch(setUserLocation(location)));
|
||||
watchLocation((location: LatLngLiteral | undefined) => store.dispatch(setUserLocation(location)));
|
||||
MainMap.on('zoomend', event => store.dispatch(mapZoomChange(event.target._zoom)))
|
||||
|
|
|
@ -15,7 +15,7 @@ export interface IRouteListItem {
|
|||
export interface IRootReducer {
|
||||
// ready: boolean,
|
||||
user: IUser;
|
||||
location: LatLngLiteral;
|
||||
location?: LatLngLiteral;
|
||||
routes: {
|
||||
limit: 0;
|
||||
loading: boolean;
|
||||
|
@ -38,7 +38,7 @@ export type IRootState = Readonly<IRootReducer>;
|
|||
|
||||
export const INITIAL_STATE: IRootReducer = {
|
||||
user: { ...DEFAULT_USER },
|
||||
location: null,
|
||||
location: undefined,
|
||||
routes: {
|
||||
limit: 0,
|
||||
loading: false, // <-- maybe delete this
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import { REHYDRATE, RehydrateAction } from 'redux-persist';
|
||||
import { takeLatest, select, call, put, takeEvery, delay } from 'redux-saga/effects';
|
||||
import { call, delay, put, select, takeEvery, takeLatest } from 'redux-saga/effects';
|
||||
import {
|
||||
checkIframeToken,
|
||||
checkUserToken,
|
||||
|
@ -9,15 +9,16 @@ import {
|
|||
modifyRoute,
|
||||
sendRouteStarred,
|
||||
} from '~/utils/api';
|
||||
import * as ActionCreators from '~/redux/user/actions';
|
||||
import {
|
||||
searchSetTab,
|
||||
setUser,
|
||||
mapsSetShift,
|
||||
searchChangeDistance,
|
||||
searchPutRoutes,
|
||||
searchSetLoading,
|
||||
searchSetTab,
|
||||
searchSetTitle,
|
||||
setRouteStarred,
|
||||
setUser,
|
||||
userLogin,
|
||||
} from '~/redux/user/actions';
|
||||
|
||||
|
@ -26,8 +27,6 @@ import { USER_ACTIONS } from '~/redux/user/constants';
|
|||
import { DEFAULT_USER } from '~/constants/auth';
|
||||
|
||||
import { DIALOGS, TABS } from '~/constants/dialogs';
|
||||
|
||||
import * as ActionCreators from '~/redux/user/actions';
|
||||
import { Unwrap } from '~/utils/middleware';
|
||||
import { selectUser, selectUserUser } from './selectors';
|
||||
import { mapInitSaga } from '~/redux/map/sagas';
|
||||
|
@ -35,64 +34,71 @@ import { editorSetDialog, editorSetDialogActive } from '../editor/actions';
|
|||
import { selectEditor } from '../editor/selectors';
|
||||
|
||||
function* generateGuestSaga() {
|
||||
const {
|
||||
data: { user, random_url },
|
||||
}: Unwrap<typeof getGuestToken> = yield call(getGuestToken);
|
||||
try {
|
||||
const {
|
||||
data: { user, random_url },
|
||||
}: Unwrap<typeof getGuestToken> = yield call(getGuestToken);
|
||||
|
||||
yield put(setUser({ ...user, random_url }));
|
||||
yield put(setUser({ ...user, random_url }));
|
||||
|
||||
return { ...user, random_url };
|
||||
return { ...user, random_url };
|
||||
} catch(e) {
|
||||
console.log(e)
|
||||
}
|
||||
}
|
||||
|
||||
function* authCheckSaga({ key }: RehydrateAction) {
|
||||
if (key !== 'user') return;
|
||||
try {
|
||||
if (key !== 'user') return;
|
||||
|
||||
pushLoaderState(70);
|
||||
pushLoaderState(70);
|
||||
|
||||
const { id, token }: ReturnType<typeof selectUserUser> = yield select(selectUserUser);
|
||||
const { ready }: ReturnType<typeof selectEditor> = yield select(selectEditor);
|
||||
const { id, token }: ReturnType<typeof selectUserUser> = yield select(selectUserUser);
|
||||
const { ready }: ReturnType<typeof selectEditor> = yield select(selectEditor);
|
||||
|
||||
if (window.location.search || true) {
|
||||
const { viewer_id, auth_key } = yield parseQuery(window.location.search);
|
||||
if (window.location.search || true) {
|
||||
const { viewer_id, auth_key } = yield parseQuery(window.location.search);
|
||||
|
||||
if (viewer_id && auth_key && id !== `vk:${viewer_id}`) {
|
||||
const user = yield call(checkIframeToken, { viewer_id, auth_key });
|
||||
if (viewer_id && auth_key && id !== `vk:${viewer_id}`) {
|
||||
const user = yield call(checkIframeToken, { viewer_id, auth_key });
|
||||
|
||||
if (user) {
|
||||
yield put(setUser(user));
|
||||
|
||||
pushLoaderState(99);
|
||||
|
||||
return yield call(mapInitSaga);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (id && token) {
|
||||
const {
|
||||
data: { user, random_url },
|
||||
}: Unwrap<typeof checkUserToken> = yield call(checkUserToken, {
|
||||
id,
|
||||
});
|
||||
|
||||
if (user) {
|
||||
yield put(setUser(user));
|
||||
yield put(setUser({ ...user, random_url }));
|
||||
|
||||
pushLoaderState(99);
|
||||
|
||||
return yield call(mapInitSaga);
|
||||
} else if (!ready) {
|
||||
pushNetworkInitError();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
yield call(generateGuestSaga);
|
||||
|
||||
pushLoaderState(80);
|
||||
|
||||
return yield call(mapInitSaga);
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
}
|
||||
|
||||
if (id && token) {
|
||||
const {
|
||||
data: { user, random_url },
|
||||
}: Unwrap<typeof checkUserToken> = yield call(checkUserToken, {
|
||||
id,
|
||||
token,
|
||||
});
|
||||
|
||||
if (user) {
|
||||
yield put(setUser({ ...user, random_url }));
|
||||
|
||||
pushLoaderState(99);
|
||||
|
||||
return yield call(mapInitSaga);
|
||||
} else if (!ready) {
|
||||
pushNetworkInitError();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
yield call(generateGuestSaga);
|
||||
|
||||
pushLoaderState(80);
|
||||
|
||||
return yield call(mapInitSaga);
|
||||
}
|
||||
|
||||
function* gotVkUserSaga({ user: u }: ReturnType<typeof ActionCreators.gotVkUser>) {
|
||||
|
@ -105,58 +111,63 @@ function* gotVkUserSaga({ user: u }: ReturnType<typeof ActionCreators.gotVkUser>
|
|||
}
|
||||
|
||||
function* searchGetRoutes() {
|
||||
const { token }: ReturnType<typeof selectUserUser> = yield select(selectUserUser);
|
||||
try {
|
||||
const {
|
||||
routes: {
|
||||
step,
|
||||
shift,
|
||||
filter: { title, distance, tab },
|
||||
},
|
||||
}: ReturnType<typeof selectUser> = yield select(selectUser);
|
||||
|
||||
const {
|
||||
routes: {
|
||||
const result: Unwrap<typeof getRouteList> = yield getRouteList({
|
||||
search: title,
|
||||
min: distance[0],
|
||||
max: distance[1],
|
||||
step,
|
||||
shift,
|
||||
filter: { title, distance, tab },
|
||||
},
|
||||
}: ReturnType<typeof selectUser> = yield select(selectUser);
|
||||
tab,
|
||||
});
|
||||
|
||||
const result: Unwrap<typeof getRouteList> = yield getRouteList({
|
||||
token,
|
||||
search: title,
|
||||
min: distance[0],
|
||||
max: distance[1],
|
||||
step,
|
||||
shift,
|
||||
tab,
|
||||
});
|
||||
|
||||
return result;
|
||||
return result;
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
}
|
||||
}
|
||||
|
||||
export function* searchSetSagaWorker() {
|
||||
const {
|
||||
routes: { filter },
|
||||
}: ReturnType<typeof selectUser> = yield select(selectUser);
|
||||
try {
|
||||
const {
|
||||
routes: { filter },
|
||||
}: ReturnType<typeof selectUser> = yield select(selectUser);
|
||||
|
||||
const {
|
||||
data: {
|
||||
routes,
|
||||
limits: { min, max, count: limit },
|
||||
filter: { shift, step },
|
||||
},
|
||||
}: Unwrap<typeof getRouteList> = yield call(searchGetRoutes);
|
||||
const {
|
||||
data: {
|
||||
routes,
|
||||
limits: { min, max, count: limit },
|
||||
filter: { shift, step },
|
||||
},
|
||||
}: Unwrap<typeof getRouteList> = yield call(searchGetRoutes);
|
||||
|
||||
yield put(searchPutRoutes({ list: routes, min, max, limit, shift, step }));
|
||||
yield put(searchPutRoutes({ list: routes, min, max, limit, shift, step }));
|
||||
|
||||
// change distange range if needed and load additional data
|
||||
if (
|
||||
(filter.min > min && filter.distance[0] <= filter.min) ||
|
||||
(filter.max < max && filter.distance[1] >= filter.max)
|
||||
) {
|
||||
yield put(
|
||||
searchChangeDistance([
|
||||
filter.min > min && filter.distance[0] <= filter.min ? min : filter.distance[0],
|
||||
filter.max < max && filter.distance[1] >= filter.max ? max : filter.distance[1],
|
||||
])
|
||||
);
|
||||
// change distange range if needed and load additional data
|
||||
if (
|
||||
(filter.min > min && filter.distance[0] <= filter.min) ||
|
||||
(filter.max < max && filter.distance[1] >= filter.max)
|
||||
) {
|
||||
yield put(
|
||||
searchChangeDistance([
|
||||
filter.min > min && filter.distance[0] <= filter.min ? min : filter.distance[0],
|
||||
filter.max < max && filter.distance[1] >= filter.max ? max : filter.distance[1],
|
||||
]),
|
||||
);
|
||||
}
|
||||
|
||||
return yield put(searchSetLoading(false));
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
}
|
||||
|
||||
return yield put(searchSetLoading(false));
|
||||
}
|
||||
|
||||
function* searchSetSaga() {
|
||||
|
@ -167,26 +178,30 @@ function* searchSetSaga() {
|
|||
}
|
||||
|
||||
function* openMapDialogSaga({ tab }: ReturnType<typeof ActionCreators.openMapDialog>) {
|
||||
const {
|
||||
routes: {
|
||||
filter: { tab: current },
|
||||
},
|
||||
}: ReturnType<typeof selectUser> = yield select(selectUser);
|
||||
try {
|
||||
const {
|
||||
routes: {
|
||||
filter: { tab: current },
|
||||
},
|
||||
}: ReturnType<typeof selectUser> = yield select(selectUser);
|
||||
|
||||
const { dialog_active }: ReturnType<typeof selectEditor> = yield select(selectEditor);
|
||||
const { dialog_active }: ReturnType<typeof selectEditor> = yield select(selectEditor);
|
||||
|
||||
if (dialog_active && tab === current) {
|
||||
return yield put(editorSetDialogActive(false));
|
||||
if (dialog_active && tab === current) {
|
||||
return yield put(editorSetDialogActive(false));
|
||||
}
|
||||
|
||||
if (tab !== current) {
|
||||
yield put(searchSetTab(tab));
|
||||
}
|
||||
|
||||
yield put(editorSetDialog(DIALOGS.MAP_LIST));
|
||||
yield put(editorSetDialogActive(true));
|
||||
|
||||
return tab;
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
}
|
||||
|
||||
if (tab !== current) {
|
||||
yield put(searchSetTab(tab));
|
||||
}
|
||||
|
||||
yield put(editorSetDialog(DIALOGS.MAP_LIST));
|
||||
yield put(editorSetDialogActive(true));
|
||||
|
||||
return tab;
|
||||
}
|
||||
|
||||
function* searchSetTabSaga() {
|
||||
|
@ -210,78 +225,85 @@ function* setUserSaga() {
|
|||
}
|
||||
|
||||
function* mapsLoadMoreSaga() {
|
||||
const {
|
||||
routes: { limit, list, shift, step, loading, filter },
|
||||
}: ReturnType<typeof selectUser> = yield select(selectUser);
|
||||
try {
|
||||
const {
|
||||
routes: { limit, list, shift, step, loading, filter },
|
||||
}: ReturnType<typeof selectUser> = yield select(selectUser);
|
||||
|
||||
if (loading || list.length >= limit || limit === 0) return;
|
||||
if (loading || list.length >= limit || limit === 0) return;
|
||||
|
||||
yield delay(50);
|
||||
yield delay(50);
|
||||
|
||||
yield put(searchSetLoading(true));
|
||||
yield put(mapsSetShift(shift + step));
|
||||
yield put(searchSetLoading(true));
|
||||
yield put(mapsSetShift(shift + step));
|
||||
|
||||
const {
|
||||
data: {
|
||||
limits: { min, max, count },
|
||||
filter: { shift: resp_shift, step: resp_step },
|
||||
routes,
|
||||
},
|
||||
}: Unwrap<typeof getRouteList> = yield call(searchGetRoutes);
|
||||
const {
|
||||
data: {
|
||||
limits: { min, max, count },
|
||||
filter: { shift: resp_shift, step: resp_step },
|
||||
routes,
|
||||
},
|
||||
}: Unwrap<typeof getRouteList> = yield call(searchGetRoutes);
|
||||
|
||||
if (
|
||||
(filter.min > min && filter.distance[0] <= filter.min) ||
|
||||
(filter.max < max && filter.distance[1] >= filter.max)
|
||||
) {
|
||||
yield put(
|
||||
searchChangeDistance([
|
||||
filter.min > min && filter.distance[0] <= filter.min ? min : filter.distance[0],
|
||||
filter.max < max && filter.distance[1] >= filter.max ? max : filter.distance[1],
|
||||
]),
|
||||
);
|
||||
}
|
||||
|
||||
if (
|
||||
(filter.min > min && filter.distance[0] <= filter.min) ||
|
||||
(filter.max < max && filter.distance[1] >= filter.max)
|
||||
) {
|
||||
yield put(
|
||||
searchChangeDistance([
|
||||
filter.min > min && filter.distance[0] <= filter.min ? min : filter.distance[0],
|
||||
filter.max < max && filter.distance[1] >= filter.max ? max : filter.distance[1],
|
||||
])
|
||||
searchPutRoutes({
|
||||
min,
|
||||
max,
|
||||
limit: count,
|
||||
shift: resp_shift,
|
||||
step: resp_step,
|
||||
list: [...list, ...routes],
|
||||
}),
|
||||
);
|
||||
yield put(searchSetLoading(false));
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
}
|
||||
|
||||
yield put(
|
||||
searchPutRoutes({
|
||||
min,
|
||||
max,
|
||||
limit: count,
|
||||
shift: resp_shift,
|
||||
step: resp_step,
|
||||
list: [...list, ...routes],
|
||||
})
|
||||
);
|
||||
yield put(searchSetLoading(false));
|
||||
}
|
||||
|
||||
function* dropRouteSaga({ address }: ReturnType<typeof ActionCreators.dropRoute>) {
|
||||
const { token }: ReturnType<typeof selectUserUser> = yield select(selectUserUser);
|
||||
const {
|
||||
routes: {
|
||||
list,
|
||||
step,
|
||||
shift,
|
||||
limit,
|
||||
filter: { min, max },
|
||||
},
|
||||
}: ReturnType<typeof selectUser> = yield select(selectUser);
|
||||
|
||||
const index = list.findIndex(el => el.address === address);
|
||||
|
||||
if (index >= 0) {
|
||||
yield put(
|
||||
searchPutRoutes({
|
||||
list: list.filter(el => el.address !== address),
|
||||
min,
|
||||
max,
|
||||
try {
|
||||
const {
|
||||
routes: {
|
||||
list,
|
||||
step,
|
||||
shift: shift > 0 ? shift - 1 : 0,
|
||||
limit: limit > 0 ? limit - 1 : limit,
|
||||
})
|
||||
);
|
||||
}
|
||||
shift,
|
||||
limit,
|
||||
filter: { min, max },
|
||||
},
|
||||
}: ReturnType<typeof selectUser> = yield select(selectUser);
|
||||
|
||||
return yield call(dropRoute, { address, token });
|
||||
const index = list.findIndex(el => el.address === address);
|
||||
|
||||
if (index >= 0) {
|
||||
yield put(
|
||||
searchPutRoutes({
|
||||
list: list.filter(el => el.address !== address),
|
||||
min,
|
||||
max,
|
||||
step,
|
||||
shift: shift > 0 ? shift - 1 : 0,
|
||||
limit: limit > 0 ? limit - 1 : limit,
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
return yield call(dropRoute, { address });
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
}
|
||||
}
|
||||
|
||||
function* modifyRouteSaga({
|
||||
|
@ -289,53 +311,59 @@ function* modifyRouteSaga({
|
|||
title,
|
||||
is_public,
|
||||
}: ReturnType<typeof ActionCreators.modifyRoute>) {
|
||||
const { token }: ReturnType<typeof selectUserUser> = yield select(selectUserUser);
|
||||
const {
|
||||
routes: {
|
||||
list,
|
||||
step,
|
||||
shift,
|
||||
limit,
|
||||
filter: { min, max },
|
||||
},
|
||||
}: ReturnType<typeof selectUser> = yield select(selectUser);
|
||||
|
||||
const index = list.findIndex(el => el.address === address);
|
||||
|
||||
if (index >= 0) {
|
||||
yield put(
|
||||
searchPutRoutes({
|
||||
list: list.map(el => (el.address !== address ? el : { ...el, title, is_public })),
|
||||
min,
|
||||
max,
|
||||
try {
|
||||
const {
|
||||
routes: {
|
||||
list,
|
||||
step,
|
||||
shift: shift > 0 ? shift - 1 : 0,
|
||||
limit: limit > 0 ? limit - 1 : limit,
|
||||
})
|
||||
);
|
||||
}
|
||||
shift,
|
||||
limit,
|
||||
filter: { min, max },
|
||||
},
|
||||
}: ReturnType<typeof selectUser> = yield select(selectUser);
|
||||
|
||||
return yield call(modifyRoute, { address, token, title, is_public });
|
||||
const index = list.findIndex(el => el.address === address);
|
||||
|
||||
if (index >= 0) {
|
||||
yield put(
|
||||
searchPutRoutes({
|
||||
list: list.map(el => (el.address !== address ? el : { ...el, title, is_public })),
|
||||
min,
|
||||
max,
|
||||
step,
|
||||
shift: shift > 0 ? shift - 1 : 0,
|
||||
limit: limit > 0 ? limit - 1 : limit,
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
return yield call(modifyRoute, { address, title, is_public });
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
}
|
||||
}
|
||||
|
||||
function* toggleRouteStarredSaga({
|
||||
address,
|
||||
}: ReturnType<typeof ActionCreators.toggleRouteStarred>) {
|
||||
const { token }: ReturnType<typeof selectUserUser> = yield select(selectUserUser);
|
||||
const {
|
||||
routes: { list },
|
||||
}: ReturnType<typeof selectUser> = yield select(selectUser);
|
||||
try {
|
||||
const {
|
||||
routes: { list },
|
||||
}: ReturnType<typeof selectUser> = yield select(selectUser);
|
||||
|
||||
const route = list.find(el => el.address === address);
|
||||
const route = list.find(el => el.address === address);
|
||||
|
||||
yield put(setRouteStarred(address, !route.is_published));
|
||||
const result = yield sendRouteStarred({
|
||||
token,
|
||||
address,
|
||||
is_published: !route.is_published,
|
||||
});
|
||||
yield put(setRouteStarred(address, !route?.is_published));
|
||||
|
||||
if (!result) return yield put(setRouteStarred(address, route.is_published));
|
||||
const result = yield sendRouteStarred({
|
||||
address,
|
||||
is_published: !route?.is_published,
|
||||
});
|
||||
|
||||
if (!result) return yield put(setRouteStarred(address, !!route?.is_published));
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
}
|
||||
}
|
||||
|
||||
export function* updateUserRoutes() {
|
||||
|
@ -350,7 +378,7 @@ export function* userSaga() {
|
|||
|
||||
yield takeLatest(
|
||||
[USER_ACTIONS.SEARCH_SET_TITLE, USER_ACTIONS.SEARCH_SET_DISTANCE],
|
||||
searchSetSaga
|
||||
searchSetSaga,
|
||||
);
|
||||
|
||||
yield takeLatest(USER_ACTIONS.OPEN_MAP_DIALOG, openMapDialogSaga);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue