diff --git a/src/utils/api/index.ts b/src/utils/api/index.ts index d89e12d..1c6776d 100644 --- a/src/utils/api/index.ts +++ b/src/utils/api/index.ts @@ -7,16 +7,13 @@ import { IRoute } from '~/redux/map/types'; import { INominatimResult } from '~/redux/types'; import { api } from './instance'; import { postMapInterceptor } from '~/utils/api/interceptors'; -import { CheckTokenRequest, CheckTokenResult, PostMapRequest, PostMapResponse } from '~/utils/api/types'; - -interface IGetRouteList { - min: number; - max: number; - tab: string; - search: string; - step: IRootState['routes']['step']; - shift: IRootState['routes']['step']; -} +import { + CheckTokenRequest, + CheckTokenResult, + GetGuestTokenResult, GetRouteListRequest, GetRouteListResponse, GetStoredMapRequest, GetStoredMapResult, + PostMapRequest, + PostMapResponse, +} from '~/utils/api/types'; export const checkUserToken = ({ id, @@ -29,22 +26,13 @@ export const checkUserToken = ({ export const getGuestToken = () => api - .get<{ - user: IUser; - random_url: string; - }>(API.GET_GUEST); + .get(API.GET_GUEST); export const getStoredMap = ({ name, -}: { - name: IRoute['address']; -}) => +}: GetStoredMapRequest) => api - .get<{ - route: IRoute; - error?: string; - random_url: string; - }>(API.GET_MAP, { + .get(API.GET_MAP, { params: { name }, }); @@ -103,22 +91,9 @@ export const getRouteList = ({ tab, step, shift, -}: IGetRouteList) => +}: GetRouteListRequest) => api - .get<{ - routes: IRoute[]; - limits: { - min: number; - max: number; - count: number; - }; - filter: { - min: number; - max: number; - shift: number; - step: number; - }; - }>( + .get( API.GET_ROUTE_LIST(tab), { params: { diff --git a/src/utils/api/types.ts b/src/utils/api/types.ts index b0ded9a..48dbf1e 100644 --- a/src/utils/api/types.ts +++ b/src/utils/api/types.ts @@ -22,3 +22,42 @@ export interface CheckTokenRequest { id: IRootState['user']['id']; token: string, } + +export interface GetGuestTokenResult { + user: IUser; + random_url: string; +} + +export interface GetStoredMapResult { + route: IRoute; + error?: string; + random_url: string; +} + +export interface GetStoredMapRequest { + name: IRoute['address']; +} + +export interface GetRouteListRequest { + min: number; + max: number; + tab: string; + search: string; + step: IRootState['routes']['step']; + shift: IRootState['routes']['step']; +} + +export interface GetRouteListResponse { + routes: IRoute[]; + limits: { + min: number; + max: number; + count: number; + }; + filter: { + min: number; + max: number; + shift: number; + step: number; + }; +} diff --git a/src/utils/geom.ts b/src/utils/geom.ts index bfc3341..02afe02 100644 --- a/src/utils/geom.ts +++ b/src/utils/geom.ts @@ -1,9 +1,4 @@ -import { LatLng, LatLngLiteral, point, Point, PointExpression, latLng } from 'leaflet'; - -// interface LatLng { -// lat: number; -// lng: number; -// } +import { LatLng, latLng, LatLngLiteral, Point, point } from 'leaflet'; export const middleCoord = (l1: LatLng, l2: LatLng): LatLng => latLng({ lat: l2.lat + (l1.lat - l2.lat) / 2, @@ -46,14 +41,14 @@ export const findDistance = (t1: number, n1: number, t2: number, n2: number): nu export const findDistanceHaversine = (t1: number, n1: number, t2: number, n2: number): number => { const R = 6371; // km const dLat = ((t2 - t1) * Math.PI) / 180; - var dLon = ((n2 - n1) * Math.PI) / 180; - var a = + const dLon = ((n2 - n1) * Math.PI) / 180; + const a = Math.sin(dLat / 2) * Math.sin(dLat / 2) + Math.cos((t1 * Math.PI) / 180) * Math.cos((t2 * Math.PI) / 180) * Math.sin(dLon / 2) * Math.sin(dLon / 2); - var c = 2 * Math.asin(Math.sqrt(a)); + const c = 2 * Math.asin(Math.sqrt(a)); return R * c; }; @@ -88,7 +83,7 @@ export const dist2 = (A: LatLngLiteral, B: LatLngLiteral): number => const distToSegmentSquared = (A: LatLng, B: LatLng, C: LatLng): number => { const l2 = dist2(A, B); - if (l2 == 0) return dist2(C, A); + if (l2 === 0) return dist2(C, A); const t = Math.max( 0, diff --git a/src/utils/history.ts b/src/utils/history.ts index c2435c9..e203911 100644 --- a/src/utils/history.ts +++ b/src/utils/history.ts @@ -1,13 +1,5 @@ import { history } from '~/redux/store'; -import {API_RETRY_INTERVAL} from "~/constants/api"; - -interface IUrlData { - path: string, - mode: 'edit' | '', - host: string, - hash: string, - protocol: 'http' | 'https', -} +import { API_RETRY_INTERVAL } from '~/constants/api'; export const getPath = (): string => (window.location && window.location.pathname); export const pushPath = (url: string): string => history.push(url); diff --git a/src/utils/map/InteractivePoly.ts b/src/utils/map/InteractivePoly.ts index fa445bc..70aac65 100644 --- a/src/utils/map/InteractivePoly.ts +++ b/src/utils/map/InteractivePoly.ts @@ -507,7 +507,7 @@ class InteractivePoly extends Polyline { const index = this.markers.indexOf(target); const latlngs = this.getLatLngs(); - if (typeof index === 'undefined' || latlngs.length == 0) return; + if (typeof index === 'undefined' || latlngs.length === 0) return; this.dropMarkerDistanceChange(index); this._map.removeLayer(this.markers[index]); diff --git a/src/utils/map/OsrmRouter.ts b/src/utils/map/OsrmRouter.ts index 1b3a461..6da8fd8 100644 --- a/src/utils/map/OsrmRouter.ts +++ b/src/utils/map/OsrmRouter.ts @@ -35,7 +35,7 @@ export const OsrmRouter = Routing.control({ show: false, plan: Routing.plan([], { createMarker: (_, wp) => { - const marker = new Marker(wp.latLng, { + return new Marker(wp.latLng, { draggable: true, icon: createWaypointMarker(), }) @@ -45,12 +45,10 @@ export const OsrmRouter = Routing.control({ OsrmRouter.setWaypoints( OsrmRouter.getWaypoints().filter( point => - !point.latLng || (point.latLng.lat != latlng.lat && point.latLng.lng != latlng.lng) + !point.latLng || (point.latLng.lat !== latlng.lat && point.latLng.lng !== latlng.lng) ) ); }); - - return marker; }, routeWhileDragging: false, }), diff --git a/src/utils/reducer.ts b/src/utils/reducer.ts index 1121914..46e5a2d 100644 --- a/src/utils/reducer.ts +++ b/src/utils/reducer.ts @@ -1,10 +1,3 @@ -// create-reducer.ts -import { Action } from 'redux'; - -type Handlers> = { - readonly [Type in Types]: (state: State, action: Actions) => State -} - export const createReducer = ( initialState, handlers, diff --git a/src/utils/renderer.ts b/src/utils/renderer.ts index f76f0bc..1620790 100644 --- a/src/utils/renderer.ts +++ b/src/utils/renderer.ts @@ -1,18 +1,10 @@ -// import { editor } from '~/modules/Editor'; -import { COLORS, CLIENT } from '~/config/frontend'; +import { CLIENT, COLORS } from '~/config/frontend'; import saveAs from 'file-saver'; import { replaceProviderUrl } from '~/constants/providers'; import { STICKERS } from '~/constants/stickers'; -import { IRoute } from '~/redux/map/types'; -import { IStickerDump } from '~/redux/map/types'; -import { IRootState } from '~/redux/user'; -import { - angleBetweenPoints, - angleBetweenPointsRad, - findDistancePx, - middleCoordPx, -} from '~/utils/geom'; -import { Point, LatLng, latLng } from 'leaflet'; +import { IRoute, IStickerDump } from '~/redux/map/types'; +import { angleBetweenPoints, angleBetweenPointsRad, findDistancePx, middleCoordPx } from '~/utils/geom'; +import { LatLng, latLng, Point } from 'leaflet'; import { MainMap } from '~/constants/map'; export interface ITilePlacement { diff --git a/src/utils/simplify.ts b/src/utils/simplify.ts index 4c20705..1ed303d 100644 --- a/src/utils/simplify.ts +++ b/src/utils/simplify.ts @@ -1,4 +1,4 @@ -import { Map, LineUtil, LatLng } from 'leaflet'; +import { LatLng, LineUtil } from 'leaflet'; import { MainMap } from '~/constants/map'; export const simplify = (latlngs: LatLng[]): LatLng[] => {