add deleting profils but modal for confirmation dont work

pull/23/head
Rayhân HASSOU 1 year ago committed by Louison PARANT
parent 0bfdb97569
commit ec6420ece1

@ -18,6 +18,7 @@ export default function Profiles({navigation, props}) {
const [visible, setVisible] = useState(false);
const [opacity, setOpacity] = useState(1);
const [profiles, setProfiles] = useState([]);
const [selectedProfileIndex, setSelectedProfileIndex] = useState(null);
const raisePopUp = () => {
setVisible(true)
@ -26,14 +27,20 @@ export default function Profiles({navigation, props}) {
setVisible(false)
}
const handleDeleteProfiles = async () => {
const handleDeleteProfile = async (index) => {
try {
await AsyncStorage.removeItem('profiles');
console.log('Données supprimées avec succès !');
const updatedProfiles = profiles.filter((profile, i) => i !== index);
await AsyncStorage.setItem('profiles', JSON.stringify(updatedProfiles));
setSelectedProfileIndex(index);
raisePopUp(); // Afficher la boîte de dialogue de confirmation après la suppression
} 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 () => {
try {
@ -44,13 +51,17 @@ export default function Profiles({navigation, props}) {
return [];
}
}
const fetchProfiles = async () => {
const existingProfiles = await handleGetProfiles();
setProfiles(existingProfiles);
};
const subscription = EventEmitter.addListener('profileAdded', async () => {
fetchProfiles();
});
useEffect(() => {
const fetchProfiles = async () => {
const existingProfiles = await handleGetProfiles();
setProfiles(existingProfiles);
};
fetchProfiles();
}, []);
@ -190,14 +201,19 @@ export default function Profiles({navigation, props}) {
<View style={styles.modal}>
<View style={styles.viewModal}>
<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 style={styles.decisionBarVertical}>
<Text style={styles.validationQuestion}>Do you really want to delete this profile?</Text>
<View style={styles.decisionBar}>
<Pressable onPress={erasePopUp} style={{flex:0.5}}>
<Pressable onPress={confirmDelete} style={{ flex: 0.5 }}>
<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>
</View>
</Pressable>

Loading…
Cancel
Save