From 03ee5026d0a5c7617e43bb9e3557ab5169e1af9a Mon Sep 17 00:00:00 2001 From: squishyhoshi Date: Tue, 21 Nov 2023 20:32:37 -0500 Subject: [PATCH] [47] finished survey --- frontend/assets/foodQuestions.tsx | 16 +++ frontend/src/screens/foodForum.tsx | 182 ++++++++++++++++++++++++++++- 2 files changed, 192 insertions(+), 6 deletions(-) create mode 100644 frontend/assets/foodQuestions.tsx diff --git a/frontend/assets/foodQuestions.tsx b/frontend/assets/foodQuestions.tsx new file mode 100644 index 0000000..3436313 --- /dev/null +++ b/frontend/assets/foodQuestions.tsx @@ -0,0 +1,16 @@ +interface SliderData { + id: number; + label: string; + minValue: number; + maxValue: number; + initialValue: number; +} + +const foodSlidersData: SliderData[] = [ + { id: 1, label: 'Beef', minValue: 0, maxValue: 8, initialValue: 0 }, + { id: 2, label: 'Lamb', minValue: 0, maxValue: 8, initialValue: 0 }, + { id: 3, label: 'Pork', minValue: 0, maxValue: 8, initialValue: 0 }, + { id: 4, label: 'Chicken/Fish', minValue: 0, maxValue: 8, initialValue: 0 }, +]; + +export default foodSlidersData; diff --git a/frontend/src/screens/foodForum.tsx b/frontend/src/screens/foodForum.tsx index 0230524..6364f2c 100644 --- a/frontend/src/screens/foodForum.tsx +++ b/frontend/src/screens/foodForum.tsx @@ -1,9 +1,14 @@ -import { StyleSheet, Text, View } from 'react-native'; +import { StyleSheet, Text, View, ScrollView, TouchableOpacity, TextInput } from 'react-native'; import * as React from 'react'; import { type StackNavigationProp } from '@react-navigation/stack'; import { type RootStackParamList } from '../components/types'; import { useFonts } from 'expo-font'; import Colors from '../../assets/colorConstants'; +import { useState } from 'react'; +import { useNavigation } from '@react-navigation/native'; +import foodSliderData from '../../assets/foodQuestions'; +import { SafeAreaView } from 'react-native-safe-area-context'; +import Slider from '@react-native-community/slider'; export type StackNavigation = StackNavigationProp; @@ -13,14 +18,131 @@ export default function FoodForum(): JSX.Element { Josefin: require('../../assets/fonts/JosefinSansThinRegular.ttf'), }); + const navigation = useNavigation(); + + const slidersData = foodSliderData; + + const [sliderValues, setSliderValues] = useState( + slidersData.map((data) => data.initialValue) + ); + + const onSliderValueChange = (value: number, index: number): void => { + const updatedValues = [...sliderValues]; + updatedValues[index] = value; + setSliderValues(updatedValues); + switch (index) { + case 0: + setBeefServing(value); + break; + case 1: + setLambServing(value); + break; + case 2: + setPorkServing(value); + break; + case 3: + setChickenServing(value); + break; + case 4: + setCheeseServing(value); + break; + default: + break; + } + }; + + const [beefServing, setBeefServing] = useState(0); + const [lambServing, setLambServing] = useState(0); + const [porkServing, setPorkServing] = useState(0); + const [chickenServing, setChickenServing] = useState(0); + const [cheeseServing, setCheeseServing] = useState(0); + const [milkServing, setMilkServing] = useState(0); + const [foodWaste, setFoodWaste] = useState(0); + + const handleSurveySubmit = (): void => { + // Process survey responses, e.g., send them to a server + console.log('Survey Responses:', { + beefServing, + lambServing, + porkServing, + chickenServing, + cheeseServing, + milkServing, + foodWaste, + }); + + navigation.navigate('EnergyForum'); + }; + if (!loaded) { return <>; } return ( - - Calculate your food intake: - + + + Calculate your emissions from food: + + + On average, how many servings of the following food do you consume per week (Each serving + is 100g): + + + {slidersData.map((slider, index) => ( + + + {slider.label}: {sliderValues[index]} Servings + + onSliderValueChange(value, index)} + /> + + {slider.minValue} + {slider.maxValue} + + {/* You can include additional components related to this slider here */} + + ))} + + + How many cups of milk do you drink per week: + { + setMilkServing(Number(text)); + }} + /> + + + + + On average, how much food waste do you produce, in grams: + + { + setFoodWaste(Number(text) / 100); + }} + /> + + + + Next + + + ); } @@ -28,14 +150,62 @@ const styles = StyleSheet.create({ container: { flex: 1, justifyContent: 'center', + backgroundColor: Colors.LIGHTFGREEN, + }, + labelContainer: { + flexDirection: 'row', + justifyContent: 'space-between', + width: '100%', + paddingHorizontal: 12, + }, + scrollContainer: { + paddingTop: 30, + flex: 1, paddingHorizontal: 30, backgroundColor: Colors.LIGHTFGREEN, }, + label: { + fontSize: 15, + }, header: { color: Colors.DARKGREEN, fontFamily: 'Montserrat', - fontSize: 30, + fontSize: 25, + fontWeight: '700', + marginBottom: 50, + }, + question: { + fontFamily: 'Montserrat', + fontSize: 20, fontWeight: '700', - marginBottom: 30, + color: Colors.DARKGREEN, + marginBottom: 20, + }, + input: { + borderWidth: 1, + borderColor: Colors.GREY, + padding: 8, + margin: 10, + width: 200, + backgroundColor: Colors.WHITE, + }, + buttoning: { + backgroundColor: Colors.DARKGREEN, + borderRadius: 10, + marginBottom: 70, + padding: 18, + }, + buttoningText: { + color: Colors.WHITE, + fontSize: 16, + fontWeight: '700', + textAlign: 'center', + }, + questionContainer: { + paddingBottom: 30, + }, + silder: { + height: 50, + width: '100%', }, });