fixed token checking and some types

This commit is contained in:
Fedor Katurov 2021-04-20 17:26:36 +07:00
parent 48cf0b93ee
commit 0018465f15
9 changed files with 65 additions and 81 deletions

View file

@ -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<GetGuestTokenResult>(API.GET_GUEST);
export const getStoredMap = ({
name,
}: {
name: IRoute['address'];
}) =>
}: GetStoredMapRequest) =>
api
.get<{
route: IRoute;
error?: string;
random_url: string;
}>(API.GET_MAP, {
.get<GetStoredMapResult>(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<GetRouteListResponse>(
API.GET_ROUTE_LIST(tab),
{
params: {

View file

@ -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;
};
}

View file

@ -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,

View file

@ -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);

View file

@ -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]);

View file

@ -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,
}),

View file

@ -1,10 +1,3 @@
// create-reducer.ts
import { Action } from 'redux';
type Handlers<State, Types extends string, Actions extends Action<Types>> = {
readonly [Type in Types]: (state: State, action: Actions) => State
}
export const createReducer = (
initialState,
handlers,

View file

@ -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 {

View file

@ -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[] => {