start to bind modify profile
continuous-integration/drone/push Build is passing Details

pull/23/head
Rayhân HASSOU 1 year ago
parent 0d30b9a8fe
commit 8e14883221

@ -37,7 +37,7 @@ export default function ProfilesStackScreen({ navigation }) {
const _handleSearch = () => { const _handleSearch = () => {
console.log('Searching'); console.log('Searching');
} }
const _handleHeaderAdd = () => navigation.navigate('ProfileCreation'); const _handleHeaderAdd = () => navigation.navigate('ProfileCreation', { name: String });
return ( return (
<ProfilesStack.Navigator> <ProfilesStack.Navigator>

@ -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%"}}/>

@ -23,6 +23,9 @@ export default function Profiles({navigation, props}) {
const [profiles, setProfiles] = useState([]); const [profiles, setProfiles] = useState([]);
const [selectedProfileIndex, setSelectedProfileIndex] = useState(null); const [selectedProfileIndex, setSelectedProfileIndex] = useState(null);
const goDetails = (name: string) => navigation.navigate('ProfileCreation', name);
const raisePopUp = (index) => { const raisePopUp = (index) => {
setSelectedProfileIndex(index) setSelectedProfileIndex(index)
setVisible(true) setVisible(true)
@ -122,7 +125,6 @@ export default function Profiles({navigation, props}) {
width: "100%", width: "100%",
flex: 1, flex: 1,
}, },
profileValidation: { profileValidation: {
width: "100%", width: "100%",
alignItems: "center", alignItems: "center",
@ -205,6 +207,7 @@ export default function Profiles({navigation, props}) {
diets={profile.diets} diets={profile.diets}
allergies={profile.allergies} allergies={profile.allergies}
onDeleteProfile={() => raisePopUp(index)} onDeleteProfile={() => raisePopUp(index)}
onModification={() => goDetails(profile.name)}
/> />
<Portal> <Portal>
<Modal visible={visible} onDismiss={erasePopUp} contentContainerStyle={containerStyle} style={{marginTop: 0, justifyContent: "flex-start"}}> <Modal visible={visible} onDismiss={erasePopUp} contentContainerStyle={containerStyle} style={{marginTop: 0, justifyContent: "flex-start"}}>
@ -255,7 +258,6 @@ export default function Profiles({navigation, props}) {
<View style={{marginBottom: "20%"}}/> <View style={{marginBottom: "20%"}}/>
</LinearGradient> </LinearGradient>
</ScrollView> </ScrollView>
</PaperProvider> </PaperProvider>
</SafeAreaProvider> </SafeAreaProvider>
); );

Loading…
Cancel
Save