mirror of
https://github.com/muerwre/orchidmap-front.git
synced 2025-04-25 02:56:41 +07:00
fixed token checking and some types
This commit is contained in:
parent
48cf0b93ee
commit
0018465f15
9 changed files with 65 additions and 81 deletions
|
@ -7,16 +7,13 @@ import { IRoute } from '~/redux/map/types';
|
||||||
import { INominatimResult } from '~/redux/types';
|
import { INominatimResult } from '~/redux/types';
|
||||||
import { api } from './instance';
|
import { api } from './instance';
|
||||||
import { postMapInterceptor } from '~/utils/api/interceptors';
|
import { postMapInterceptor } from '~/utils/api/interceptors';
|
||||||
import { CheckTokenRequest, CheckTokenResult, PostMapRequest, PostMapResponse } from '~/utils/api/types';
|
import {
|
||||||
|
CheckTokenRequest,
|
||||||
interface IGetRouteList {
|
CheckTokenResult,
|
||||||
min: number;
|
GetGuestTokenResult, GetRouteListRequest, GetRouteListResponse, GetStoredMapRequest, GetStoredMapResult,
|
||||||
max: number;
|
PostMapRequest,
|
||||||
tab: string;
|
PostMapResponse,
|
||||||
search: string;
|
} from '~/utils/api/types';
|
||||||
step: IRootState['routes']['step'];
|
|
||||||
shift: IRootState['routes']['step'];
|
|
||||||
}
|
|
||||||
|
|
||||||
export const checkUserToken = ({
|
export const checkUserToken = ({
|
||||||
id,
|
id,
|
||||||
|
@ -29,22 +26,13 @@ export const checkUserToken = ({
|
||||||
|
|
||||||
export const getGuestToken = () =>
|
export const getGuestToken = () =>
|
||||||
api
|
api
|
||||||
.get<{
|
.get<GetGuestTokenResult>(API.GET_GUEST);
|
||||||
user: IUser;
|
|
||||||
random_url: string;
|
|
||||||
}>(API.GET_GUEST);
|
|
||||||
|
|
||||||
export const getStoredMap = ({
|
export const getStoredMap = ({
|
||||||
name,
|
name,
|
||||||
}: {
|
}: GetStoredMapRequest) =>
|
||||||
name: IRoute['address'];
|
|
||||||
}) =>
|
|
||||||
api
|
api
|
||||||
.get<{
|
.get<GetStoredMapResult>(API.GET_MAP, {
|
||||||
route: IRoute;
|
|
||||||
error?: string;
|
|
||||||
random_url: string;
|
|
||||||
}>(API.GET_MAP, {
|
|
||||||
params: { name },
|
params: { name },
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -103,22 +91,9 @@ export const getRouteList = ({
|
||||||
tab,
|
tab,
|
||||||
step,
|
step,
|
||||||
shift,
|
shift,
|
||||||
}: IGetRouteList) =>
|
}: GetRouteListRequest) =>
|
||||||
api
|
api
|
||||||
.get<{
|
.get<GetRouteListResponse>(
|
||||||
routes: IRoute[];
|
|
||||||
limits: {
|
|
||||||
min: number;
|
|
||||||
max: number;
|
|
||||||
count: number;
|
|
||||||
};
|
|
||||||
filter: {
|
|
||||||
min: number;
|
|
||||||
max: number;
|
|
||||||
shift: number;
|
|
||||||
step: number;
|
|
||||||
};
|
|
||||||
}>(
|
|
||||||
API.GET_ROUTE_LIST(tab),
|
API.GET_ROUTE_LIST(tab),
|
||||||
{
|
{
|
||||||
params: {
|
params: {
|
||||||
|
|
|
@ -22,3 +22,42 @@ export interface CheckTokenRequest {
|
||||||
id: IRootState['user']['id'];
|
id: IRootState['user']['id'];
|
||||||
token: string,
|
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;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
|
@ -1,9 +1,4 @@
|
||||||
import { LatLng, LatLngLiteral, point, Point, PointExpression, latLng } from 'leaflet';
|
import { LatLng, latLng, LatLngLiteral, Point, point } from 'leaflet';
|
||||||
|
|
||||||
// interface LatLng {
|
|
||||||
// lat: number;
|
|
||||||
// lng: number;
|
|
||||||
// }
|
|
||||||
|
|
||||||
export const middleCoord = (l1: LatLng, l2: LatLng): LatLng => latLng({
|
export const middleCoord = (l1: LatLng, l2: LatLng): LatLng => latLng({
|
||||||
lat: l2.lat + (l1.lat - l2.lat) / 2,
|
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 => {
|
export const findDistanceHaversine = (t1: number, n1: number, t2: number, n2: number): number => {
|
||||||
const R = 6371; // km
|
const R = 6371; // km
|
||||||
const dLat = ((t2 - t1) * Math.PI) / 180;
|
const dLat = ((t2 - t1) * Math.PI) / 180;
|
||||||
var dLon = ((n2 - n1) * Math.PI) / 180;
|
const dLon = ((n2 - n1) * Math.PI) / 180;
|
||||||
var a =
|
const a =
|
||||||
Math.sin(dLat / 2) * Math.sin(dLat / 2) +
|
Math.sin(dLat / 2) * Math.sin(dLat / 2) +
|
||||||
Math.cos((t1 * Math.PI) / 180) *
|
Math.cos((t1 * Math.PI) / 180) *
|
||||||
Math.cos((t2 * Math.PI) / 180) *
|
Math.cos((t2 * Math.PI) / 180) *
|
||||||
Math.sin(dLon / 2) *
|
Math.sin(dLon / 2) *
|
||||||
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;
|
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 distToSegmentSquared = (A: LatLng, B: LatLng, C: LatLng): number => {
|
||||||
const l2 = dist2(A, B);
|
const l2 = dist2(A, B);
|
||||||
if (l2 == 0) return dist2(C, A);
|
if (l2 === 0) return dist2(C, A);
|
||||||
|
|
||||||
const t = Math.max(
|
const t = Math.max(
|
||||||
0,
|
0,
|
||||||
|
|
|
@ -1,13 +1,5 @@
|
||||||
import { history } from '~/redux/store';
|
import { history } from '~/redux/store';
|
||||||
import {API_RETRY_INTERVAL} from "~/constants/api";
|
import { API_RETRY_INTERVAL } from '~/constants/api';
|
||||||
|
|
||||||
interface IUrlData {
|
|
||||||
path: string,
|
|
||||||
mode: 'edit' | '',
|
|
||||||
host: string,
|
|
||||||
hash: string,
|
|
||||||
protocol: 'http' | 'https',
|
|
||||||
}
|
|
||||||
|
|
||||||
export const getPath = (): string => (window.location && window.location.pathname);
|
export const getPath = (): string => (window.location && window.location.pathname);
|
||||||
export const pushPath = (url: string): string => history.push(url);
|
export const pushPath = (url: string): string => history.push(url);
|
||||||
|
|
|
@ -507,7 +507,7 @@ class InteractivePoly extends Polyline {
|
||||||
const index = this.markers.indexOf(target);
|
const index = this.markers.indexOf(target);
|
||||||
const latlngs = this.getLatLngs();
|
const latlngs = this.getLatLngs();
|
||||||
|
|
||||||
if (typeof index === 'undefined' || latlngs.length == 0) return;
|
if (typeof index === 'undefined' || latlngs.length === 0) return;
|
||||||
|
|
||||||
this.dropMarkerDistanceChange(index);
|
this.dropMarkerDistanceChange(index);
|
||||||
this._map.removeLayer(this.markers[index]);
|
this._map.removeLayer(this.markers[index]);
|
||||||
|
|
|
@ -35,7 +35,7 @@ export const OsrmRouter = Routing.control({
|
||||||
show: false,
|
show: false,
|
||||||
plan: Routing.plan([], {
|
plan: Routing.plan([], {
|
||||||
createMarker: (_, wp) => {
|
createMarker: (_, wp) => {
|
||||||
const marker = new Marker(wp.latLng, {
|
return new Marker(wp.latLng, {
|
||||||
draggable: true,
|
draggable: true,
|
||||||
icon: createWaypointMarker(),
|
icon: createWaypointMarker(),
|
||||||
})
|
})
|
||||||
|
@ -45,12 +45,10 @@ export const OsrmRouter = Routing.control({
|
||||||
OsrmRouter.setWaypoints(
|
OsrmRouter.setWaypoints(
|
||||||
OsrmRouter.getWaypoints().filter(
|
OsrmRouter.getWaypoints().filter(
|
||||||
point =>
|
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,
|
routeWhileDragging: false,
|
||||||
}),
|
}),
|
||||||
|
|
|
@ -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 = (
|
export const createReducer = (
|
||||||
initialState,
|
initialState,
|
||||||
handlers,
|
handlers,
|
||||||
|
|
|
@ -1,18 +1,10 @@
|
||||||
// import { editor } from '~/modules/Editor';
|
import { CLIENT, COLORS } from '~/config/frontend';
|
||||||
import { COLORS, CLIENT } from '~/config/frontend';
|
|
||||||
import saveAs from 'file-saver';
|
import saveAs from 'file-saver';
|
||||||
import { replaceProviderUrl } from '~/constants/providers';
|
import { replaceProviderUrl } from '~/constants/providers';
|
||||||
import { STICKERS } from '~/constants/stickers';
|
import { STICKERS } from '~/constants/stickers';
|
||||||
import { IRoute } from '~/redux/map/types';
|
import { IRoute, IStickerDump } from '~/redux/map/types';
|
||||||
import { IStickerDump } from '~/redux/map/types';
|
import { angleBetweenPoints, angleBetweenPointsRad, findDistancePx, middleCoordPx } from '~/utils/geom';
|
||||||
import { IRootState } from '~/redux/user';
|
import { LatLng, latLng, Point } from 'leaflet';
|
||||||
import {
|
|
||||||
angleBetweenPoints,
|
|
||||||
angleBetweenPointsRad,
|
|
||||||
findDistancePx,
|
|
||||||
middleCoordPx,
|
|
||||||
} from '~/utils/geom';
|
|
||||||
import { Point, LatLng, latLng } from 'leaflet';
|
|
||||||
import { MainMap } from '~/constants/map';
|
import { MainMap } from '~/constants/map';
|
||||||
|
|
||||||
export interface ITilePlacement {
|
export interface ITilePlacement {
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import { Map, LineUtil, LatLng } from 'leaflet';
|
import { LatLng, LineUtil } from 'leaflet';
|
||||||
import { MainMap } from '~/constants/map';
|
import { MainMap } from '~/constants/map';
|
||||||
|
|
||||||
export const simplify = (latlngs: LatLng[]): LatLng[] => {
|
export const simplify = (latlngs: LatLng[]): LatLng[] => {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue