BoilerLiftUp / src / components / signup / DefinedAverageStats.jsx
DefinedAverageStats.jsx
Raw
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 DefinedAverageStats({route, navigation}) {
    const { colors } = useTheme();

    const [benchpress, setBenchpress] = useState('');
    const [squat, setSquat] = useState('');
    const [deadlift, setDeadlift] = useState('');

    const postDefAvgStats=() => {
        if (benchpress != '' || squat != '' || deadlift != '') {
            fetch(localhost+'/signup/defAvgStat', {
                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 postDefAvgStats');
                        alert("Successfully added!")
                        navigation.navigate("DefinedPRs", {
                            username: route.params.username
                        });
                    } else {
                        // Examine the text in the response
                        console.log('issue in postDefAvgStats. Status code: '+ response.status);
                        alert("Unsuccessful")
                    }
                }
            )
            .catch(function(err) {
                console.log('Fetch Error :-S', err);
            });
        }
        navigation.navigate("DefinedPRs", {
            username: route.params.username
        });
    }

    return (
        <SafeAreaView style={ [styles.screen, {flexDirection:"column"}] }>
            <Text style={ [styles.title, {color: colors.text}] }>Enter average stats (lbs)</Text>
            <Text style={ [styles.subtitle, {color: colors.text}] }>Bench Press:</Text>
            <TextInput placeholder = "150" style={ [styles.input, {color: colors.text}] } onChangeText={(benchpress) => setBenchpress(benchpress)} />
            <Text style={ [styles.subtitle, {color: colors.text}] }>Squats:</Text>
            <TextInput placeholder = "200" style={ [styles.input, {color: colors.text}] } onChangeText={(squat) => setSquat(squat)} />
            <Text style={ [styles.subtitle, {color: colors.text}] }>Deadlift:</Text>
            <TextInput placeholder = "180" style={ [styles.input, {color: colors.text}] } onChangeText={(deadlift) => setDeadlift(deadlift)} />
            <View style={{flexDirection: "row"}}>
                <Button style={ styles.nextButton } onPress={postDefAvgStats} >
                    <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 DefinedAverageStats;