début import

Backend/add_session
mohamed 2 years ago
parent ecf486f435
commit 2d684c1640

@ -1,4 +1,4 @@
import { configureStore } from '@reduxjs/toolkit' import { configureStore, getDefaultMiddleware } from '@reduxjs/toolkit'
import appReducer from './reducers/appReducer'; import appReducer from './reducers/appReducer';
// Reference here all your application reducers // Reference here all your application reducers
@ -6,9 +6,13 @@ const reducer = {
appReducer: appReducer, appReducer: appReducer,
} }
// @ts-ignore const middleware = getDefaultMiddleware({
const store = configureStore({ serializableCheck: false, // Disable serializableCheck
reducer, immutableCheck: false
}); });
const store = configureStore({
reducer,
middleware,
});
export default store; export default store;

@ -12,19 +12,39 @@ export const setSessionsList = (sessionsList: Session[]) => {
}; };
} }
export const addXlsFile = async (file: File) => { // export const addXlsFile = async (file: File) => {
// try {
// const formData = new FormData();
// formData.append('file', file);
// 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',
// body: formData
// });
// const data = await response.json();
// return data;
// } catch (error) {
// console.log('Error---------', error);
// }
// };
export const addXlsFile = (file: File, pseudoPilote: string, email: string, password: string, nameSession: string, nameCircuit: string, typeSession: string) => {
return async dispatch => {
try { try {
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=test_PILOTE" + "&Email=test@gmail.com" + "&password=test123" + "&nameSession=test_SESSION" + "&nameCircuit=test_CIRCUIT" + "&typeSession=Unknown", { `https://r-dash.azurewebsites.net/File?pseudoPilote=${pseudoPilote}&Email=${email}&password=${password}&nameSession=${nameSession}&nameCircuit=${nameCircuit}&typeSession=${typeSession}`,
{
method: 'POST', method: 'POST',
body: formData body: formData
}); }
);
const data = await response.json(); const data = await response.json();
return data; return data;
} catch (error) { } catch (error) {
console.log('Error---------', error); console.log('Error - POST FILE', error);
}
} }
}; };
@ -39,13 +59,13 @@ export const getSessionsList = () => {
const geo = new Geocalisation(point["longitude"], point["latitude"]); const geo = new Geocalisation(point["longitude"], point["latitude"]);
return new Point(geo, point["timer"] , point["distance"], point["nGear"], point["pBrakeF"], point["aSteer"], point["rPedal"], point["gLong"], point["gLat"], point["vCar"]); 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["temps"], points, lap["temps"]); return new Lap(lap["numero"], points, lap["temps"]);
}); });
return new Session(elt["name"], laps, elt["type"]); return new Session(elt["name"], laps, elt["type"]);
}); });
dispatch(setSessionsList(sessionsList)); dispatch(setSessionsList(sessionsList));
} catch (error) { } catch (error) {
console.log('Error---------', error); console.log('Error -- GET SESSIONS', error);
//dispatch(fetchDataRejected(error)) //dispatch(fetchDataRejected(error))
} }
} }

@ -3,23 +3,45 @@ import { Pressable, StyleSheet, Text, View, Image, TouchableOpacity, TextInput }
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 { addXlsFile } from '../redux/actions/sessions';
import { useDispatch } from 'react-redux';
export default function NewTrack(props: { navigation: any }) { export default function NewTrack(props: { navigation: any }) {
const { navigation } = props; const { navigation } = props;
const dispatch = useDispatch();
const [pickedDocument, setPickedDocument] = useState<DocumentPicker.DocumentResult | null>(null); const [pickedDocument, setPickedDocument] = useState<DocumentPicker.DocumentResult | null>(null);
const [trackName, setTrackName] = useState('');
const [sessionName, setSessionName] = useState('');
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);
} }
else if(result.type === 'cancel'){
console.log("AAA");
setPickedDocument(null);
}
} catch (err) { } catch (err) {
console.log(err); console.log(err);
} }
}; };
const handleConfirm = async () => {
if (!pickedDocument || !trackName || !sessionName) {
return;
}
try {
await dispatch(addXlsFile(pickedDocument.uri, 'test_PILOTE', 'test@gmail.com', 'test123', sessionName, trackName, 'Training'));
navigation.goBack();
} catch (error) {
console.log('Error - POST FILE', error);
}
};
return ( return (
<SafeAreaView> <SafeAreaView>
<View style={styles.container}> <View style={styles.container}>
@ -33,7 +55,8 @@ export default function NewTrack(props: { navigation: any }) {
<Text style={{ paddingTop: 20 }}>Track name: </Text> <Text style={{ paddingTop: 20 }}>Track name: </Text>
<TextInput <TextInput
style={styles.textInput} style={styles.textInput}
secureTextEntry={true} onChangeText={setTrackName}
value={trackName}
placeholder="Track name" placeholder="Track name"
/> />
</View> </View>
@ -42,7 +65,8 @@ export default function NewTrack(props: { navigation: any }) {
<Text style={{ paddingTop: 20 }}>Session name: </Text> <Text style={{ paddingTop: 20 }}>Session name: </Text>
<TextInput <TextInput
style={styles.textInput} style={styles.textInput}
secureTextEntry={true} onChangeText={setSessionName}
value={sessionName}
placeholder="Session name" placeholder="Session name"
/> />
</View> </View>
@ -67,7 +91,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={handleConfirm}>
<Image <Image
style={styles.return} style={styles.return}
source={require('../assets/images/checked.png')} source={require('../assets/images/checked.png')}

Loading…
Cancel
Save