|
|
|
@ -1,32 +1,81 @@
|
|
|
|
|
import React, { useContext } from 'react';
|
|
|
|
|
import {StyleSheet, View, ScrollView, useWindowDimensions} from 'react-native';
|
|
|
|
|
import React, { useContext, useState } from 'react';
|
|
|
|
|
import {StyleSheet, View, ScrollView, useWindowDimensions, TextInput, Image, Text, NativeEventEmitter, Pressable} from 'react-native';
|
|
|
|
|
import { LinearGradient } from 'expo-linear-gradient';
|
|
|
|
|
import { SafeAreaProvider } from 'react-native-safe-area-context';
|
|
|
|
|
|
|
|
|
|
import ProfileModification from '../components/ProfileModification';
|
|
|
|
|
import ValidateButton from '../components/ValidateButton';
|
|
|
|
|
import ColorContext from '../theme/ColorContext';
|
|
|
|
|
import ListWithoutSelect from '../components/ListWithoutSelect';
|
|
|
|
|
import ListSelect from '../components/ListSelect';
|
|
|
|
|
import AsyncStorage from '@react-native-async-storage/async-storage';
|
|
|
|
|
import EventEmitter from './EventEmitter';
|
|
|
|
|
import * as ImagePicker from 'expo-image-picker';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export default function CreateProfile(props) {
|
|
|
|
|
const { colors } = useContext(ColorContext)
|
|
|
|
|
const all = []
|
|
|
|
|
const die = [{value: "Dairy free"}, {value: "Gluten free"}, {value: "Porkless"}, {value: "Vegan"}, {value: "Vegetarian"}, {value: "Pescatarian"}]
|
|
|
|
|
const [name, onChangeName] = useState();
|
|
|
|
|
const [avatar, setAvatar] = useState<string>('');
|
|
|
|
|
const [selectedDiets, setSelectedDiets] = useState([]);
|
|
|
|
|
|
|
|
|
|
const handleSelectedDiets = (selectedValues) => {
|
|
|
|
|
setSelectedDiets(selectedValues);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const pickImage = async () => {
|
|
|
|
|
// No permissions request is necessary for launching the image library
|
|
|
|
|
let result = await ImagePicker.launchImageLibraryAsync({
|
|
|
|
|
mediaTypes: ImagePicker.MediaTypeOptions.All,
|
|
|
|
|
allowsEditing: true,
|
|
|
|
|
aspect: [4, 3],
|
|
|
|
|
quality: 1,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
console.log(result);
|
|
|
|
|
|
|
|
|
|
if (!result.canceled) {
|
|
|
|
|
setAvatar(result.assets[0].uri);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let imageSource
|
|
|
|
|
if (props.avatar == "plus.png"){
|
|
|
|
|
imageSource = {uri: avatar}
|
|
|
|
|
}
|
|
|
|
|
else if (props.avatar == "plus_small.png"){
|
|
|
|
|
imageSource = {uri: avatar}
|
|
|
|
|
}
|
|
|
|
|
else{
|
|
|
|
|
imageSource = {uri: avatar}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const handleCreateProfile = () => {
|
|
|
|
|
const profileData = {
|
|
|
|
|
name: "Nom du profil", // Remplacez par le nom du profil
|
|
|
|
|
avatar: "Lien de l'avatar", // Remplacez par le lien de l'avatar
|
|
|
|
|
diets: die.map(item => item.value), // Liste des régimes
|
|
|
|
|
allergies: all, // Liste des allergies
|
|
|
|
|
};
|
|
|
|
|
const handleCreateProfile = async () => {
|
|
|
|
|
try {
|
|
|
|
|
// Ton code pour récupérer les profils existants et ajouter un nouveau profil
|
|
|
|
|
const newProfile = {
|
|
|
|
|
name: name,
|
|
|
|
|
avatar: avatar,
|
|
|
|
|
diets: selectedDiets,
|
|
|
|
|
allergies: all,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
localStorage.setItem('profile', JSON.stringify(profileData));
|
|
|
|
|
console.log("Profil créé :", profileData);
|
|
|
|
|
// Mettre à jour AsyncStorage avec le nouveau profil
|
|
|
|
|
let existingProfiles = await AsyncStorage.getItem('profiles');
|
|
|
|
|
existingProfiles = existingProfiles ? JSON.parse(existingProfiles) : [];
|
|
|
|
|
const updatedProfiles = [...existingProfiles, newProfile];
|
|
|
|
|
await AsyncStorage.setItem('profiles', JSON.stringify(updatedProfiles));
|
|
|
|
|
EventEmitter.emit('profileAdded');
|
|
|
|
|
|
|
|
|
|
// Redirection vers la page précédente avec un message de confirmation
|
|
|
|
|
props.navigation.goBack();
|
|
|
|
|
// Affichage d'un message
|
|
|
|
|
alert("Profil créé !");
|
|
|
|
|
console.log('Profil créé :', newProfile);
|
|
|
|
|
|
|
|
|
|
props.navigation.goBack();
|
|
|
|
|
|
|
|
|
|
alert('Profil créé !');
|
|
|
|
|
} catch (error) {
|
|
|
|
|
console.error('Erreur lors de la création du profil :', error);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const styles = StyleSheet.create({
|
|
|
|
@ -36,7 +85,74 @@ export default function CreateProfile(props) {
|
|
|
|
|
flex: 1,
|
|
|
|
|
padding: "2%",
|
|
|
|
|
paddingTop: 0,
|
|
|
|
|
},background: {
|
|
|
|
|
flexDirection: 'column',
|
|
|
|
|
alignItems: 'center',
|
|
|
|
|
justifyContent: 'center',
|
|
|
|
|
borderRadius: 15,
|
|
|
|
|
backgroundColor: colors.cardBackground,
|
|
|
|
|
padding: "3%",
|
|
|
|
|
marginHorizontal: "3%",
|
|
|
|
|
borderWidth: 1,
|
|
|
|
|
borderColor: colors.blocBorder,
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
pseudoBar: {
|
|
|
|
|
flexDirection: "row",
|
|
|
|
|
alignItems: "center",
|
|
|
|
|
justifyContent: "center",
|
|
|
|
|
width: "100%",
|
|
|
|
|
marginHorizontal: "3%",
|
|
|
|
|
marginBottom: "3%",
|
|
|
|
|
},
|
|
|
|
|
avatar: {
|
|
|
|
|
padding: "5%",
|
|
|
|
|
resizeMode: 'contain',
|
|
|
|
|
borderWidth: 2,
|
|
|
|
|
borderColor: colors.cardElementBorder,
|
|
|
|
|
borderRadius: 45,
|
|
|
|
|
height: "100%",
|
|
|
|
|
flex: 0.04,
|
|
|
|
|
},
|
|
|
|
|
textInput: {
|
|
|
|
|
fontSize: 15,
|
|
|
|
|
color: colors.cardTitle,
|
|
|
|
|
borderRadius: 10,
|
|
|
|
|
borderWidth: 2,
|
|
|
|
|
borderStyle: 'dashed',
|
|
|
|
|
borderColor: colors.cardElementBorder,
|
|
|
|
|
alignItems: 'center',
|
|
|
|
|
textAlign: 'left',
|
|
|
|
|
flex: 0.8,
|
|
|
|
|
marginLeft: "7%",
|
|
|
|
|
padding: "2%",
|
|
|
|
|
},
|
|
|
|
|
modify: {
|
|
|
|
|
height: "100%",
|
|
|
|
|
tintColor: colors.cardElementBorder,
|
|
|
|
|
resizeMode: 'contain',
|
|
|
|
|
flex: 0.1,
|
|
|
|
|
marginLeft: "3%",
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
filterBar: {
|
|
|
|
|
flexDirection: "row",
|
|
|
|
|
width: "85%",
|
|
|
|
|
paddingTop: "3%",
|
|
|
|
|
paddingBottom: "2%",
|
|
|
|
|
alignItems: "flex-end",
|
|
|
|
|
justifyContent: "center",
|
|
|
|
|
},
|
|
|
|
|
filters: {
|
|
|
|
|
fontSize: 20,
|
|
|
|
|
color: colors.cardElementBorder,
|
|
|
|
|
flex: 1,
|
|
|
|
|
},
|
|
|
|
|
nbSelected: {
|
|
|
|
|
fontSize: 11,
|
|
|
|
|
color: colors.cardDetail,
|
|
|
|
|
textAlign: "right",
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|