|
|
@ -1,4 +1,4 @@
|
|
|
|
import React, {useContext} from 'react';
|
|
|
|
import React, {useContext, useEffect, useState} from 'react';
|
|
|
|
import {StyleSheet, View, ScrollView, useWindowDimensions} from 'react-native';
|
|
|
|
import {StyleSheet, View, ScrollView, useWindowDimensions} from 'react-native';
|
|
|
|
import { LinearGradient } from 'expo-linear-gradient';
|
|
|
|
import { LinearGradient } from 'expo-linear-gradient';
|
|
|
|
import { SafeAreaProvider } from 'react-native-safe-area-context';
|
|
|
|
import { SafeAreaProvider } from 'react-native-safe-area-context';
|
|
|
@ -7,17 +7,48 @@ import ProfileModification from '../components/ProfileModification';
|
|
|
|
import ValidateButton from '../components/ValidateButton';
|
|
|
|
import ValidateButton from '../components/ValidateButton';
|
|
|
|
|
|
|
|
|
|
|
|
import ColorContext from '../theme/ColorContext'
|
|
|
|
import ColorContext from '../theme/ColorContext'
|
|
|
|
|
|
|
|
import { useRoute } from '@react-navigation/native';
|
|
|
|
|
|
|
|
import AsyncStorage from '@react-native-async-storage/async-storage';
|
|
|
|
|
|
|
|
|
|
|
|
export default function ModifyProfile(props) {
|
|
|
|
export default function ModifyProfile(props) {
|
|
|
|
const {colors} = useContext(ColorContext);
|
|
|
|
const {colors} = useContext(ColorContext);
|
|
|
|
const all = [{value: "Mussels"}, {value: "Skimmed Milk"}, {value: "Nuts"}]
|
|
|
|
const all = [{value: "Mussels"}, {value: "Skimmed Milk"}, {value: "Nuts"}]
|
|
|
|
const die = [{value: "Dairy free"}, {value: "Gluten free"}, {value: "Porkless"}, {value: "Vegan"}, {value: "Vegetarian"}, {value: "Pescatarian"}]
|
|
|
|
const die = [{value: "Dairy free"}, {value: "Gluten free"}, {value: "Porkless"}, {value: "Vegan"}, {value: "Vegetarian"}, {value: "Pescatarian"}]
|
|
|
|
|
|
|
|
const [profile, setProfile] = useState(null);
|
|
|
|
|
|
|
|
const route = useRoute();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const handleGetProfileByName = async (profileName) => {
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
const existingProfiles = await AsyncStorage.getItem('profiles');
|
|
|
|
|
|
|
|
const profiles = JSON.parse(existingProfiles) || [];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const matchedProfile = profiles.find(profile => profile.name === profileName);
|
|
|
|
|
|
|
|
console.log("Le profil choisit : " + matchedProfile);
|
|
|
|
|
|
|
|
return matchedProfile || null;
|
|
|
|
|
|
|
|
} catch (error) {
|
|
|
|
|
|
|
|
console.log("Erreur lors de la récupération du profil :", error);
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const fetchProfiles = async () => {
|
|
|
|
|
|
|
|
const selectedProfil = await handleGetProfileByName(route.params);
|
|
|
|
|
|
|
|
setProfile(selectedProfil);
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
|
|
|
fetchProfiles();
|
|
|
|
|
|
|
|
}, []);
|
|
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
return (
|
|
|
|
<SafeAreaProvider style={{flex: 1}}>
|
|
|
|
<SafeAreaProvider style={{flex: 1}}>
|
|
|
|
<ScrollView style={{minHeight: useWindowDimensions().height}}>
|
|
|
|
<ScrollView style={{minHeight: useWindowDimensions().height}}>
|
|
|
|
<LinearGradient colors={[colors.primary, colors.primaryComplement]} style={[styles.linearGradient, {minHeight: useWindowDimensions().height}]}>
|
|
|
|
<LinearGradient colors={[colors.primary, colors.primaryComplement]} style={[styles.linearGradient, {minHeight: useWindowDimensions().height}]}>
|
|
|
|
<View style={{marginTop: "6%"}}/>
|
|
|
|
<View style={{marginTop: "6%"}}/>
|
|
|
|
<ProfileModification name="Johnny Silverhand" avatar="plus_small.png" diets={die} allergies={all}></ProfileModification>
|
|
|
|
<ProfileModification name={profile.name} avatar={profile.avatar} diets={profile.diets} allergies={profile.allergies}></ProfileModification>
|
|
|
|
<View style={{marginTop: "3%"}}/>
|
|
|
|
<View style={{marginTop: "3%"}}/>
|
|
|
|
<ValidateButton title="Update Profile" image="update.png" colour={colors.buttonMain} backColour={colors.cardBackground} todo={() => (console.log("Profile Modified"))}></ValidateButton>
|
|
|
|
<ValidateButton title="Update Profile" image="update.png" colour={colors.buttonMain} backColour={colors.cardBackground} todo={() => (console.log("Profile Modified"))}></ValidateButton>
|
|
|
|
<View style={{marginTop: "20%"}}/>
|
|
|
|
<View style={{marginTop: "20%"}}/>
|
|
|
|