import React, { useState } from "react"; import { StyleSheet, SafeAreaView, Text, TextInput, View } from "react-native"; import { Button} from 'native-base'; import { useTheme } from '@react-navigation/native'; function DefinedPRs({route, navigation}) { const { colors } = useTheme(); const [benchpress, setBenchpress] = useState(''); const [squat, setSquat] = useState(''); const [deadlift, setDeadlift] = useState(''); const postDefPRStats=() => { if (benchpress != '' || squat != '' || deadlift != '') { fetch(localhost+'/signup/defPRStat', { method: "PUT", headers: { 'Accept': 'application/json', 'Content-Type': 'application/json' }, body: JSON.stringify({ "username": route.params.username, "bench_press": benchpress, "squat": squat, "deadlift": deadlift }) }) .then( function(response) { if (response.status === 200 || response.status === 201) { // Successful POST console.log('good defPRStat'); alert("Successfully added!") navigation.navigate("UniqueAvgStats", { username: route.params.username }); } else { // Examine the text in the response console.log('issue in defPRStat. Status code: '+ response.status); alert("Unsuccessful") } } ) .catch(function(err) { console.log('Fetch Error :-S', err); }); } navigation.navigate("UniqueAvgStats", { username: route.params.username }); } return ( <SafeAreaView style={ [styles.screen, {flexDirection:"column"}] }> <Text style={ [styles.title, {color: colors.text}] }>Enter personal records (lbs)</Text> <Text style={ [styles.subtitle, {color: colors.text}] }>Bench Press:</Text> <TextInput placeholder = "200" style={ [styles.input, {color: colors.text}] } onChangeText={(benchpress) => setBenchpress(benchpress)} /> <Text style={ [styles.subtitle, {color: colors.text}] }>Squats:</Text> <TextInput placeholder = "270" style={ [styles.input, {color: colors.text}] } onChangeText={(squat) => setSquat(squat)} /> <Text style={ [styles.subtitle, {color: colors.text}] }>Deadlift:</Text> <TextInput placeholder = "250" style={ [styles.input, {color: colors.text}] } onChangeText={(deadlift) => setDeadlift(deadlift)} /> <View style={{flexDirection: "row"}}> <Button style={ styles.nextButton } onPress={postDefPRStats}> <Text style={ styles.nextText } >Next</Text> </Button> </View> </SafeAreaView> ); } const styles = StyleSheet.create({ screen:{ marginTop: "20%", paddingLeft: "5%", paddingRight: "5%", paddingBottom: "30%", marginLeft: "10%", marginRight: "10%" }, title: { fontSize: 25, fontWeight: "bold", marginTop: "10%", paddingBottom: "20%", textAlign:"left" }, subtitle: { fontSize: 16, textAlign:"left", fontWeight: "bold", color: '#5c5a55' }, input: { width: "100%", height: 40, borderBottomWidth: 1 }, nextButton: { width: '100%', justifyContent: 'center', backgroundColor: "#d4911c", borderRadius: 10, alignItems: "center", marginBottom: 10, marginTop: 50 }, nextText: { fontSize: 16, fontWeight: "bold", color: "white" }, }); export default DefinedPRs;