Alexandre GLENAT 2 years ago
parent 0329133e1a
commit 724f63e605

@ -16,7 +16,8 @@ export const addXlsFile = async (file: File) => {
try { try {
const formData = new FormData(); const formData = new FormData();
formData.append('file', file); formData.append('file', file);
const response = await fetch('https://codefirst.iut.uca.fr/containers/enzojolys-r-dash_container/upload', { const response = await fetch(
'https://r-dash.azurewebsites.net/File?' + "pseudoPilote=test_PILOTE" + "&Email=test@gmail.com" + "&password=test123" + "&nameSession=test_SESSION" + "&nameCircuit=test_CIRCUIT" + "&typeSession=Unknown", {
method: 'POST', method: 'POST',
body: formData body: formData
}); });
@ -30,7 +31,7 @@ export const addXlsFile = async (file: File) => {
export const getSessionsList = (user: User) => { export const getSessionsList = (user: User) => {
return async dispatch => { return async dispatch => {
try { try {
const sessionsPromise = await fetch('https://codefirst.iut.uca.fr/containers/enzojolys-r-dash_container/Sessions/'+user.getUsername); const sessionsPromise = await fetch('https://r-dash.azurewebsites.net/Sessions/'+user.getUsername);
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.laps.map(lap => { const laps: Lap[] = elt.laps.map(lap => {

@ -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://codefirst.iut.uca.fr/containers/enzojolys-r-dash_container/Ecuries', { const response = await fetch('https://r-dash.azurewebsites.net/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://codefirst.iut.uca.fr/containers/enzojolys-r-dash_container/Ecuries'); const teamsPromise = await fetch('https://r-dash.azurewebsites.net/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));

@ -22,16 +22,12 @@ export default function CreateTeam(props: { navigation: any }) {
} }
}; };
const nList = useSelector(state => state.appReducer.teams);
const dispatch = useDispatch(); const dispatch = useDispatch();
useEffect(() => { const onPressAddTeam = async () => {
const addTeams = async () => { dispatch();
await dispatch(addNewTeam()); navigation.goBack();
}; };
addTeams();
}, [dispatch]);
return ( return (
<SafeAreaView style={styles.container}> <SafeAreaView style={styles.container}>
@ -67,7 +63,7 @@ export default function CreateTeam(props: { navigation: any }) {
source={require('../assets/images/return.png')} source={require('../assets/images/return.png')}
/> />
</Pressable> </Pressable>
<Pressable style={styles.button} onPress={() => navigation.goBack()}> <Pressable style={styles.button} onPress={onPressAddTeam}>
<Image <Image
style={styles.return} style={styles.return}
source={require('../assets/images/checked.png')} source={require('../assets/images/checked.png')}

@ -1,9 +1,11 @@
import { StatusBar } from 'expo-status-bar'; import { StatusBar } from 'expo-status-bar';
import React, { useState } from 'react'; import React, { useEffect, useState } from 'react';
import { Button, Pressable, StyleSheet, Text, View, Image, TouchableOpacity, TextInput } from 'react-native'; import { Button, 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 * as DocumentPicker from 'expo-document-picker';
import TopBar from '../components/TopBar'; import TopBar from '../components/TopBar';
import { useDispatch, useSelector } from 'react-redux';
import { addXlsFile } from '../redux/actions/sessions';
export default function NewTrack(props: { navigation: any }) { export default function NewTrack(props: { navigation: any }) {
const { navigation } = props; const { navigation } = props;
@ -12,7 +14,7 @@ export default function NewTrack(props: { navigation: any }) {
const handlePickDocument = async () => { const handlePickDocument = async () => {
try { try {
const result = await DocumentPicker.getDocumentAsync({ type: 'excel/xls' }); const result = await DocumentPicker.getDocumentAsync();
if (result.type === 'success') { if (result.type === 'success') {
setPickedDocument(result); setPickedDocument(result);
} }
@ -21,6 +23,15 @@ export default function NewTrack(props: { navigation: any }) {
} }
}; };
//const nList = useSelector(state => state.appReducer.teams);
const dispatch = useDispatch();
const onPressAddFile = async () => {
dispatch(await addXlsFile(pickedDocument));
navigation.goBack();
};
return ( return (
<SafeAreaView> <SafeAreaView>
<View style={styles.container}> <View style={styles.container}>
@ -68,7 +79,7 @@ export default function NewTrack(props: { navigation: any }) {
source={require('../assets/images/return.png')} source={require('../assets/images/return.png')}
/> />
</Pressable> </Pressable>
<Pressable style={styles.button} onPress={() => navigation.goBack()}> <Pressable style={styles.button} onPress={onPressAddFile}>
<Image <Image
style={styles.return} style={styles.return}
source={require('../assets/images/checked.png')} source={require('../assets/images/checked.png')}

Loading…
Cancel
Save