You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
35 lines
1.5 KiB
35 lines
1.5 KiB
import { Geocalisation } from "../../core/Geocalisation";
|
|
import { Lap } from "../../core/Lap";
|
|
import { Point } from "../../core/Point";
|
|
import { Session } from "../../core/Session";
|
|
import { Fetch_Sessions } from "../Constants";
|
|
|
|
export const setSessionsList = (sessionsList: Session[]) => {
|
|
return {
|
|
type: Fetch_Sessions,
|
|
payload: sessionsList,
|
|
};
|
|
}
|
|
|
|
export const getSessionsList = () => {
|
|
return async dispatch => {
|
|
try {
|
|
const sessionsPromise = await fetch('https://codefirst.iut.uca.fr/containers/enzojolys-r-dash_container/Sessions');
|
|
const sessionsListJson = await sessionsPromise.json();
|
|
const sessionsList: Session[] = sessionsListJson.map(elt => {
|
|
const laps: Lap[] = elt.laps.map(lap => {
|
|
const points: Point[] = lap.points.map(point => {
|
|
const geo = new Geocalisation(point.geo.latitude, point.geo.longitude);
|
|
return new Point(geo, point.timer, point.distance, point.nGear, point.pBrakeF, point.aSteer, point.rPedal, point.gLong, point.gLat, point.vCar);
|
|
});
|
|
return new Lap(lap.number, points, lap.time);
|
|
});
|
|
return new Session(elt.name, laps, elt.type);
|
|
});
|
|
dispatch(setSessionsList(sessionsList));
|
|
} catch (error) {
|
|
console.log('Error---------', error);
|
|
//dispatch(fetchDataRejected(error))
|
|
}
|
|
}
|
|
} |