|
|
@ -18,6 +18,7 @@ export default function Profiles({navigation, props}) {
|
|
|
|
const [visible, setVisible] = useState(false);
|
|
|
|
const [visible, setVisible] = useState(false);
|
|
|
|
const [opacity, setOpacity] = useState(1);
|
|
|
|
const [opacity, setOpacity] = useState(1);
|
|
|
|
const [profiles, setProfiles] = useState([]);
|
|
|
|
const [profiles, setProfiles] = useState([]);
|
|
|
|
|
|
|
|
const [selectedProfileIndex, setSelectedProfileIndex] = useState(null);
|
|
|
|
|
|
|
|
|
|
|
|
const raisePopUp = () => {
|
|
|
|
const raisePopUp = () => {
|
|
|
|
setVisible(true)
|
|
|
|
setVisible(true)
|
|
|
@ -26,14 +27,20 @@ export default function Profiles({navigation, props}) {
|
|
|
|
setVisible(false)
|
|
|
|
setVisible(false)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const handleDeleteProfiles = async () => {
|
|
|
|
const handleDeleteProfile = async (index) => {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
await AsyncStorage.removeItem('profiles');
|
|
|
|
const updatedProfiles = profiles.filter((profile, i) => i !== index);
|
|
|
|
console.log('Données supprimées avec succès !');
|
|
|
|
await AsyncStorage.setItem('profiles', JSON.stringify(updatedProfiles));
|
|
|
|
|
|
|
|
setSelectedProfileIndex(index);
|
|
|
|
|
|
|
|
raisePopUp(); // Afficher la boîte de dialogue de confirmation après la suppression
|
|
|
|
} catch (error) {
|
|
|
|
} catch (error) {
|
|
|
|
console.error('Erreur lors de la suppression des données :', error);
|
|
|
|
console.error('Erreur lors de la suppression du profil :', error);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const confirmDelete = () => {
|
|
|
|
|
|
|
|
erasePopUp();
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
const handleGetProfiles = async () => {
|
|
|
|
const handleGetProfiles = async () => {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
@ -44,13 +51,17 @@ export default function Profiles({navigation, props}) {
|
|
|
|
return [];
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const fetchProfiles = async () => {
|
|
|
|
|
|
|
|
const existingProfiles = await handleGetProfiles();
|
|
|
|
|
|
|
|
setProfiles(existingProfiles);
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const subscription = EventEmitter.addListener('profileAdded', async () => {
|
|
|
|
|
|
|
|
fetchProfiles();
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
useEffect(() => {
|
|
|
|
const fetchProfiles = async () => {
|
|
|
|
|
|
|
|
const existingProfiles = await handleGetProfiles();
|
|
|
|
|
|
|
|
setProfiles(existingProfiles);
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fetchProfiles();
|
|
|
|
fetchProfiles();
|
|
|
|
}, []);
|
|
|
|
}, []);
|
|
|
|
|
|
|
|
|
|
|
@ -190,14 +201,19 @@ export default function Profiles({navigation, props}) {
|
|
|
|
<View style={styles.modal}>
|
|
|
|
<View style={styles.modal}>
|
|
|
|
<View style={styles.viewModal}>
|
|
|
|
<View style={styles.viewModal}>
|
|
|
|
<View style={styles.profileValidation}>
|
|
|
|
<View style={styles.profileValidation}>
|
|
|
|
{/* <ProfileDelete name="Johnny Silverhand" avatar="plus_small.png" diets={dieJohnny} allergies={allJohnny}></ProfileDelete> */}
|
|
|
|
<ProfileDelete
|
|
|
|
|
|
|
|
name={profiles[selectedProfileIndex].name}
|
|
|
|
|
|
|
|
avatar={profiles[selectedProfileIndex].avatar}
|
|
|
|
|
|
|
|
diets={profiles[selectedProfileIndex].diets}
|
|
|
|
|
|
|
|
allergies={profiles[selectedProfileIndex].allergies}
|
|
|
|
|
|
|
|
/>
|
|
|
|
</View>
|
|
|
|
</View>
|
|
|
|
<View style={styles.decisionBarVertical}>
|
|
|
|
<View style={styles.decisionBarVertical}>
|
|
|
|
<Text style={styles.validationQuestion}>Do you really want to delete this profile?</Text>
|
|
|
|
<Text style={styles.validationQuestion}>Do you really want to delete this profile?</Text>
|
|
|
|
<View style={styles.decisionBar}>
|
|
|
|
<View style={styles.decisionBar}>
|
|
|
|
<Pressable onPress={erasePopUp} style={{flex:0.5}}>
|
|
|
|
<Pressable onPress={confirmDelete} style={{ flex: 0.5 }}>
|
|
|
|
<View style={styles.yesButton}>
|
|
|
|
<View style={styles.yesButton}>
|
|
|
|
<Image source={require("../assets/images/validate.png")} style={{tintColor: "#2DE04A", height: "100%", flex: 0.2, margin: "5%", resizeMode: "contain"}}/>
|
|
|
|
<Image source={require("../assets/images/validate.png")} style={{ tintColor: "#2DE04A", height: "100%", flex: 0.2, margin: "5%", resizeMode: "contain" }} />
|
|
|
|
<Text style={styles.yesText}>Yes</Text>
|
|
|
|
<Text style={styles.yesText}>Yes</Text>
|
|
|
|
</View>
|
|
|
|
</View>
|
|
|
|
</Pressable>
|
|
|
|
</Pressable>
|
|
|
|