deleting profil works

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

@ -5,18 +5,13 @@ import ColorContext from '../theme/ColorContext';
type ListProps = { type ListProps = {
title: string title: string
content: {value: string}[] content: string[]
} }
export default function ListWithoutSelect(props: ListProps) { export default function ListWithoutSelect(props: ListProps) {
const [selected, setSelected] = React.useState([]); const [selected, setSelected] = React.useState([]);
const { colors } = useContext(ColorContext); const { colors } = useContext(ColorContext);
let listContent = []
props.content.forEach((val) => {
listContent.push({value: val.value, disabled: true})
})
const styles = StyleSheet.create({ const styles = StyleSheet.create({
titleBar: { titleBar: {
@ -86,7 +81,7 @@ export default function ListWithoutSelect(props: ListProps) {
return ( return (
<MultipleSelectList <MultipleSelectList
setSelected={(val) => setSelected(val)} setSelected={(val) => setSelected(val)}
data={listContent} data={props.content}
save="value" save="value"
search={false} search={false}
arrowicon={<Image source={require("../assets/images/arrow.png")} style={styles.arrow}></Image>} arrowicon={<Image source={require("../assets/images/arrow.png")} style={styles.arrow}></Image>}

@ -8,6 +8,9 @@ import ProfileDetails from '../components/ProfileDetails';
import ProfileDelete from '../components/ProfileDelete'; import ProfileDelete from '../components/ProfileDelete';
import ColorContext from '../theme/ColorContext'; import ColorContext from '../theme/ColorContext';
import AsyncStorage from '@react-native-async-storage/async-storage'; import AsyncStorage from '@react-native-async-storage/async-storage';
import EventEmitter from './EventEmitter';
import Profil from '../Models/Profil';
import { PaperProvider, Portal } from 'react-native-paper';
export default function Profiles({navigation, props}) { export default function Profiles({navigation, props}) {
const { colors, toggleColors } = useContext(ColorContext) const { colors, toggleColors } = useContext(ColorContext)
@ -20,19 +23,30 @@ 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 raisePopUp = () => { const raisePopUp = (index) => {
setSelectedProfileIndex(index)
setVisible(true) setVisible(true)
} }
const erasePopUp = () => { const erasePopUp = () => {
setVisible(false) setVisible(false)
} }
const handleDeleteProfiles = async () => {
try {
await AsyncStorage.removeItem('profiles');
console.log('Données supprimées avec succès !');
} catch (error) {
console.error('Erreur lors de la suppression des données :', error);
}
};
const handleDeleteProfile = async (index) => { const handleDeleteProfile = async (index) => {
try { try {
const updatedProfiles = profiles.filter((profile, i) => i !== index); const updatedProfiles = profiles.filter((profile, i) => i !== index);
await AsyncStorage.setItem('profiles', JSON.stringify(updatedProfiles)); await AsyncStorage.setItem('profiles', JSON.stringify(updatedProfiles));
fetchProfiles();
setSelectedProfileIndex(index); setSelectedProfileIndex(index);
raisePopUp(); // Afficher la boîte de dialogue de confirmation après la suppression erasePopUp();
} catch (error) { } catch (error) {
console.error('Erreur lors de la suppression du profil :', error); console.error('Erreur lors de la suppression du profil :', error);
} }
@ -63,11 +77,16 @@ export default function Profiles({navigation, props}) {
useEffect(() => { useEffect(() => {
fetchProfiles(); fetchProfiles();
console.log(profiles)
}, []); }, []);
const containerStyle = {
height: "75%",
width: "100%",
};
const styles = StyleSheet.create({
const styles = StyleSheet.create({
container: { container: {
height: "100%", height: "100%",
width: "100%", width: "100%",
@ -118,11 +137,13 @@ export default function Profiles({navigation, props}) {
borderRadius: 15, borderRadius: 15,
alignItems: "center", alignItems: "center",
justifyContent: "center", justifyContent: "center",
backgroundColor: "#F2F0E4", backgroundColor: colors.cardBackground,
borderWidth: 1,
borderColor: colors.blocBorder,
}, },
validationQuestion: { validationQuestion: {
fontSize: 20, fontSize: 20,
color: '#ACA279', color: colors.cardElementBorder,
alignItems: 'center', alignItems: 'center',
justifyContent: 'center', justifyContent: 'center',
flex: 0.3, flex: 0.3,
@ -145,7 +166,7 @@ export default function Profiles({navigation, props}) {
borderRadius: 20, borderRadius: 20,
alignItems: "center", alignItems: "center",
justifyContent: "center", justifyContent: "center",
backgroundColor: "#59BDCD", backgroundColor: colors.yesButton,
}, },
yesText: { yesText: {
fontSize: 20, fontSize: 20,
@ -206,33 +227,47 @@ export default function Profiles({navigation, props}) {
avatar={profiles[selectedProfileIndex].avatar} avatar={profiles[selectedProfileIndex].avatar}
diets={profiles[selectedProfileIndex].diets} diets={profiles[selectedProfileIndex].diets}
allergies={profiles[selectedProfileIndex].allergies} 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={confirmDelete} style={{ flex: 0.5 }}> <Pressable onPress={() => handleDeleteProfile(selectedProfileIndex)} 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>
</Pressable>
<Pressable onPress={erasePopUp} style={{flex:0.5}}>
<View style={styles.noButton}>
<Image source={require("../assets/images/cross.png")} style={{tintColor: "#E02D2D", height: "100%", flex: 0.2, margin: "5%", resizeMode: "contain"}}/>
<Text style={styles.noText}>No</Text>
</View>
</Pressable>
</View> </View>
</View> </Pressable>
<Pressable onPress={erasePopUp} style={{flex:0.5}}>
<View style={styles.noButton}>
<Image source={require("../assets/images/cross.png")} style={{tintColor: "#E02D2D", height: "100%", flex: 0.2, margin: "5%", resizeMode: "contain"}}/>
<Text style={styles.noText}>No</Text>
</View>
</Pressable>
</View> </View>
</View> </View>
</Modal> </View>
</View> </View>
</Modal>
</Portal>
{index < profiles.length - 1 && <View style={styles.separator} />}
</View>
));
return (
<SafeAreaProvider style={{flex: 1}}>
<PaperProvider>
<ScrollView>
<LinearGradient colors={[colors.primary, colors.primaryComplement]} style={[styles.linearGradient, {minHeight: useWindowDimensions().height}]}>
<View style={styles.separator}/>
{profileComponents}
<View style={{marginBottom: "20%"}}/> <View style={{marginBottom: "20%"}}/>
</LinearGradient> </LinearGradient>
</View> </ScrollView>
</ScrollView>
</PaperProvider>
</SafeAreaProvider> </SafeAreaProvider>
); );
} }
Loading…
Cancel
Save