From 8fdddda189095a45685ffee3f529ea151757b9df Mon Sep 17 00:00:00 2001 From: Louison PARANT Date: Tue, 5 Dec 2023 08:57:29 +0100 Subject: [PATCH] MaJ Profiles Home Page after Delete --- LeftOvers/Models/Profile.tsx | 30 ++++++ .../Services/Recipes/RecipesServices.tsx | 1 - LeftOvers/components/ProfileElement.tsx | 3 +- LeftOvers/components/RecipeElementReduce.tsx | 99 ++++++++++--------- LeftOvers/screens/CreateProfile.tsx | 8 +- LeftOvers/screens/HomePage.tsx | 4 + LeftOvers/screens/Profiles.tsx | 17 ++-- 7 files changed, 97 insertions(+), 65 deletions(-) create mode 100644 LeftOvers/Models/Profile.tsx diff --git a/LeftOvers/Models/Profile.tsx b/LeftOvers/Models/Profile.tsx new file mode 100644 index 0000000..1dc1775 --- /dev/null +++ b/LeftOvers/Models/Profile.tsx @@ -0,0 +1,30 @@ +export default class Profile { + private _name: string; + private _avatar: string; + private _allergy: string[]; + private _diets: string[]; + + constructor( name: string, avatar: string, allergy: string[], diets: string[]) { + this._name = name; + this._avatar = avatar; + this._allergy = allergy; + this._diets = diets; + } + + get name(): string { + return this._name; + } + + + get avatar(): string{ + return this._avatar; + } + + get allergy(): string[]{ + return this._allergy; + } + + get diets(): string[]{ + return this._diets; + } + } \ No newline at end of file diff --git a/LeftOvers/Services/Recipes/RecipesServices.tsx b/LeftOvers/Services/Recipes/RecipesServices.tsx index e5100ba..fbb3583 100644 --- a/LeftOvers/Services/Recipes/RecipesServices.tsx +++ b/LeftOvers/Services/Recipes/RecipesServices.tsx @@ -18,7 +18,6 @@ export default class RecipesService implements IRecipesService { async getRecipeById(id: number): Promise{ try { const response = await axios.get(`${this.API_URL}/${id}`); - //console.log(response.name); return response.data as Recipes; } catch (error) { throw new Error('Erreur lors de la récupération des ingrédients : ' + error.message); diff --git a/LeftOvers/components/ProfileElement.tsx b/LeftOvers/components/ProfileElement.tsx index e78d8e0..28fb4fe 100644 --- a/LeftOvers/components/ProfileElement.tsx +++ b/LeftOvers/components/ProfileElement.tsx @@ -37,11 +37,10 @@ export default function ProfileElement(props : Profile) { let imageSource if(props.avatar == null){ - console.log("NUUUULLLLLE" + props.avatar) + imageSource=require("../assets/images/logo.png") } else{ imageSource = { uri: props.avatar }; - console.log("MAAARCHHEEE" + props.avatar) } const styles = StyleSheet.create({ diff --git a/LeftOvers/components/RecipeElementReduce.tsx b/LeftOvers/components/RecipeElementReduce.tsx index 7ee1da4..bea510c 100644 --- a/LeftOvers/components/RecipeElementReduce.tsx +++ b/LeftOvers/components/RecipeElementReduce.tsx @@ -1,7 +1,8 @@ -import React from 'react'; +import React, {useContext} from 'react'; import {StyleSheet, Text, View, Image} from 'react-native'; import brochette from '../assets/images/brochette.png'; -import background from '../assets/images/Background.png'; +import background from '../assets/images/Background.png'; +import ColorContext from '../theme/ColorContext'; interface RecipeElementReduceProps { @@ -12,6 +13,53 @@ interface RecipeElementReduceProps { } export default function RecipeElementReduce(props: RecipeElementReduceProps) { + const {colors} = useContext(ColorContext) + + const styles = StyleSheet.create({ + button: { + alignItems: 'center', + justifyContent: 'center', + width : 250, + height: 250, + borderRadius: 40, + backgroundColor: colors.recipeElementBackground, + }, + text: { + fontSize: 15, + fontWeight: 'bold', + color: '#6F6532', + marginTop: "4%", + zIndex: 2 + }, + smallText: { + position: "absolute", + fontSize: 12, + color: '#F2F0E4', + textAlign: "center", + margin : "2%", + zIndex: 2, + fontWeight: "bold", + top: "89.25%" + }, + title:{ + fontSize: 18, + fontWeight: 'bold', + color: '#524B1A', + zIndex: 2 + }, + view: { + width : "95%", + height: "95%", + borderRadius: 40, + borderWidth: 2, + padding: "5%", + borderColor: '#73692A', + alignItems: 'center', + justifyContent: "center", + }, + }); + + return ( @@ -24,49 +72,4 @@ export default function RecipeElementReduce(props: RecipeElementReduceProps) { ); -} - - -const styles = StyleSheet.create({ - button: { - alignItems: 'center', - justifyContent: 'center', - width : 250, - height: 250, - borderRadius: 40, - backgroundColor: '#E3DEC9', - }, - text: { - fontSize: 15, - fontWeight: 'bold', - color: '#756C28', - marginTop: "4%", - zIndex: 2 - }, - smallText: { - position: "absolute", - fontSize: 12, - color: '#F2F0E4', - textAlign: "center", - margin : "2%", - zIndex: 2, - fontWeight: "bold", - top: "89.25%" - }, - title:{ - fontSize: 18, - fontWeight: 'bold', - color: '#524B1A', - zIndex: 2 - }, - view: { - width : "95%", - height: "95%", - borderRadius: 40, - borderWidth: 2, - padding: "5%", - borderColor: '#73692A', - alignItems: 'center', - justifyContent: "center", - }, -}); \ No newline at end of file +} \ No newline at end of file diff --git a/LeftOvers/screens/CreateProfile.tsx b/LeftOvers/screens/CreateProfile.tsx index 8e6a161..32bdf4f 100644 --- a/LeftOvers/screens/CreateProfile.tsx +++ b/LeftOvers/screens/CreateProfile.tsx @@ -47,6 +47,9 @@ export default function CreateProfile(props) { else if (props.avatar == "plus_small.png"){ imageSource = {uri: avatar} } + else if (props.avatar == ""){ + imageSource = require("../assets/images/logo.png") + } else{ imageSource = {uri: avatar} } @@ -67,11 +70,8 @@ export default function CreateProfile(props) { const updatedProfiles = [...existingProfiles, newProfile]; await AsyncStorage.setItem('profiles', JSON.stringify(updatedProfiles)); EventEmitter.emit('profileAdded'); - console.log('Profil créé :', newProfile); - props.navigation.goBack(); - alert('Profil créé !'); } catch (error) { console.error('Erreur lors de la création du profil :', error); @@ -169,7 +169,7 @@ export default function CreateProfile(props) { Filters - "0 diets selected + 0 diets selected diff --git a/LeftOvers/screens/HomePage.tsx b/LeftOvers/screens/HomePage.tsx index 73f4e2e..b8897b7 100644 --- a/LeftOvers/screens/HomePage.tsx +++ b/LeftOvers/screens/HomePage.tsx @@ -46,6 +46,10 @@ export default function HomePage({ navigation, props }) { fetchProfiles(); }); + const subscriptionDeleteProfile = EventEmitter.addListener('profileDeleted', async () => { + fetchProfiles(); + }); + useEffect(() => { fetchProfiles(); console.log(profiles.length) diff --git a/LeftOvers/screens/Profiles.tsx b/LeftOvers/screens/Profiles.tsx index 16408ac..4a54ca6 100644 --- a/LeftOvers/screens/Profiles.tsx +++ b/LeftOvers/screens/Profiles.tsx @@ -44,24 +44,22 @@ export default function Profiles({navigation, props}) { try { const updatedProfiles = profiles.filter((profile, i) => i !== index); await AsyncStorage.setItem('profiles', JSON.stringify(updatedProfiles)); + EventEmitter.emit('profileDeleted'); fetchProfiles(); setSelectedProfileIndex(index); erasePopUp(); + alert('Profile Deleted!'); } catch (error) { console.error('Erreur lors de la suppression du profil :', error); } }; - const confirmDelete = () => { - erasePopUp(); - }; - const handleGetProfiles = async () => { try { const existingProfiles = await AsyncStorage.getItem('profiles'); return JSON.parse(existingProfiles) || []; } catch (error) { - console.log("ça maaaaaaaaarche poaaaaaaaaaaaas"); + console.log(error); return []; } } @@ -199,13 +197,13 @@ export default function Profiles({navigation, props}) { const profileComponents = profiles.map((profile, index) => ( - raisePopUp(index)} - /> + onModification={() => navigation.navigate("ProfileModification")} + onDeleteProfile={() => raisePopUp(index)}/> @@ -239,7 +237,7 @@ export default function Profiles({navigation, props}) { - {index < profiles.length - 1 && } + {index < profiles.length - 1 && } )); @@ -255,7 +253,6 @@ export default function Profiles({navigation, props}) { - );