add some changes

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

@ -3,7 +3,6 @@ import { View, StyleSheet, Text, Image, Pressable, ActivityIndicator, FlatList,
import { SafeAreaProvider } from 'react-native-safe-area-context'; import { SafeAreaProvider } from 'react-native-safe-area-context';
import { Searchbar } from 'react-native-paper'; import { Searchbar } from 'react-native-paper';
import FoodElementText from '../components/FoodElementText'; import FoodElementText from '../components/FoodElementText';
import plus from '../assets/images/plus.png'; import plus from '../assets/images/plus.png';
import moins from '../assets/images/minus.png'; import moins from '../assets/images/minus.png';
import Ingredient from '../Models/Ingredient'; import Ingredient from '../Models/Ingredient';
@ -20,7 +19,7 @@ export default function IngredientSelection(props) {
const ingredientService = new IngredientService(); const ingredientService = new IngredientService();
const {colors} = useContext(ColorContext); const {colors} = useContext(ColorContext);
const [availableSize, setAvailableSize] = useState(0); const [availableSize, setAvailableSize] = useState(0);
const [listVisibility, setListVisibility] = useState("none"); const [listVisibility, setListVisibility] = useState("flex");
const [availableVisibility, setAvailableVisibility] = useState("none"); const [availableVisibility, setAvailableVisibility] = useState("none");
const [searchQuery, setSearchQuery] = useState(''); const [searchQuery, setSearchQuery] = useState('');
@ -28,7 +27,6 @@ export default function IngredientSelection(props) {
try { try {
setIsLoading(true); setIsLoading(true);
if (query === '') { if (query === '') {
// Si le query (prompt) est vide, charger tous les ingrédients
loadIngredients(); loadIngredients();
} else { } else {
const filtered = await ingredientService.getfilteredIngredient(query); const filtered = await ingredientService.getfilteredIngredient(query);
@ -41,7 +39,6 @@ export default function IngredientSelection(props) {
} }
}; };
// Appelée à chaque changement de la recherche
const handleSearch = (query) => { const handleSearch = (query) => {
setSearchQuery(query); setSearchQuery(query);
filterIngredients(query); filterIngredients(query);

@ -1,7 +1,5 @@
import React, { useContext, useState } from 'react'; import React, { useContext, useEffect, useState } from 'react';
import { StyleSheet, View, Pressable, Text, Image, ScrollView, useWindowDimensions } from 'react-native'; import { StyleSheet, View, Modal, Pressable, Text, Image, ScrollView, useWindowDimensions } from 'react-native';
import {Modal, Portal, PaperProvider} from 'react-native-paper';
import { LinearGradient } from 'expo-linear-gradient'; import { LinearGradient } from 'expo-linear-gradient';
import { SafeAreaProvider } from 'react-native-safe-area-context'; import { SafeAreaProvider } from 'react-native-safe-area-context';
@ -9,17 +7,18 @@ import { SafeAreaProvider } from 'react-native-safe-area-context';
import ProfileDetails from '../components/ProfileDetails'; 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';
export default function Profiles({navigation, props}) { export default function Profiles({navigation, props}) {
const { colors } = useContext(ColorContext) const { colors, toggleColors } = useContext(ColorContext)
const allJohnny = [{value: "Coconut"}, {value: "Skimmed Milk"}, {value: "Nuts"}]
const dieJohnny = [{value: "Gluten free"}, {value: "Porkless"}, {value: "Pescatarian"}]
const allJackie = [{value: "Tomato"}, {value: "Relic"}] const all = []
const dieJackie = [{value: "Porkless"}, {value: "Vegetarian"}] const die = [{value: "Dairy free"}, {value: "Gluten free"}, {value: "Porkless"}, {value: "Vegan"}, {value: "Vegetarian"}, {value: "Pescatarian"}]
const [visible, setVisible] = useState(false); const [visible, setVisible] = useState(false);
const [opacity, setOpacity] = useState(1);
const [profiles, setProfiles] = useState([]);
const raisePopUp = () => { const raisePopUp = () => {
setVisible(true) setVisible(true)
} }
@ -27,28 +26,35 @@ export default function Profiles({navigation, props}) {
setVisible(false) setVisible(false)
} }
const profiles = [ const handleDeleteProfiles = async () => {
{ try {
name: "Johnny Silverhand", await AsyncStorage.removeItem('profiles');
avatar: "plus_small.png", console.log('Données supprimées avec succès !');
diets: dieJohnny, } catch (error) {
allergies: allJohnny, console.error('Erreur lors de la suppression des données :', error);
}, }
{ };
name: "Jackie Welles",
avatar: "plus_small.png", const handleGetProfiles = async () => {
diets: dieJackie, try {
allergies: allJackie, const existingProfiles = await AsyncStorage.getItem('profiles');
}, return JSON.parse(existingProfiles) || [];
// ... Ajoutez d'autres profils ici de la même manière } 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({ const styles = StyleSheet.create({
container: { container: {
@ -101,13 +107,11 @@ export default function Profiles({navigation, props}) {
borderRadius: 15, borderRadius: 15,
alignItems: "center", alignItems: "center",
justifyContent: "center", justifyContent: "center",
backgroundColor: colors.cardBackground, backgroundColor: "#F2F0E4",
borderWidth: 1,
borderColor: colors.blocBorder,
}, },
validationQuestion: { validationQuestion: {
fontSize: 20, fontSize: 20,
color: colors.cardElementBorder, color: '#ACA279',
alignItems: 'center', alignItems: 'center',
justifyContent: 'center', justifyContent: 'center',
flex: 0.3, flex: 0.3,
@ -130,7 +134,7 @@ export default function Profiles({navigation, props}) {
borderRadius: 20, borderRadius: 20,
alignItems: "center", alignItems: "center",
justifyContent: "center", justifyContent: "center",
backgroundColor: colors.yesButton, backgroundColor: "#59BDCD",
}, },
yesText: { yesText: {
fontSize: 20, fontSize: 20,
@ -176,43 +180,43 @@ export default function Profiles({navigation, props}) {
return ( return (
<SafeAreaProvider style={{flex: 1}}> <SafeAreaProvider style={{flex: 1}}>
<PaperProvider> <ScrollView>
<ScrollView> <View style={{opacity: opacity, height: "100%", width: "100%", flex: 1}}>
<LinearGradient colors={[colors.primary, colors.primaryComplement]} style={[styles.linearGradient, {minHeight: useWindowDimensions().height}]}> <LinearGradient colors={[colors.primary, colors.primaryComplement]} style={[styles.linearGradient, {minHeight: useWindowDimensions().height}]}>
<View style={styles.separator}/> <View style={styles.separator}/>
{profileComponents} {profileComponents}
<View style={{marginBottom: "20%"}}/>
</LinearGradient>
</ScrollView>
<Portal>
<Modal visible={visible} onDismiss={erasePopUp} contentContainerStyle={containerStyle} style={{marginTop: 0, justifyContent: "flex-start"}}>
<View style={styles.modal}> <View style={styles.modal}>
<View style={styles.viewModal}> <Modal visible={visible} onRequestClose={erasePopUp} animationType="fade" transparent={true}>
<View style={styles.profileValidation}> <View style={styles.modal}>
<ProfileDelete name="Johnny Silverhand" avatar="plus_small.png" diets={dieJohnny} allergies={allJohnny}></ProfileDelete> <View style={styles.viewModal}>
</View> <View style={styles.profileValidation}>
<View style={styles.decisionBarVertical}> {/* <ProfileDelete name="Johnny Silverhand" avatar="plus_small.png" diets={dieJohnny} allergies={allJohnny}></ProfileDelete> */}
<Text style={styles.validationQuestion}>Do you really want to delete this profile?</Text> </View>
<View style={styles.decisionBar}> <View style={styles.decisionBarVertical}>
<Pressable onPress={erasePopUp} style={{flex:0.5}}> <Text style={styles.validationQuestion}>Do you really want to delete this profile?</Text>
<View style={styles.yesButton}> <View style={styles.decisionBar}>
<Image source={require("../assets/images/validate.png")} style={{tintColor: "#2DE04A", height: "100%", flex: 0.2, margin: "5%", resizeMode: "contain"}}/> <Pressable onPress={erasePopUp} style={{flex:0.5}}>
<Text style={styles.yesText}>Yes</Text> <View style={styles.yesButton}>
<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>
<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>
</Pressable> </View>
<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>
</View> </Modal>
</View> </View>
</Modal> <View style={{marginBottom: "20%"}}/>
</Portal> </LinearGradient>
</PaperProvider> </View>
</ScrollView>
</SafeAreaProvider> </SafeAreaProvider>
); );
} }
Loading…
Cancel
Save