Dev
mohamed 2 years ago
parent 448ad0f5dd
commit a3d83b19fd

@ -20,7 +20,7 @@
"jsonwebtoken": "^9.0.0", "jsonwebtoken": "^9.0.0",
"react": "18.2.0", "react": "18.2.0",
"react-native": "0.71.3", "react-native": "0.71.3",
"react-native-document-picker": "^8.1.4", "react-native-document-picker": "^8.2.0",
"react-native-gesture-handler": "^2.9.0", "react-native-gesture-handler": "^2.9.0",
"react-native-maps": "1.3.2", "react-native-maps": "1.3.2",
"react-native-safe-area-context": "^4.5.0", "react-native-safe-area-context": "^4.5.0",
@ -12210,9 +12210,9 @@
} }
}, },
"node_modules/react-native-document-picker": { "node_modules/react-native-document-picker": {
"version": "8.1.4", "version": "8.2.0",
"resolved": "https://registry.npmjs.org/react-native-document-picker/-/react-native-document-picker-8.1.4.tgz", "resolved": "https://registry.npmjs.org/react-native-document-picker/-/react-native-document-picker-8.2.0.tgz",
"integrity": "sha512-1GJ6jKTxmoT3jyQQjH6cBXZDLLAjCe+f3JE//bfm1+CFa12ziM4wkv8o6sVzbqQWbFr98Mvnx9VKptmUNTXVWQ==", "integrity": "sha512-S/n4DIHWC0DTrtJnj2WZZleIfN4C2QjPMUpe8l/URt2Gc3/95dxkyfp4Dz4d7aZq5yEVFkdAvXv0nyWkM5w4MA==",
"dependencies": { "dependencies": {
"invariant": "^2.2.4" "invariant": "^2.2.4"
}, },
@ -23871,9 +23871,9 @@
} }
}, },
"react-native-document-picker": { "react-native-document-picker": {
"version": "8.1.4", "version": "8.2.0",
"resolved": "https://registry.npmjs.org/react-native-document-picker/-/react-native-document-picker-8.1.4.tgz", "resolved": "https://registry.npmjs.org/react-native-document-picker/-/react-native-document-picker-8.2.0.tgz",
"integrity": "sha512-1GJ6jKTxmoT3jyQQjH6cBXZDLLAjCe+f3JE//bfm1+CFa12ziM4wkv8o6sVzbqQWbFr98Mvnx9VKptmUNTXVWQ==", "integrity": "sha512-S/n4DIHWC0DTrtJnj2WZZleIfN4C2QjPMUpe8l/URt2Gc3/95dxkyfp4Dz4d7aZq5yEVFkdAvXv0nyWkM5w4MA==",
"requires": { "requires": {
"invariant": "^2.2.4" "invariant": "^2.2.4"
} }

@ -21,7 +21,7 @@
"jsonwebtoken": "^9.0.0", "jsonwebtoken": "^9.0.0",
"react": "18.2.0", "react": "18.2.0",
"react-native": "0.71.3", "react-native": "0.71.3",
"react-native-document-picker": "^8.1.4", "react-native-document-picker": "^8.2.0",
"react-native-gesture-handler": "^2.9.0", "react-native-gesture-handler": "^2.9.0",
"react-native-maps": "1.3.2", "react-native-maps": "1.3.2",
"react-native-safe-area-context": "^4.5.0", "react-native-safe-area-context": "^4.5.0",

@ -3,3 +3,5 @@ export const FETCH_TEAMS = 'FETCH_TEAMS';
export const FETCH_SESSIONS = 'FETCH_SESSIONS'; export const FETCH_SESSIONS = 'FETCH_SESSIONS';
export const ADD_TEAM = 'ADD_TEAM'; export const ADD_TEAM = 'ADD_TEAM';
export const ADD_FILE = 'ADD_FILE'; export const ADD_FILE = 'ADD_FILE';
//export const server_link = "https://codefirst.iut.uca.fr/containers/enzojolys-r-dash_container";
export const server_link = "https://r-dash.azurewebsites.net";

@ -1,9 +1,10 @@
import { Alert } from "react-native";
import { Geocalisation } from "../../core/Geocalisation"; import { Geocalisation } from "../../core/Geocalisation";
import { Lap } from "../../core/Lap"; import { Lap } from "../../core/Lap";
import { Point } from "../../core/Point"; import { Point } from "../../core/Point";
import { Session } from "../../core/Session"; import { Session } from "../../core/Session";
import { User } from "../../core/User"; import { User } from "../../core/User";
import { FETCH_SESSIONS } from "../Constants"; import { FETCH_SESSIONS, server_link } from "../Constants";
export const setSessionsList = (sessionsList: Session[]) => { export const setSessionsList = (sessionsList: Session[]) => {
return { return {
@ -34,7 +35,7 @@ export const addXlsFile = (file: File, pseudoPilote: string, email: string, pass
const formData = new FormData(); const formData = new FormData();
formData.append('file', file); formData.append('file', file);
const response = await fetch( const response = await fetch(
`https://r-dash.azurewebsites.net/File?pseudoPilote=${pseudoPilote}&Email=${email}&password=${password}&nameSession=${nameSession}&nameCircuit=${nameCircuit}&typeSession=${typeSession}`, server_link+`/File?pseudoPilote=${pseudoPilote}&Email=${email}&password=${password}&nameSession=${nameSession}&nameCircuit=${nameCircuit}&typeSession=${typeSession}`,
{ {
method: 'POST', method: 'POST',
body: formData body: formData
@ -44,14 +45,14 @@ export const addXlsFile = (file: File, pseudoPilote: string, email: string, pass
return data; return data;
} catch (error) { } catch (error) {
console.log('Error - POST FILE', error); console.log('Error - POST FILE', error);
Alert.alert('Error', 'An error occured while adding a session. (server might be down)');
} }
} }
}; };
export const getSessionsList = () => { export const getSessionsList = () => {
return async dispatch => { return async dispatch => {
try { try {
const sessionsPromise = await fetch('https://r-dash.azurewebsites.net/FullSession'); const sessionsPromise = await fetch(server_link+'/FullSession');
const sessionsListJson = await sessionsPromise.json(); const sessionsListJson = await sessionsPromise.json();
const sessionsList: Session[] = sessionsListJson.map(elt => { const sessionsList: Session[] = sessionsListJson.map(elt => {
const laps: Lap[] = elt["tours"].map(lap => { const laps: Lap[] = elt["tours"].map(lap => {
@ -66,6 +67,7 @@ export const getSessionsList = () => {
dispatch(setSessionsList(sessionsList)); dispatch(setSessionsList(sessionsList));
} catch (error) { } catch (error) {
console.log('Error -- GET SESSIONS', error); console.log('Error -- GET SESSIONS', error);
Alert.alert('Error', 'An error occured while getting sessions. (server might be down)');
//dispatch(fetchDataRejected(error)) //dispatch(fetchDataRejected(error))
} }
} }

@ -1,5 +1,5 @@
import { Team } from "../../core/Team"; import { Team } from "../../core/Team";
import { FETCH_TEAMS, ADD_TEAM } from "../Constants"; import { FETCH_TEAMS, ADD_TEAM, server_link } from "../Constants";
export const setTeamsList = (teamsList: Team[]) => { export const setTeamsList = (teamsList: Team[]) => {
return { return {
@ -11,7 +11,7 @@ export const setTeamsList = (teamsList: Team[]) => {
export const addNewTeam = (newTeam: Team) => { export const addNewTeam = (newTeam: Team) => {
return async dispatch => { return async dispatch => {
try { try {
const response = await fetch('https://r-dash.azurewebsites.net/Ecuries?' + "Email=test@gmail.com" + "&password=test123" + "&pseudoPilote=test_PILOTE", { const response = await fetch(server_link + '/Ecuries?' + "Email=test@gmail.com" + "&password=test123" + "&pseudoPilote=test_PILOTE", {
method: 'POST', method: 'POST',
headers: { headers: {
'Content-Type': 'application/json' 'Content-Type': 'application/json'
@ -33,7 +33,7 @@ export const addNewTeam = (newTeam: Team) => {
export const getTeamsList = () => { export const getTeamsList = () => {
return async dispatch => { return async dispatch => {
try { try {
const teamsPromise = await fetch('https://r-dash.azurewebsites.net/Ecuries'); const teamsPromise = await fetch(server_link+'/Ecuries');
const teamsListJson = await teamsPromise.json(); const teamsListJson = await teamsPromise.json();
const teamsList: Team[] = teamsListJson.map(elt => new Team(elt["name"], elt["owner"], elt["users"], elt["logo"])); const teamsList: Team[] = teamsListJson.map(elt => new Team(elt["name"], elt["owner"], elt["users"], elt["logo"]));
dispatch(setTeamsList(teamsList)); dispatch(setTeamsList(teamsList));

@ -16,7 +16,7 @@ export const setUsersList = (usersList: User[]) => {
export const getUsersList = (team: Team) => { export const getUsersList = (team: Team) => {
return async dispatch => { return async dispatch => {
try { try {
const usersPromise = await fetch('https://codefirst.iut.uca.fr/containers/enzojolys-r-dash_container/Pilotes/'+team); const usersPromise = await fetch(server_link+'/Pilotes/'+team);
const usersListJson = await usersPromise.json(); const usersListJson = await usersPromise.json();
const dto: DtoUserEcurie = usersListJson.map(elt => new DtoUserEcurie(elt["owner"], elt["members"], elt["waitingMember"])); const dto: DtoUserEcurie = usersListJson.map(elt => new DtoUserEcurie(elt["owner"], elt["members"], elt["waitingMember"]));
const usersList: User[] = [] const usersList: User[] = []

@ -1,11 +1,10 @@
import React, { useState } from 'react'; import React, { useState } from 'react';
import { Pressable, StyleSheet, Text, View, Image, TouchableOpacity, TextInput } from 'react-native'; import { Pressable, StyleSheet, Text, View, Image, TouchableOpacity, TextInput } from 'react-native';
import { SafeAreaView } from 'react-native-safe-area-context'; import { SafeAreaView } from 'react-native-safe-area-context';
import * as DocumentPicker from 'expo-document-picker';
import TopBar from '../components/TopBar'; import TopBar from '../components/TopBar';
import { addXlsFile } from '../redux/actions/sessions'; import { addXlsFile } from '../redux/actions/sessions';
import { useDispatch } from 'react-redux'; import { useDispatch } from 'react-redux';
import * as DocumentPicker from 'expo-document-picker';
export default function NewTrack(props: { navigation: any }) { export default function NewTrack(props: { navigation: any }) {
const { navigation } = props; const { navigation } = props;
const dispatch = useDispatch(); const dispatch = useDispatch();
@ -29,19 +28,102 @@ export default function NewTrack(props: { navigation: any }) {
} }
}; };
// const handleConfirm = async () => {
// if (!pickedDocument || !trackName || !sessionName) {
// return;
// }
// const formData = new FormData();
// formData.append('file', {
// uri: pickedDocument.uri,
// type: pickedDocument.type,
// name: pickedDocument.name,
// });
// try {
// await dispatch(addXlsFile(formData, 'test_PILOTE', 'test@gmail.com', 'test123', sessionName, trackName, 'Training'));
// navigation.goBack();
// } catch (error) {
// console.log('Error - POST FILE', error);
// }
// };
// const handleConfirm = async () => {
// if (!pickedDocument || !trackName || !sessionName) {
// return;
// }
// try {
// const file = new File([await pickedDocument.uri], pickedDocument.name, { type: pickedDocument.type });
// const url = 'https://r-dash.azurewebsites.net/File?pseudoPilote=test_PILOTE&nameSession=weekend&nameCircuit=test_CIRCUIT&typeSession=Training';
// const options = {
// method: 'POST',
// body: file,
// headers: {
// 'Content-Type': 'application/octet-stream',
// },
// };
// await fetch(url, options);
// navigation.goBack();
// } catch (error) {
// console.log('Error - POST FILE', error);
// }
// };
// const handleConfirm = async () => {
// if (!pickedDocument || !trackName || !sessionName) {
// return;
// }
// try {
// const file = new File([await pickedDocument.uri], pickedDocument.name, { type: pickedDocument.type });
// const url = 'https://r-dash.azurewebsites.net/File?pseudoPilote=test_PILOTE&nameSession=weekend&nameCircuit=test_CIRCUIT&typeSession=Training';
// const options = {
// method: 'POST',
// body: file,
// headers: {
// 'Content-Type': 'application/octet-stream',
// },
// };
// const response = await fetch(url, options);
// const responseData = await response.text(); // or response.text() or response.blob() depending on the expected response type
// navigation.goBack();
// console.log(responseData);
// } catch (error) {
// console.log('Error - POST FILE', error);
// }
// };
const handleConfirm = async () => { const handleConfirm = async () => {
if (!pickedDocument || !trackName || !sessionName) { if (!pickedDocument || !trackName || !sessionName) {
return; return;
} }
try { try {
await dispatch(addXlsFile(pickedDocument.uri, 'test_PILOTE', 'test@gmail.com', 'test123', sessionName, trackName, 'Training')); const file = new File([await pickedDocument.uri], pickedDocument.name, { type: pickedDocument.type });
const url = 'https://r-dash.azurewebsites.net/File?pseudoPilote=test_PILOTE&nameSession=weeke&nameCircuit=test_CIRCUIT&typeSession=Training';
const formData = new FormData();
formData.append('file', file);
// formData.append('pseudoPilote', 'test_PILOTE');
// formData.append('nameSession', sessionName);
// formData.append('nameCircuit', 'test_CIRCUIT');
// formData.append('typeSession', 'Training');
const response = await fetch(url, {
method: 'POST',
body: file,
headers: {
Accept: '*/*',
'Content-Type': 'multipart/form-data',
},
});
if (!response.ok) {
throw new Error('Failed to upload file');
}
const data = await response.json();
console.log('API response:', data);
navigation.goBack(); navigation.goBack();
} catch (error) { } catch (error) {
console.log('Error - POST FILE', error); console.log('Error - POST FILE', error);
} }
}; };
return ( return (
<SafeAreaView> <SafeAreaView>
<View style={styles.container}> <View style={styles.container}>

Loading…
Cancel
Save