diff --git a/LeftOvers/components/ListWithoutSelect.tsx b/LeftOvers/components/ListWithoutSelect.tsx index 069534b..1944867 100644 --- a/LeftOvers/components/ListWithoutSelect.tsx +++ b/LeftOvers/components/ListWithoutSelect.tsx @@ -5,18 +5,13 @@ import ColorContext from '../theme/ColorContext'; type ListProps = { title: string - content: {value: string}[] + content: string[] } export default function ListWithoutSelect(props: ListProps) { const [selected, setSelected] = React.useState([]); const { colors } = useContext(ColorContext); - let listContent = [] - - props.content.forEach((val) => { - listContent.push({value: val.value, disabled: true}) - }) const styles = StyleSheet.create({ titleBar: { @@ -86,7 +81,7 @@ export default function ListWithoutSelect(props: ListProps) { return ( setSelected(val)} - data={listContent} + data={props.content} save="value" search={false} arrowicon={} diff --git a/LeftOvers/screens/Profiles.tsx b/LeftOvers/screens/Profiles.tsx index 9cb7e02..0047ae7 100644 --- a/LeftOvers/screens/Profiles.tsx +++ b/LeftOvers/screens/Profiles.tsx @@ -10,6 +10,7 @@ import ColorContext from '../theme/ColorContext'; 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}) { const { colors, toggleColors } = useContext(ColorContext) @@ -22,19 +23,30 @@ export default function Profiles({navigation, props}) { const [profiles, setProfiles] = useState([]); const [selectedProfileIndex, setSelectedProfileIndex] = useState(null); - const raisePopUp = () => { + const raisePopUp = (index) => { + setSelectedProfileIndex(index) setVisible(true) } const erasePopUp = () => { 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) => { try { const updatedProfiles = profiles.filter((profile, i) => i !== index); await AsyncStorage.setItem('profiles', JSON.stringify(updatedProfiles)); + fetchProfiles(); setSelectedProfileIndex(index); - raisePopUp(); // Afficher la boîte de dialogue de confirmation après la suppression + erasePopUp(); } catch (error) { console.error('Erreur lors de la suppression du profil :', error); } @@ -65,11 +77,16 @@ export default function Profiles({navigation, props}) { useEffect(() => { fetchProfiles(); + console.log(profiles) }, []); - + const containerStyle = { + height: "75%", + width: "100%", + }; - const styles = StyleSheet.create({ + + const styles = StyleSheet.create({ container: { height: "100%", width: "100%", @@ -120,11 +137,13 @@ export default function Profiles({navigation, props}) { borderRadius: 15, alignItems: "center", justifyContent: "center", - backgroundColor: "#F2F0E4", + backgroundColor: colors.cardBackground, + borderWidth: 1, + borderColor: colors.blocBorder, }, validationQuestion: { fontSize: 20, - color: '#ACA279', + color: colors.cardElementBorder, alignItems: 'center', justifyContent: 'center', flex: 0.3, @@ -147,7 +166,7 @@ export default function Profiles({navigation, props}) { borderRadius: 20, alignItems: "center", justifyContent: "center", - backgroundColor: "#59BDCD", + backgroundColor: colors.yesButton, }, yesText: { fontSize: 20, @@ -185,56 +204,60 @@ export default function Profiles({navigation, props}) { avatar={profile.avatar} diets={profile.diets} allergies={profile.allergies} - onDeleteProfile={() => handleDeleteProfile(index)} + onDeleteProfile={() => raisePopUp(index)} /> - {index < profiles.length - 1 && } - - )); - - return ( - - - - - - {profileComponents} + + - - - - - + + + {/* - - - Do you really want to delete this profile? - - - - - Yes - - - - - - No - - + /> */} + + + Do you really want to delete this profile? + + handleDeleteProfile(selectedProfileIndex)} style={{flex:0.5}}> + + + Yes + + + + + + No - + - + + + + {index < profiles.length - 1 && } + + )); + + + + return ( + + + + + + {profileComponents} - - + + + ); } \ No newline at end of file