From e43e04d4f8ab00df60fbf4573bf6f3065e2d02d4 Mon Sep 17 00:00:00 2001 From: Rayhan Hassou Date: Thu, 30 Nov 2023 13:24:34 +0100 Subject: [PATCH] add some changes --- LeftOvers/screens/IngredientSelection.tsx | 8 +- LeftOvers/screens/Profiles.tsx | 138 +++++++++++----------- 2 files changed, 73 insertions(+), 73 deletions(-) diff --git a/LeftOvers/screens/IngredientSelection.tsx b/LeftOvers/screens/IngredientSelection.tsx index 9bfe6ca..0691f8d 100644 --- a/LeftOvers/screens/IngredientSelection.tsx +++ b/LeftOvers/screens/IngredientSelection.tsx @@ -3,8 +3,6 @@ import { View, StyleSheet, Text, Image, Pressable, ActivityIndicator, FlatList, import { SafeAreaProvider } from 'react-native-safe-area-context'; import { Searchbar } from 'react-native-paper'; import FoodElementText from '../components/FoodElementText'; -import CustomButton from '../components/CustomButton'; - import plus from '../assets/images/plus.png'; import moins from '../assets/images/minus.png'; import Ingredient from '../Models/Ingredient'; @@ -28,7 +26,6 @@ export default function IngredientSelection(props) { try { setIsLoading(true); if (query === '') { - // Si le query (prompt) est vide, charger tous les ingrédients loadIngredients(); } else { const filtered = await ingredientService.getfilteredIngredient(query); @@ -41,7 +38,6 @@ export default function IngredientSelection(props) { } }; - // Appelée à chaque changement de la recherche const handleSearch = (query) => { setSearchQuery(query); filterIngredients(query); @@ -179,7 +175,7 @@ const loadIngredients = async () => { Available - + ( @@ -192,7 +188,7 @@ const loadIngredients = async () => { - + diff --git a/LeftOvers/screens/Profiles.tsx b/LeftOvers/screens/Profiles.tsx index 4123c9a..b6f906f 100644 --- a/LeftOvers/screens/Profiles.tsx +++ b/LeftOvers/screens/Profiles.tsx @@ -1,7 +1,5 @@ -import React, { useContext, useState } from 'react'; -import { StyleSheet, View, Pressable, Text, Image, ScrollView, useWindowDimensions } from 'react-native'; - -import {Modal, Portal, PaperProvider} from 'react-native-paper'; +import React, { useContext, useEffect, useState } from 'react'; +import { StyleSheet, View, Modal, Pressable, Text, Image, ScrollView, useWindowDimensions } from 'react-native'; import { LinearGradient } from 'expo-linear-gradient'; import { SafeAreaProvider } from 'react-native-safe-area-context'; @@ -9,18 +7,18 @@ import { SafeAreaProvider } from 'react-native-safe-area-context'; import ProfileDetails from '../components/ProfileDetails'; import ProfileDelete from '../components/ProfileDelete'; import ColorContext from '../theme/ColorContext'; +import AsyncStorage from '@react-native-async-storage/async-storage'; export default function Profiles({navigation, props}) { - const { colors } = useContext(ColorContext) - - const allJohnny = [{value: "Coconut"}, {value: "Skimmed Milk"}, {value: "Nuts"}] - const dieJohnny = [{value: "Gluten free"}, {value: "Porkless"}, {value: "Pescatarian"}] + const { colors, toggleColors } = useContext(ColorContext) - const allJackie = [{value: "Tomato"}, {value: "Relic"}] - const dieJackie = [{value: "Porkless"}, {value: "Vegetarian"}] + const all = [] + const die = [{value: "Dairy free"}, {value: "Gluten free"}, {value: "Porkless"}, {value: "Vegan"}, {value: "Vegetarian"}, {value: "Pescatarian"}] const [visible, setVisible] = useState(false); const [opacity, setOpacity] = useState(1); + const [profiles, setProfiles] = useState([]); + const raisePopUp = () => { setVisible(true) setOpacity(0.3) @@ -30,28 +28,35 @@ export default function Profiles({navigation, props}) { setOpacity(1) } - const profiles = [ - { - name: "Johnny Silverhand", - avatar: "plus_small.png", - diets: dieJohnny, - allergies: allJohnny, - }, - { - name: "Jackie Welles", - avatar: "plus_small.png", - diets: dieJackie, - allergies: allJackie, - }, - // ... Ajoutez d'autres profils ici de la même manière - ]; + 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 handleGetProfiles = async () => { + try { + const existingProfiles = await AsyncStorage.getItem('profiles'); + return JSON.parse(existingProfiles) || []; + } catch (error) { + console.log("ça maaaaaaaaarche poaaaaaaaaaaaas"); + return []; + } + } + + useEffect(() => { + const fetchProfiles = async () => { + const existingProfiles = await handleGetProfiles(); + setProfiles(existingProfiles); + }; + + fetchProfiles(); + }, []); - const containerStyle = { - //minHeight: useWindowDimensions().height/2, - //width: useWindowDimensions().width, - height: "75%", - width: "100%", - }; + const styles = StyleSheet.create({ container: { @@ -104,13 +109,11 @@ export default function Profiles({navigation, props}) { borderRadius: 15, alignItems: "center", justifyContent: "center", - backgroundColor: colors.cardBackground, - borderWidth: 1, - borderColor: colors.blocBorder, + backgroundColor: "#F2F0E4", }, validationQuestion: { fontSize: 20, - color: colors.cardElementBorder, + color: '#ACA279', alignItems: 'center', justifyContent: 'center', flex: 0.3, @@ -133,7 +136,7 @@ export default function Profiles({navigation, props}) { borderRadius: 20, alignItems: "center", justifyContent: "center", - backgroundColor: colors.yesButton, + backgroundColor: "#59BDCD", }, yesText: { fontSize: 20, @@ -171,50 +174,51 @@ export default function Profiles({navigation, props}) { avatar={profile.avatar} diets={profile.diets} allergies={profile.allergies} - onDeleteProfile={raisePopUp}/> + onDeleteProfile={raisePopUp} + /> {index < profiles.length - 1 && } )); return ( - - + + {profileComponents} - - - - - - - - - - - Do you really want to delete this profile? - - - - - Yes + + + + + {/* */} + + + Do you really want to delete this profile? + + + + + Yes + + + + + + No + + - - - - - No - - + - + - - - + + + + ); - } + } \ No newline at end of file