From 989f2c2813c54795f435c5f22fe224a7cc16b130 Mon Sep 17 00:00:00 2001 From: Remi REGNAULT Date: Tue, 28 Nov 2023 15:33:35 +0100 Subject: [PATCH 01/27] refactor: Ingredients selection page --- LeftOvers/screens/IngredientSelection.tsx | 199 +++++++++++----------- 1 file changed, 101 insertions(+), 98 deletions(-) diff --git a/LeftOvers/screens/IngredientSelection.tsx b/LeftOvers/screens/IngredientSelection.tsx index 3b90812..9933677 100644 --- a/LeftOvers/screens/IngredientSelection.tsx +++ b/LeftOvers/screens/IngredientSelection.tsx @@ -14,114 +14,117 @@ import fruit from '../assets/images/fruit_icon.png'; export default function IngredientSelection(props) { + const [searchQuery, setSearchQuery] = React.useState(''); - const [searchQuery, setSearchQuery] = React.useState(''); + const onChangeSearch = query => setSearchQuery(query); - const onChangeSearch = query => setSearchQuery(query); + type ItemProps = {value: string} - type ItemProps = {value: string} - - const AvailaibleItem = ({value}: ItemProps) => ( - <> - - - - - -) - -const ChooseItem = ({value}: ItemProps) => ( - <> - - - - - -) - - return ( - - - - - + const AvailaibleItem = ({value}: ItemProps) => ( + <> + + - - - - + + + + ) + + const ChooseItem = ({value}: ItemProps) => ( + <> + + - + - - - - - - - {props.listIngredient.map((source, index) => ( - - ))} - - - - + + + ) + + + const styles = StyleSheet.create({ + page: { + flex: 1, + backgroundColor: '#59BDCD', + alignItems: 'center', + display: 'flex', + flexWrap: 'wrap', + padding: 20, + }, + element: { + backgroundColor:'#F2F0E4', + borderRadius: 30, + }, + horizontalAlignement: { + display: 'flex', + height: 30, + width: 350, + flexDirection: 'row', + justifyContent: 'space-around', + alignItems: 'center', + marginTop: 15, + } + }); - - - Available + return ( + + + + + + + + + + + + + + + + + + + + {props.listIngredient.map((source, index) => ( + + ))} + + + - - - - - {props.listIngredient.map((source, index) => ( - - ))} - - - - + + + Available + + + - - - + + + {props.listIngredient.map((source, index) => ( + + ))} + + + + + + + + - ); + ); } - -const styles = StyleSheet.create({ - page: { - flex: 1, - backgroundColor: '#59BDCD', - alignItems: 'center', - display: 'flex', - flexWrap: 'wrap', - padding: 20, - }, - element: { - backgroundColor:'#F2F0E4', - borderRadius: 30, - }, - horizontalAlignement: { - display: 'flex', - height: 30, - width: 350, - flexDirection: 'row', - justifyContent: 'space-around', - alignItems: 'center', - marginTop: 15, - } -}); From 92dbfb6387c070d63cdfef86dee7d095979aa355 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20REGNAULT?= Date: Tue, 28 Nov 2023 15:39:16 +0100 Subject: [PATCH 02/27] =?UTF-8?q?Mise=20=C3=A0=20jour=20de=20'.drone.yml'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .drone.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.drone.yml b/.drone.yml index 7f1dcbe..a966f62 100644 --- a/.drone.yml +++ b/.drone.yml @@ -12,7 +12,7 @@ steps: commands: - cd ./LeftOvers/ - npm install - - npm run + - npx react-native bundle --platform android --dev false --entry-file index.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/src/main/res/ - name: code-analysis image: node:latest From a999899e2ffea47e8c50764c60b0f04bd3a843aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20REGNAULT?= Date: Tue, 28 Nov 2023 15:43:54 +0100 Subject: [PATCH 03/27] =?UTF-8?q?Mise=20=C3=A0=20jour=20de=20'.drone.yml'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .drone.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.drone.yml b/.drone.yml index a966f62..29b8fb3 100644 --- a/.drone.yml +++ b/.drone.yml @@ -12,7 +12,8 @@ steps: commands: - cd ./LeftOvers/ - npm install - - npx react-native bundle --platform android --dev false --entry-file index.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/src/main/res/ + - npx react-native bundle --platform android --dev false --entry-file index.js --bundle-output android/app/src/main/res/raw/index.android.bundle --assets-dest android/app/src/main/res/ + - name: code-analysis image: node:latest From bc0c5a424e0b9f11b9574ec2c29e735e4859da05 Mon Sep 17 00:00:00 2001 From: Remi REGNAULT Date: Tue, 28 Nov 2023 16:20:11 +0100 Subject: [PATCH 04/27] add repertory android/app/src/main/res/raw --- LeftOvers/android/app/src/main/res/raw/placeholder.txt | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 LeftOvers/android/app/src/main/res/raw/placeholder.txt diff --git a/LeftOvers/android/app/src/main/res/raw/placeholder.txt b/LeftOvers/android/app/src/main/res/raw/placeholder.txt new file mode 100644 index 0000000..e69de29 From b0a5f2141f57b903472338164e402e98cab3b56d Mon Sep 17 00:00:00 2001 From: Remi REGNAULT Date: Tue, 28 Nov 2023 16:28:12 +0100 Subject: [PATCH 05/27] resolving code smells --- LeftOvers/screens/HomePage.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/LeftOvers/screens/HomePage.tsx b/LeftOvers/screens/HomePage.tsx index 415971f..60c0ba0 100644 --- a/LeftOvers/screens/HomePage.tsx +++ b/LeftOvers/screens/HomePage.tsx @@ -13,7 +13,7 @@ import bracketRight from '../assets/images/angle_bracket_right.png'; export default function HomePage({ navigation, props }) { - const {colors, toggleColors} = useContext(ColorContext); + const colors = useContext(ColorContext).colors const profiles = [ {name: "Johnny Silverhand", avatar: "plus_small.png", isActive: "flex"}, From c204a2a5429c71d01c65e4f2a34c807d05a4d3d5 Mon Sep 17 00:00:00 2001 From: Remi REGNAULT Date: Wed, 29 Nov 2023 08:40:49 +0100 Subject: [PATCH 06/27] add color context on page Ingredient Selection --- LeftOvers/components/FoodElementText.tsx | 7 +++---- LeftOvers/screens/IngredientSelection.tsx | 21 +++++++++++---------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/LeftOvers/components/FoodElementText.tsx b/LeftOvers/components/FoodElementText.tsx index bc9eefc..7e211cd 100644 --- a/LeftOvers/components/FoodElementText.tsx +++ b/LeftOvers/components/FoodElementText.tsx @@ -1,6 +1,5 @@ import React, { useContext } from 'react'; -import {StyleSheet,Pressable, Text, View, Image} from 'react-native'; -import Separator from '../components/Separator'; +import {StyleSheet,Pressable, Text, View} from 'react-native'; import ColorContext from '../theme/ColorContext'; @@ -12,8 +11,8 @@ const componentHeight = 60; const componentWidth = 280; -export default function FoodElementText(props : any) { - const {colors, toggleColors } = useContext(ColorContext) +export default function FoodElementText(props : foodElementImageProps) { + const colors = useContext(ColorContext).colors const styles = StyleSheet.create({ button: { diff --git a/LeftOvers/screens/IngredientSelection.tsx b/LeftOvers/screens/IngredientSelection.tsx index bb206ed..aa37de7 100644 --- a/LeftOvers/screens/IngredientSelection.tsx +++ b/LeftOvers/screens/IngredientSelection.tsx @@ -1,4 +1,4 @@ -import React, { useEffect, useState } from 'react'; +import React, { useContext, useEffect, useState } from 'react'; import { View, StyleSheet, Text, Image, Pressable, ActivityIndicator, FlatList } from 'react-native'; import { SafeAreaProvider } from 'react-native-safe-area-context'; import { Searchbar } from 'react-native-paper'; @@ -7,11 +7,14 @@ import FoodElementText from '../components/FoodElementText'; import CustomButton from '../components/CustomButton'; import Ingredient from '../Models/Ingredient'; import IngredientService from '../Services/Ingredients/IngredientsServices'; +import ColorContext from '../theme/ColorContext'; import plus from '../assets/images/plus.png'; import moins from '../assets/images/minus.png'; export default function IngredientSelection(props) { + const colors = useContext(ColorContext).colors + const alphabetArray: Array = ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"]; const [isLoading, setIsLoading] = useState(true); const [error, setError] = useState(); @@ -110,13 +113,13 @@ export default function IngredientSelection(props) { return ( - - + + {alphabetArray.map((source, index) => ( handleLetterPress(source)}> - {source} + {source} ))} @@ -128,9 +131,9 @@ export default function IngredientSelection(props) { value={searchQuery} style={{ margin: 10, - backgroundColor: '#F2F0E4', + backgroundColor: colors.cardBackground, borderWidth: 1, - borderColor: "#ACA279", + borderColor:colors.cardTitle, borderRadius: 15, height: 50, }} /> @@ -152,9 +155,9 @@ export default function IngredientSelection(props) { - + - Selected + Selected @@ -182,14 +185,12 @@ export default function IngredientSelection(props) { const styles = StyleSheet.create({ page: { flex: 1, - backgroundColor: '#59BDCD', alignItems: 'center', display: 'flex', flexWrap: 'wrap', padding: 20, }, element: { - backgroundColor: '#F2F0E4', borderRadius: 30, }, horizontalAlignement: { From 995095f20a6a5e76c5bf33b4b9a9a2dd755cbc91 Mon Sep 17 00:00:00 2001 From: Remi REGNAULT Date: Wed, 29 Nov 2023 08:49:59 +0100 Subject: [PATCH 07/27] removing unused variables --- LeftOvers/navigation/BottomBar.tsx | 2 +- LeftOvers/navigation/CookingStackScreen.tsx | 2 +- LeftOvers/navigation/HomeStackScreen.tsx | 3 +-- LeftOvers/navigation/ProfileStackScreen.tsx | 10 +++++----- LeftOvers/navigation/Utils.tsx | 2 +- LeftOvers/screens/CreateProfile.tsx | 2 +- LeftOvers/screens/Profiles.tsx | 2 +- 7 files changed, 11 insertions(+), 12 deletions(-) diff --git a/LeftOvers/navigation/BottomBar.tsx b/LeftOvers/navigation/BottomBar.tsx index 56f9419..61ab00f 100644 --- a/LeftOvers/navigation/BottomBar.tsx +++ b/LeftOvers/navigation/BottomBar.tsx @@ -16,7 +16,7 @@ import DarkIcon from '../assets/images/moon.png'; export default function BottomBar({ state, descriptors, navigation }) { const {theme, toggleTheme} = useContext(ThemeContext); - const {colors, toggleColors} = useContext(ColorContext) + const toggleColors = useContext(ColorContext).toggleColors; const [iconThemeButton, setThemeIconButton] = useState(( theme === 'dark' ) ? LightIcon : DarkIcon) const [textThemeButton, setTextThemeButton] = useState(( theme === 'dark' ) ? 'Light' : 'Dark'); diff --git a/LeftOvers/navigation/CookingStackScreen.tsx b/LeftOvers/navigation/CookingStackScreen.tsx index 6dc6ded..4a9e791 100644 --- a/LeftOvers/navigation/CookingStackScreen.tsx +++ b/LeftOvers/navigation/CookingStackScreen.tsx @@ -8,7 +8,7 @@ import ThemeContext from '../theme/ThemeContext'; const CookingStack = createNativeStackNavigator() export default function CookingStackScreen() { - const {theme, toggleTheme} = useContext(ThemeContext); + const theme = useContext(ThemeContext).theme; return ( diff --git a/LeftOvers/navigation/HomeStackScreen.tsx b/LeftOvers/navigation/HomeStackScreen.tsx index 6864e34..9eca446 100644 --- a/LeftOvers/navigation/HomeStackScreen.tsx +++ b/LeftOvers/navigation/HomeStackScreen.tsx @@ -23,8 +23,7 @@ function AppIcon() { } export default function HomeStackScreen() { - const {theme, toggleTheme} = useContext(ThemeContext) - const {colors, toggleColors} = useContext(ColorContext) + const colors = useContext(ColorContext).colors return ( diff --git a/LeftOvers/navigation/ProfileStackScreen.tsx b/LeftOvers/navigation/ProfileStackScreen.tsx index ea88a7f..ce664ee 100644 --- a/LeftOvers/navigation/ProfileStackScreen.tsx +++ b/LeftOvers/navigation/ProfileStackScreen.tsx @@ -5,7 +5,7 @@ import { createNativeStackNavigator } from '@react-navigation/native-stack'; import Profiles from '../screens/Profiles'; import CreateProfile from '../screens/CreateProfile'; import ModifyProfile from '../screens/ModifyProfile'; -import ThemeContext from '../theme/ThemeContext'; +import ColorContext from '../theme/ColorContext'; import { HeaderTitle } from './Utils'; @@ -15,11 +15,11 @@ import AddIcon from '../assets/images/plus.png' const ProfilesStack = createNativeStackNavigator() export default function ProfilesStackScreen({ navigation }) { - const {theme, toggleTheme} = useContext(ThemeContext); + const colors = useContext(ColorContext).colors; const styles = StyleSheet.create({ headerBarContainer: { - backgroundColor: theme === 'light' ? '#F2F0E4' : '#3F3C42', + backgroundColor: colors.cardBackground, }, headerBarRightContainer: { display: 'flex', @@ -53,13 +53,13 @@ export default function ProfilesStackScreen({ navigation }) { + tintColor={colors.cardDetail}/> + tintColor={colors.cardDetail}/> ) diff --git a/LeftOvers/navigation/Utils.tsx b/LeftOvers/navigation/Utils.tsx index 0a6c072..4a3a9bc 100644 --- a/LeftOvers/navigation/Utils.tsx +++ b/LeftOvers/navigation/Utils.tsx @@ -4,7 +4,7 @@ import { Text, StyleSheet } from 'react-native'; import ColorContext from '../theme/ColorContext'; export function HeaderTitle(props) { - const {colors, toggleColors} = useContext(ColorContext) + const colors = useContext(ColorContext).colors const styles = StyleSheet.create({ headerTitle: { diff --git a/LeftOvers/screens/CreateProfile.tsx b/LeftOvers/screens/CreateProfile.tsx index a8fe93d..947cb0c 100644 --- a/LeftOvers/screens/CreateProfile.tsx +++ b/LeftOvers/screens/CreateProfile.tsx @@ -8,7 +8,7 @@ import ValidateButton from '../components/ValidateButton'; import ColorContext from '../theme/ColorContext'; export default function CreateProfile(props) { - const { colors, toggleColors } = useContext(ColorContext) + const colors = useContext(ColorContext).colors const all = [] const die = [{value: "Dairy free"}, {value: "Gluten free"}, {value: "Porkless"}, {value: "Vegan"}, {value: "Vegetarian"}, {value: "Pescatarian"}] diff --git a/LeftOvers/screens/Profiles.tsx b/LeftOvers/screens/Profiles.tsx index 72617cb..c086032 100644 --- a/LeftOvers/screens/Profiles.tsx +++ b/LeftOvers/screens/Profiles.tsx @@ -9,7 +9,7 @@ import ProfileDelete from '../components/ProfileDelete'; import ColorContext from '../theme/ColorContext'; export default function Profiles({navigation, props}) { - const { colors, toggleColors } = useContext(ColorContext) + const colors = useContext(ColorContext).colors const allJohnny = [{value: "Coconut"}, {value: "Skimmed Milk"}, {value: "Nuts"}] const dieJohnny = [{value: "Gluten free"}, {value: "Porkless"}, {value: "Pescatarian"}] From ff4f27d1b76b58e346fe7d9eae683a2e43985b39 Mon Sep 17 00:00:00 2001 From: Remi REGNAULT Date: Wed, 29 Nov 2023 08:53:46 +0100 Subject: [PATCH 08/27] removing unused variables and imports --- LeftOvers/components/ListWithoutSelect.tsx | 9 ++++----- LeftOvers/components/ProfileDetails.tsx | 2 +- LeftOvers/components/ProfileElement.tsx | 2 +- LeftOvers/components/ProfileModification.tsx | 2 +- LeftOvers/components/ProfileSelection.tsx | 2 +- 5 files changed, 8 insertions(+), 9 deletions(-) diff --git a/LeftOvers/components/ListWithoutSelect.tsx b/LeftOvers/components/ListWithoutSelect.tsx index 758c0ff..0502eba 100644 --- a/LeftOvers/components/ListWithoutSelect.tsx +++ b/LeftOvers/components/ListWithoutSelect.tsx @@ -1,8 +1,7 @@ import React, { useContext } from 'react'; -import {StyleSheet, Text, TextInput, View, Image, FlatList, Pressable} from 'react-native'; -import ValidateButton from './ValidateButton'; -import HeaderFlatList from './HeaderFlatList'; -import { MultipleSelectList, SelectList } from 'react-native-dropdown-select-list' +import { StyleSheet, Image } from 'react-native'; + +import { MultipleSelectList } from 'react-native-dropdown-select-list' import ColorContext from '../theme/ColorContext'; type ListProps = { @@ -12,7 +11,7 @@ type ListProps = { export default function ListWithoutSelect(props: ListProps) { const [selected, setSelected] = React.useState([]); - const { colors, toggleColors } = useContext(ColorContext); + const colors = useContext(ColorContext).colors; const styles = StyleSheet.create({ titleBar: { diff --git a/LeftOvers/components/ProfileDetails.tsx b/LeftOvers/components/ProfileDetails.tsx index ea8ab6e..73a0a5a 100644 --- a/LeftOvers/components/ProfileDetails.tsx +++ b/LeftOvers/components/ProfileDetails.tsx @@ -14,7 +14,7 @@ type ProfileProps = { } export default function ProfileDetails(props) { - const { colors, toggleColors } = useContext(ColorContext) + const colors = useContext(ColorContext).colors const navigation = useNavigation() const [display, setDisplay] = useState("none") const changeListVisibility = () => { diff --git a/LeftOvers/components/ProfileElement.tsx b/LeftOvers/components/ProfileElement.tsx index f3ecf30..58c14cc 100644 --- a/LeftOvers/components/ProfileElement.tsx +++ b/LeftOvers/components/ProfileElement.tsx @@ -10,7 +10,7 @@ type Profile = { } export default function ProfileElement(props : Profile) { - const { colors, toggleColors } = useContext(ColorContext) + const colors = useContext(ColorContext).colors const [waiting, setWaiting] = useState("none") const [separator, setSeparator] = useState("none") diff --git a/LeftOvers/components/ProfileModification.tsx b/LeftOvers/components/ProfileModification.tsx index 52dbc0e..9c383ec 100644 --- a/LeftOvers/components/ProfileModification.tsx +++ b/LeftOvers/components/ProfileModification.tsx @@ -15,7 +15,7 @@ type ProfileProps = { export default function ProfileModification(props: ProfileProps) { const [name, onChangeName] = useState(props.name); - const { colors, toggleColors } = useContext(ColorContext); + const colors = useContext(ColorContext).colors; let imageSource if (props.avatar == "plus.png"){ diff --git a/LeftOvers/components/ProfileSelection.tsx b/LeftOvers/components/ProfileSelection.tsx index 87d349e..da4c253 100644 --- a/LeftOvers/components/ProfileSelection.tsx +++ b/LeftOvers/components/ProfileSelection.tsx @@ -19,7 +19,7 @@ type Profile = { } export default function ProfileSelection(props: ProfileSelectionProps) { - const { colors, toggleColors } = useContext(ColorContext); + const colors = useContext(ColorContext).colors; const [cpt, setCpt] = useState(0); const decreaseCounter = () => { From 39484c90e9e1cee8335b8f92f93ecd5790b557f7 Mon Sep 17 00:00:00 2001 From: Remi REGNAULT Date: Wed, 29 Nov 2023 08:55:15 +0100 Subject: [PATCH 09/27] removing unused variables and imports --- LeftOvers/components/HeaderFlatList.tsx | 2 +- LeftOvers/components/ListSelect.tsx | 8 +++----- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/LeftOvers/components/HeaderFlatList.tsx b/LeftOvers/components/HeaderFlatList.tsx index e29de73..671b85d 100644 --- a/LeftOvers/components/HeaderFlatList.tsx +++ b/LeftOvers/components/HeaderFlatList.tsx @@ -1,5 +1,5 @@ import React from 'react'; -import {StyleSheet, Text, TextInput, View, Image, FlatList} from 'react-native'; +import {StyleSheet, Text, View, Image} from 'react-native'; type TitleProps = { title: string diff --git a/LeftOvers/components/ListSelect.tsx b/LeftOvers/components/ListSelect.tsx index a4ff431..879d189 100644 --- a/LeftOvers/components/ListSelect.tsx +++ b/LeftOvers/components/ListSelect.tsx @@ -1,8 +1,6 @@ import React, { useContext } from 'react'; -import {StyleSheet, Text, TextInput, View, Image, FlatList} from 'react-native'; -import ValidateButton from './ValidateButton'; -import HeaderFlatList from './HeaderFlatList'; -import { MultipleSelectList, SelectList } from 'react-native-dropdown-select-list' +import { StyleSheet, Image } from 'react-native'; +import { MultipleSelectList } from 'react-native-dropdown-select-list' import ColorContext from '../theme/ColorContext'; type ListProps = { @@ -12,7 +10,7 @@ type ListProps = { export default function ListSelect(props: ListProps) { const [selected, setSelected] = React.useState([]); - const { colors, toggleColors } = useContext(ColorContext); + const colors = useContext(ColorContext).colors; const styles = StyleSheet.create({ titleBar: { From cffc79e73047e90cb67eb52d4808d9b918e8c0ed Mon Sep 17 00:00:00 2001 From: Remi REGNAULT Date: Mon, 4 Dec 2023 10:21:31 +0100 Subject: [PATCH 10/27] fix: colors wasnt define in BottomBar. now it works --- LeftOvers/navigation/BottomBar.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/LeftOvers/navigation/BottomBar.tsx b/LeftOvers/navigation/BottomBar.tsx index 1baac98..e2d83bd 100644 --- a/LeftOvers/navigation/BottomBar.tsx +++ b/LeftOvers/navigation/BottomBar.tsx @@ -15,7 +15,7 @@ import DarkIcon from '../assets/images/moon.png'; export default function BottomBar({ state, descriptors, navigation }) { const {theme, toggleTheme} = useContext(ThemeContext); - const toggleColors = useContext(ColorContext).toggleColors; + const { colors, toggleColors } = useContext(ColorContext); const [iconThemeButton, setThemeIconButton] = useState(( theme === 'dark' ) ? LightIcon : DarkIcon) const [textThemeButton, setTextThemeButton] = useState(( theme === 'dark' ) ? 'Light' : 'Dark'); From f622179de17f1f97be28eee1c26f0fce90df5e3e Mon Sep 17 00:00:00 2001 From: Remi REGNAULT Date: Mon, 4 Dec 2023 10:26:11 +0100 Subject: [PATCH 11/27] fix: BottomBar - more use of colors variable --- LeftOvers/navigation/BottomBar.tsx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/LeftOvers/navigation/BottomBar.tsx b/LeftOvers/navigation/BottomBar.tsx index e2d83bd..a65c78d 100644 --- a/LeftOvers/navigation/BottomBar.tsx +++ b/LeftOvers/navigation/BottomBar.tsx @@ -47,10 +47,10 @@ export default function BottomBar({ state, descriptors, navigation }) { flexDirection: 'row', alignItems: 'center', alignContent: 'space-around', - borderBlockColor: theme === 'light' ? '#F2F0E4' : '#222222', + borderBlockColor: colors.blocBorder, borderWidth: 2, - borderLeftColor: theme === 'light'? '#F2F0E4' : '#222222', - borderRightColor: theme === 'light'? '#F2F0E4' : '#222222', + borderLeftColor: colors.blocBorder, + borderRightColor: colors.blocBorder, }, BottomBarIcon: { width: 25, From 05ffc723038284aaf770630f4b2e4f57ae42659a Mon Sep 17 00:00:00 2001 From: Remi REGNAULT Date: Mon, 4 Dec 2023 10:55:13 +0100 Subject: [PATCH 12/27] feat: add IProfileService and ProfileService --- LeftOvers/Services/Profiles/IProfileService.ts | 6 ++++++ LeftOvers/Services/Profiles/ProfileService.ts | 14 ++++++++++++++ LeftOvers/components/ProfileDetails.tsx | 1 + LeftOvers/screens/Profiles.tsx | 7 ++++--- 4 files changed, 25 insertions(+), 3 deletions(-) create mode 100644 LeftOvers/Services/Profiles/IProfileService.ts create mode 100644 LeftOvers/Services/Profiles/ProfileService.ts diff --git a/LeftOvers/Services/Profiles/IProfileService.ts b/LeftOvers/Services/Profiles/IProfileService.ts new file mode 100644 index 0000000..477cc76 --- /dev/null +++ b/LeftOvers/Services/Profiles/IProfileService.ts @@ -0,0 +1,6 @@ +import Profil from "../../Models/Profil"; + +export default interface IProfileService { + getProfiles(): Promise, + addProfile(new_profile: Profil): void +} \ No newline at end of file diff --git a/LeftOvers/Services/Profiles/ProfileService.ts b/LeftOvers/Services/Profiles/ProfileService.ts new file mode 100644 index 0000000..61cd418 --- /dev/null +++ b/LeftOvers/Services/Profiles/ProfileService.ts @@ -0,0 +1,14 @@ +import Profil from "../../Models/Profil"; +import IProfileService from "./IProfileService"; +import AsyncStorage from "@react-native-async-storage/async-storage"; + +export default class ProfileService implements IProfileService { + async getProfiles(): Promise { + const existingProfiles = await AsyncStorage.getItem('profiles'); + return JSON.parse(existingProfiles) || []; + } + addProfile(new_profile : Profil): void { + throw new Error("Method not implemented."); + } + +} \ No newline at end of file diff --git a/LeftOvers/components/ProfileDetails.tsx b/LeftOvers/components/ProfileDetails.tsx index 06ddea2..b0162f1 100644 --- a/LeftOvers/components/ProfileDetails.tsx +++ b/LeftOvers/components/ProfileDetails.tsx @@ -1,5 +1,6 @@ import React, { useContext, useState } from 'react'; import { StyleSheet, Text, View, Image, Pressable } from 'react-native'; +import { useNavigation } from '@react-navigation/native'; import ListWithoutSelect from './ListWithoutSelect'; import ColorContext from '../theme/ColorContext'; diff --git a/LeftOvers/screens/Profiles.tsx b/LeftOvers/screens/Profiles.tsx index b96f90a..dd46e2d 100644 --- a/LeftOvers/screens/Profiles.tsx +++ b/LeftOvers/screens/Profiles.tsx @@ -11,9 +11,11 @@ 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'; +import ProfileService from '../Services/Profiles/ProfileService'; export default function Profiles({navigation, props}) { const colors = useContext(ColorContext).colors + const profile_service = new ProfileService() const all = [] const die = [{value: "Dairy free"}, {value: "Gluten free"}, {value: "Porkless"}, {value: "Vegan"}, {value: "Vegetarian"}, {value: "Pescatarian"}] @@ -56,10 +58,9 @@ export default function Profiles({navigation, props}) { erasePopUp(); }; - const handleGetProfiles = async () => { + const handleGetProfiles = async () => { try { - const existingProfiles = await AsyncStorage.getItem('profiles'); - return JSON.parse(existingProfiles) || []; + return await profile_service.getProfiles() } catch (error) { console.log("ça maaaaaaaaarche poaaaaaaaaaaaas"); return []; From 24537f1b852684116fe74350a8be1a74121b68b3 Mon Sep 17 00:00:00 2001 From: Remi REGNAULT Date: Mon, 4 Dec 2023 12:04:58 +0100 Subject: [PATCH 13/27] feat: CreateProfile use profile and not struct specified in CreateProfile --- .../Services/Profiles/IProfileService.ts | 2 +- LeftOvers/Services/Profiles/ProfileService.ts | 8 +++++-- LeftOvers/screens/CreateProfile.tsx | 21 +++++++------------ LeftOvers/screens/Profiles.tsx | 16 +++++++------- 4 files changed, 21 insertions(+), 26 deletions(-) diff --git a/LeftOvers/Services/Profiles/IProfileService.ts b/LeftOvers/Services/Profiles/IProfileService.ts index 477cc76..3aea6ff 100644 --- a/LeftOvers/Services/Profiles/IProfileService.ts +++ b/LeftOvers/Services/Profiles/IProfileService.ts @@ -2,5 +2,5 @@ import Profil from "../../Models/Profil"; export default interface IProfileService { getProfiles(): Promise, - addProfile(new_profile: Profil): void + addProfile(new_profile: Profil): Promise } \ No newline at end of file diff --git a/LeftOvers/Services/Profiles/ProfileService.ts b/LeftOvers/Services/Profiles/ProfileService.ts index 61cd418..78f66e3 100644 --- a/LeftOvers/Services/Profiles/ProfileService.ts +++ b/LeftOvers/Services/Profiles/ProfileService.ts @@ -7,8 +7,12 @@ export default class ProfileService implements IProfileService { const existingProfiles = await AsyncStorage.getItem('profiles'); return JSON.parse(existingProfiles) || []; } - addProfile(new_profile : Profil): void { - throw new Error("Method not implemented."); + + async addProfile(new_profile : Profil): Promise { + const list = [new_profile] + const key_exist = ((await AsyncStorage.getAllKeys()).includes('profiles')) + if (!key_exist) await AsyncStorage.setItem('profiles', JSON.stringify(list)) + else await AsyncStorage.mergeItem('profiles', JSON.stringify(list)) } } \ No newline at end of file diff --git a/LeftOvers/screens/CreateProfile.tsx b/LeftOvers/screens/CreateProfile.tsx index 450ad13..4cfc583 100644 --- a/LeftOvers/screens/CreateProfile.tsx +++ b/LeftOvers/screens/CreateProfile.tsx @@ -9,15 +9,18 @@ import ListSelect from '../components/ListSelect'; import AsyncStorage from '@react-native-async-storage/async-storage'; import EventEmitter from './EventEmitter'; import * as ImagePicker from 'expo-image-picker'; +import ProfileService from '../Services/Profiles/ProfileService'; +import Profil from '../Models/Profil'; export default function CreateProfile(props) { const colors = useContext(ColorContext).colors - const all = [] + const profile_service = new ProfileService() const die = [{value: "Dairy free"}, {value: "Gluten free"}, {value: "Porkless"}, {value: "Vegan"}, {value: "Vegetarian"}, {value: "Pescatarian"}] const [name, onChangeName] = useState(); const [avatar, setAvatar] = useState(''); const [selectedDiets, setSelectedDiets] = useState([]); + const [selectedAllergies, setSelectedAllergies] = useState([]) const handleSelectedDiets = (selectedValues) => { setSelectedDiets(selectedValues); @@ -54,22 +57,12 @@ export default function CreateProfile(props) { const handleCreateProfile = async () => { try { // Ton code pour récupérer les profils existants et ajouter un nouveau profil - const newProfile = { - name: name, - avatar: avatar, - diets: selectedDiets, - allergies: all, - }; + const new_profile = new Profil(name, avatar, selectedAllergies, selectedDiets) // Mettre à jour AsyncStorage avec le nouveau profil - let existingProfiles = await AsyncStorage.getItem('profiles'); - existingProfiles = existingProfiles ? JSON.parse(existingProfiles) : []; - const updatedProfiles = [...existingProfiles, newProfile]; - await AsyncStorage.setItem('profiles', JSON.stringify(updatedProfiles)); + await profile_service.addProfile(new_profile) EventEmitter.emit('profileAdded'); - console.log('Profil créé :', newProfile); - props.navigation.goBack(); alert('Profil créé !'); @@ -173,7 +166,7 @@ export default function CreateProfile(props) { - + diff --git a/LeftOvers/screens/Profiles.tsx b/LeftOvers/screens/Profiles.tsx index dd46e2d..278e958 100644 --- a/LeftOvers/screens/Profiles.tsx +++ b/LeftOvers/screens/Profiles.tsx @@ -60,7 +60,8 @@ export default function Profiles({navigation, props}) { const handleGetProfiles = async () => { try { - return await profile_service.getProfiles() + const results = await profile_service.getProfiles() + return results } catch (error) { console.log("ça maaaaaaaaarche poaaaaaaaaaaaas"); return []; @@ -78,15 +79,12 @@ export default function Profiles({navigation, props}) { useEffect(() => { fetchProfiles(); - console.log(profiles) }, []); const containerStyle = { height: "75%", width: "100%", - }; - - + }; const styles = StyleSheet.create({ container: { height: "100%", @@ -201,10 +199,10 @@ export default function Profiles({navigation, props}) { const profileComponents = profiles.map((profile, index) => ( raisePopUp(index)} /> From 996d656d18407c326ed5b2dd876ba4098f7688cf Mon Sep 17 00:00:00 2001 From: Remi REGNAULT Date: Mon, 4 Dec 2023 14:30:26 +0100 Subject: [PATCH 14/27] fix: profile creation --- .../Services/Profiles/IProfileService.ts | 2 +- LeftOvers/Services/Profiles/ProfileService.ts | 24 +++++++++---- LeftOvers/screens/CreateProfile.tsx | 36 ++++++++++--------- 3 files changed, 38 insertions(+), 24 deletions(-) diff --git a/LeftOvers/Services/Profiles/IProfileService.ts b/LeftOvers/Services/Profiles/IProfileService.ts index 3aea6ff..e83e010 100644 --- a/LeftOvers/Services/Profiles/IProfileService.ts +++ b/LeftOvers/Services/Profiles/IProfileService.ts @@ -2,5 +2,5 @@ import Profil from "../../Models/Profil"; export default interface IProfileService { getProfiles(): Promise, - addProfile(new_profile: Profil): Promise + addProfile(new_profile: Profil): Promise } \ No newline at end of file diff --git a/LeftOvers/Services/Profiles/ProfileService.ts b/LeftOvers/Services/Profiles/ProfileService.ts index 78f66e3..75d93e5 100644 --- a/LeftOvers/Services/Profiles/ProfileService.ts +++ b/LeftOvers/Services/Profiles/ProfileService.ts @@ -4,15 +4,25 @@ import AsyncStorage from "@react-native-async-storage/async-storage"; export default class ProfileService implements IProfileService { async getProfiles(): Promise { - const existingProfiles = await AsyncStorage.getItem('profiles'); - return JSON.parse(existingProfiles) || []; + const results = await AsyncStorage.getItem('profiles'); + const tmp = JSON.parse(results) + let existingProfiles: Profil[] = [] + for (let item of tmp) { + existingProfiles.push(new Profil(item._name, item._avatar, item._allergy, item._diets)) + } + return existingProfiles; } - async addProfile(new_profile : Profil): Promise { - const list = [new_profile] - const key_exist = ((await AsyncStorage.getAllKeys()).includes('profiles')) - if (!key_exist) await AsyncStorage.setItem('profiles', JSON.stringify(list)) - else await AsyncStorage.mergeItem('profiles', JSON.stringify(list)) + async addProfile(new_profile : Profil): Promise { + const existingProfiles = await this.getProfiles() + for (let current_profile of existingProfiles) { + if (current_profile.name == new_profile.name) { + console.log("Tried to create a profil already existing !") + return false + } + } + await AsyncStorage.setItem('profiles', JSON.stringify([...existingProfiles, new_profile])) + return true } } \ No newline at end of file diff --git a/LeftOvers/screens/CreateProfile.tsx b/LeftOvers/screens/CreateProfile.tsx index 4cfc583..8a56cb3 100644 --- a/LeftOvers/screens/CreateProfile.tsx +++ b/LeftOvers/screens/CreateProfile.tsx @@ -29,16 +29,16 @@ export default function CreateProfile(props) { const pickImage = async () => { // No permissions request is necessary for launching the image library let result = await ImagePicker.launchImageLibraryAsync({ - mediaTypes: ImagePicker.MediaTypeOptions.All, - allowsEditing: true, - aspect: [4, 3], - quality: 1, + mediaTypes: ImagePicker.MediaTypeOptions.All, + allowsEditing: true, + aspect: [4, 3], + quality: 1, }); console.log(result); if (!result.canceled) { - setAvatar(result.assets[0].uri); + setAvatar(result.assets[0].uri); } }; @@ -56,18 +56,22 @@ export default function CreateProfile(props) { const handleCreateProfile = async () => { try { - // Ton code pour récupérer les profils existants et ajouter un nouveau profil - const new_profile = new Profil(name, avatar, selectedAllergies, selectedDiets) - - // Mettre à jour AsyncStorage avec le nouveau profil - await profile_service.addProfile(new_profile) - EventEmitter.emit('profileAdded'); - - props.navigation.goBack(); - - alert('Profil créé !'); + // Ton code pour récupérer les profils existants et ajouter un nouveau profil + const new_profile = new Profil(name, avatar, selectedAllergies, selectedDiets) + + // Mettre à jour AsyncStorage avec le nouveau profil + if (await profile_service.addProfile(new_profile)) { + EventEmitter.emit('profileAdded'); + props.navigation.goBack(); + alert('Profile Created !'); + } + else { + props.navigation.goBack() + alert('Profile already exists !') + } + } catch (error) { - console.error('Erreur lors de la création du profil :', error); + console.error('Erreur lors de la création du profil :', error); } }; From 8e27377e08fb9d14db2bf5fc5b105143a9c28569 Mon Sep 17 00:00:00 2001 From: Remi REGNAULT Date: Mon, 4 Dec 2023 15:00:02 +0100 Subject: [PATCH 15/27] fix: delete profile now use ProfileService.delProfile(name) --- LeftOvers/Services/Profiles/IProfileService.ts | 3 ++- LeftOvers/Services/Profiles/ProfileService.ts | 13 +++++++++++++ LeftOvers/screens/Profiles.tsx | 3 +-- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/LeftOvers/Services/Profiles/IProfileService.ts b/LeftOvers/Services/Profiles/IProfileService.ts index e83e010..a3fdfe6 100644 --- a/LeftOvers/Services/Profiles/IProfileService.ts +++ b/LeftOvers/Services/Profiles/IProfileService.ts @@ -2,5 +2,6 @@ import Profil from "../../Models/Profil"; export default interface IProfileService { getProfiles(): Promise, - addProfile(new_profile: Profil): Promise + addProfile(new_profile: Profil): Promise, + delProfile(profile_name_to_del: String): Promise } \ No newline at end of file diff --git a/LeftOvers/Services/Profiles/ProfileService.ts b/LeftOvers/Services/Profiles/ProfileService.ts index 75d93e5..e013180 100644 --- a/LeftOvers/Services/Profiles/ProfileService.ts +++ b/LeftOvers/Services/Profiles/ProfileService.ts @@ -25,4 +25,17 @@ export default class ProfileService implements IProfileService { return true } + async delProfile(profile_name_to_del: String): Promise { + const existing_profiles = await this.getProfiles() + let key: number = -1 + for (let current_profile of existing_profiles) { + if (current_profile.name == profile_name_to_del) { + let updated_profile = existing_profiles.splice(key, 1) + await AsyncStorage.setItem('profiles', JSON.stringify(updated_profile)) + return true + } + key ++ + } + return false + } } \ No newline at end of file diff --git a/LeftOvers/screens/Profiles.tsx b/LeftOvers/screens/Profiles.tsx index 278e958..acad12e 100644 --- a/LeftOvers/screens/Profiles.tsx +++ b/LeftOvers/screens/Profiles.tsx @@ -44,8 +44,7 @@ export default function Profiles({navigation, props}) { const handleDeleteProfile = async (index) => { try { - const updatedProfiles = profiles.filter((profile, i) => i !== index); - await AsyncStorage.setItem('profiles', JSON.stringify(updatedProfiles)); + await profile_service.delProfile(profiles[index].name) fetchProfiles(); setSelectedProfileIndex(index); erasePopUp(); From 3a4c0ddd98fe515236617b422577d5dc05ddf7b1 Mon Sep 17 00:00:00 2001 From: Remi REGNAULT Date: Mon, 4 Dec 2023 15:04:22 +0100 Subject: [PATCH 16/27] fix: removed useless imports --- LeftOvers/screens/CreateProfile.tsx | 1 - LeftOvers/screens/Profiles.tsx | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/LeftOvers/screens/CreateProfile.tsx b/LeftOvers/screens/CreateProfile.tsx index 8a56cb3..a2662db 100644 --- a/LeftOvers/screens/CreateProfile.tsx +++ b/LeftOvers/screens/CreateProfile.tsx @@ -6,7 +6,6 @@ import ValidateButton from '../components/ValidateButton'; import ColorContext from '../theme/ColorContext'; import ListWithoutSelect from '../components/ListWithoutSelect'; import ListSelect from '../components/ListSelect'; -import AsyncStorage from '@react-native-async-storage/async-storage'; import EventEmitter from './EventEmitter'; import * as ImagePicker from 'expo-image-picker'; import ProfileService from '../Services/Profiles/ProfileService'; diff --git a/LeftOvers/screens/Profiles.tsx b/LeftOvers/screens/Profiles.tsx index acad12e..325ec0f 100644 --- a/LeftOvers/screens/Profiles.tsx +++ b/LeftOvers/screens/Profiles.tsx @@ -40,7 +40,7 @@ export default function Profiles({navigation, props}) { } catch (error) { console.error('Erreur lors de la suppression des données :', error); } - }; + }; const handleDeleteProfile = async (index) => { try { From ab1cc07648f9f4d62dbf0b5c6a6dce79953ec105 Mon Sep 17 00:00:00 2001 From: Remi REGNAULT Date: Tue, 5 Dec 2023 08:06:18 +0100 Subject: [PATCH 17/27] feat: start of profile on home page --- LeftOvers/screens/HomePage.tsx | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/LeftOvers/screens/HomePage.tsx b/LeftOvers/screens/HomePage.tsx index e1eb26d..84a6802 100644 --- a/LeftOvers/screens/HomePage.tsx +++ b/LeftOvers/screens/HomePage.tsx @@ -1,4 +1,4 @@ -import React, { useContext, useState } from 'react'; +import React, { useContext, useEffect, useState } from 'react'; import { StyleSheet, View, Text, Pressable, Image, ScrollView } from 'react-native'; import {LinearGradient} from 'expo-linear-gradient'; import {SafeAreaProvider} from 'react-native-safe-area-context'; @@ -7,6 +7,8 @@ import ValidateButton from '../components/ValidateButton'; import ProfileSelection from '../components/ProfileSelection'; import FoodElementText from '../components/FoodElementText'; import ColorContext from '../theme/ColorContext'; +import ProfileService from '../Services/Profiles/ProfileService'; +import Profil from '../Models/Profil'; import bracketLeft from '../assets/images/angle_bracket_left.png'; import bracketRight from '../assets/images/angle_bracket_right.png'; @@ -14,6 +16,7 @@ import bracketRight from '../assets/images/angle_bracket_right.png'; export default function HomePage({ navigation, props }) { const colors = useContext(ColorContext).colors + const profile_service = new ProfileService() const profiles = [ {name: "Johnny Silverhand", avatar: "plus_small.png", isActive: "flex"}, @@ -22,6 +25,22 @@ export default function HomePage({ navigation, props }) { {name: "David Martinez", avatar: "plus_small.png", isActive: "flex"}, ] + const [existingProfiles, setExistingProfiles]: [Profil[], React.Dispatch] = useState([]) + const [data, setData] = useState([]) + const loadProfiles = async () => { + setExistingProfiles(await profile_service.getProfiles()) + // for (let current_profile of existingProfiles) { + // let new_data = [{profile=current_profile, isActive="none"}] + // data.push({profile, isActive="none"}) + // } + } + + useEffect(() => { + loadProfiles() + }, []) + + + const ingredientList = [{title: "Carrot"}, {title: "Potato"}, {title: "Peach"}] const [cpt, setCpt] = useState(0); From 8fdddda189095a45685ffee3f529ea151757b9df Mon Sep 17 00:00:00 2001 From: Louison PARANT Date: Tue, 5 Dec 2023 08:57:29 +0100 Subject: [PATCH 18/27] 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}) { - ); From 57c6c66b2441d4ab1ab50f4b27abbad70c52c064 Mon Sep 17 00:00:00 2001 From: Louison PARANT Date: Tue, 5 Dec 2023 09:02:28 +0100 Subject: [PATCH 19/27] Fix FoodElementText Height --- LeftOvers/components/FoodElementText.tsx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/LeftOvers/components/FoodElementText.tsx b/LeftOvers/components/FoodElementText.tsx index 006abc8..2da10b3 100644 --- a/LeftOvers/components/FoodElementText.tsx +++ b/LeftOvers/components/FoodElementText.tsx @@ -37,11 +37,12 @@ export default function FoodElementText(props : any) { alignItems: 'flex-start', justifyContent: 'center', marginRight: "3%", + marginBottom: "2%", width: "100%" }, container: { width: "100%", - height: 50, + //height: 50, borderRadius: 5, borderWidth: 2, borderColor: props.secondaryColour ? props.secondaryColour : colors.foodElementBorder, From 98dcac200f3d0831dccc90c08b839921b1b7ae6f Mon Sep 17 00:00:00 2001 From: Louison PARANT Date: Tue, 5 Dec 2023 09:42:46 +0100 Subject: [PATCH 20/27] Profile Management (Home/Profiles Pages) --- LeftOvers/components/ProfileDetails.tsx | 10 +++------- LeftOvers/components/ProfileElement.tsx | 2 +- LeftOvers/screens/CreateProfile.tsx | 9 +-------- LeftOvers/screens/HomePage.tsx | 26 ++++++++++++++----------- LeftOvers/screens/Profiles.tsx | 1 - 5 files changed, 20 insertions(+), 28 deletions(-) diff --git a/LeftOvers/components/ProfileDetails.tsx b/LeftOvers/components/ProfileDetails.tsx index c372b11..777397f 100644 --- a/LeftOvers/components/ProfileDetails.tsx +++ b/LeftOvers/components/ProfileDetails.tsx @@ -26,15 +26,11 @@ export default function ProfileDetails(props) { }; let imageSource - - if (props.avatar === "plus.png"){ - imageSource = require('../assets/images/plus.png') - } - else if (props.avatar === "plus_small.png"){ - imageSource = require('../assets/images/plus_small.png') + if (props.avatar == ""){ + imageSource = require("../assets/images/logo.png") } else{ - imageSource = require('../assets/images/logo.png') + imageSource = {uri: props.avatar} } const styles = StyleSheet.create({ diff --git a/LeftOvers/components/ProfileElement.tsx b/LeftOvers/components/ProfileElement.tsx index 28fb4fe..c75b8d9 100644 --- a/LeftOvers/components/ProfileElement.tsx +++ b/LeftOvers/components/ProfileElement.tsx @@ -36,7 +36,7 @@ export default function ProfileElement(props : Profile) { } let imageSource - if(props.avatar == null){ + if(props.avatar == ""){ imageSource=require("../assets/images/logo.png") } else{ diff --git a/LeftOvers/screens/CreateProfile.tsx b/LeftOvers/screens/CreateProfile.tsx index 32bdf4f..52d3ade 100644 --- a/LeftOvers/screens/CreateProfile.tsx +++ b/LeftOvers/screens/CreateProfile.tsx @@ -41,13 +41,7 @@ export default function CreateProfile(props) { let imageSource - if (props.avatar == "plus.png"){ - imageSource = {uri: avatar} - } - else if (props.avatar == "plus_small.png"){ - imageSource = {uri: avatar} - } - else if (props.avatar == ""){ + if (props.avatar == ""){ imageSource = require("../assets/images/logo.png") } else{ @@ -72,7 +66,6 @@ export default function CreateProfile(props) { 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); } diff --git a/LeftOvers/screens/HomePage.tsx b/LeftOvers/screens/HomePage.tsx index b8897b7..4dd8d28 100644 --- a/LeftOvers/screens/HomePage.tsx +++ b/LeftOvers/screens/HomePage.tsx @@ -18,14 +18,10 @@ export default function HomePage({ navigation, props }) { const {colors} = useContext(ColorContext); const profilesHand = [ - {name: "Johnny Silverhand", avatar: "plus_small.png", isActive: "flex"}, - {name: "Panam Palmer", avatar: "plus_small.png", isActive: "none"}, - {name: "Goro Takemura", avatar: "plus_small.png", isActive: "none"}, - {name: "David Martinez", avatar: "plus_small.png", isActive: "flex"}, + {name: "None", avatar: "logo.png", isActive: "none"} ] - const [profiles, setProfiles] = useState([{name: "None", avatar: "plus_small.png", isActive: "none"}]); - console.log(profiles, profiles.length) + const [profiles, setProfiles] = useState(profilesHand); const handleGetProfiles = async () => { try { @@ -39,7 +35,13 @@ export default function HomePage({ navigation, props }) { const fetchProfiles = async () => { const existingProfiles = await handleGetProfiles(); - setProfiles(existingProfiles); + console.log("Existing Profiles: ---------------------------------"+existingProfiles, existingProfiles.length) + if (existingProfiles.length != 0){ + setProfiles(existingProfiles); + } + else{ + setProfiles(profilesHand) + } }; const subscription = EventEmitter.addListener('profileAdded', async () => { @@ -47,17 +49,19 @@ export default function HomePage({ navigation, props }) { }); const subscriptionDeleteProfile = EventEmitter.addListener('profileDeleted', async () => { - fetchProfiles(); + if (profiles.length == 1){ + setProfiles(profilesHand) + } + else{ + fetchProfiles(); + } }); useEffect(() => { fetchProfiles(); - console.log(profiles.length) if(profiles.length == 0){ setProfiles([{name: "None", avatar: "plus_small.png", isActive: "none"}]) - console.log("Je passe ici") } - console.log(profiles) }, []); const ingredientList = [{title: "Carrot"}, {title: "Potato"}, {title: "Peach"}] diff --git a/LeftOvers/screens/Profiles.tsx b/LeftOvers/screens/Profiles.tsx index 4a54ca6..331474c 100644 --- a/LeftOvers/screens/Profiles.tsx +++ b/LeftOvers/screens/Profiles.tsx @@ -48,7 +48,6 @@ export default function Profiles({navigation, props}) { fetchProfiles(); setSelectedProfileIndex(index); erasePopUp(); - alert('Profile Deleted!'); } catch (error) { console.error('Erreur lors de la suppression du profil :', error); } From 09967fa732de19e77ecba716379a24dab092f95c Mon Sep 17 00:00:00 2001 From: Louison PARANT Date: Tue, 5 Dec 2023 10:32:52 +0100 Subject: [PATCH 21/27] Profile/Recipe Management --- LeftOvers/screens/CreateProfile.tsx | 1 - LeftOvers/screens/HomePage.tsx | 1 - LeftOvers/screens/IngredientSelection.tsx | 1 - LeftOvers/screens/Profiles.tsx | 10 ---------- LeftOvers/screens/RecipeDetails.tsx | 3 --- 5 files changed, 16 deletions(-) diff --git a/LeftOvers/screens/CreateProfile.tsx b/LeftOvers/screens/CreateProfile.tsx index 52d3ade..90be921 100644 --- a/LeftOvers/screens/CreateProfile.tsx +++ b/LeftOvers/screens/CreateProfile.tsx @@ -162,7 +162,6 @@ export default function CreateProfile(props) { Filters - 0 diets selected diff --git a/LeftOvers/screens/HomePage.tsx b/LeftOvers/screens/HomePage.tsx index 4dd8d28..0b206b1 100644 --- a/LeftOvers/screens/HomePage.tsx +++ b/LeftOvers/screens/HomePage.tsx @@ -35,7 +35,6 @@ export default function HomePage({ navigation, props }) { const fetchProfiles = async () => { const existingProfiles = await handleGetProfiles(); - console.log("Existing Profiles: ---------------------------------"+existingProfiles, existingProfiles.length) if (existingProfiles.length != 0){ setProfiles(existingProfiles); } diff --git a/LeftOvers/screens/IngredientSelection.tsx b/LeftOvers/screens/IngredientSelection.tsx index ee7b49a..9a0a1fe 100644 --- a/LeftOvers/screens/IngredientSelection.tsx +++ b/LeftOvers/screens/IngredientSelection.tsx @@ -56,7 +56,6 @@ const loadIngredients = async () => { }; useEffect(() => { - console.log("Je passe ici (Ingredient Selection)") loadIngredients(); }, []); diff --git a/LeftOvers/screens/Profiles.tsx b/LeftOvers/screens/Profiles.tsx index 331474c..7ff396c 100644 --- a/LeftOvers/screens/Profiles.tsx +++ b/LeftOvers/screens/Profiles.tsx @@ -31,15 +31,6 @@ export default function Profiles({navigation, props}) { 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); @@ -74,7 +65,6 @@ export default function Profiles({navigation, props}) { useEffect(() => { fetchProfiles(); - console.log(profiles) }, []); const containerStyle = { diff --git a/LeftOvers/screens/RecipeDetails.tsx b/LeftOvers/screens/RecipeDetails.tsx index 595e4ee..0e6c5ac 100644 --- a/LeftOvers/screens/RecipeDetails.tsx +++ b/LeftOvers/screens/RecipeDetails.tsx @@ -26,9 +26,7 @@ export default function RecipeDetails(props) { const loadRecipe = async () => { try { const recipe = await recipesService.getRecipeById(120); - console.log("Recipe.name: "+recipe.name) setResponse(recipe); - console.log("Response.name: "+response.name) } catch (error) { console.log(error); } finally{ @@ -37,7 +35,6 @@ export default function RecipeDetails(props) { }; useEffect(() => { - console.log("Je passe ici (useEffect)") loadRecipe(); }, []); From c95100996d3f03a44e13b60260c27d033e8b91cf Mon Sep 17 00:00:00 2001 From: Louison PARANT Date: Tue, 5 Dec 2023 10:36:50 +0100 Subject: [PATCH 22/27] Code Smells Fix --- LeftOvers/screens/CreateProfile.tsx | 2 +- LeftOvers/screens/Profiles.tsx | 9 +-------- LeftOvers/screens/RecipeSuggestion.tsx | 1 - 3 files changed, 2 insertions(+), 10 deletions(-) diff --git a/LeftOvers/screens/CreateProfile.tsx b/LeftOvers/screens/CreateProfile.tsx index 90be921..0f67009 100644 --- a/LeftOvers/screens/CreateProfile.tsx +++ b/LeftOvers/screens/CreateProfile.tsx @@ -1,5 +1,5 @@ import React, { useContext, useState } from 'react'; -import {StyleSheet, View, ScrollView, useWindowDimensions, TextInput, Image, Text, NativeEventEmitter, Pressable} from 'react-native'; +import {StyleSheet, View, ScrollView, useWindowDimensions, TextInput, Image, Text, Pressable} from 'react-native'; import { LinearGradient } from 'expo-linear-gradient'; import { SafeAreaProvider } from 'react-native-safe-area-context'; import ValidateButton from '../components/ValidateButton'; diff --git a/LeftOvers/screens/Profiles.tsx b/LeftOvers/screens/Profiles.tsx index 7ff396c..c73af58 100644 --- a/LeftOvers/screens/Profiles.tsx +++ b/LeftOvers/screens/Profiles.tsx @@ -5,21 +5,14 @@ import { LinearGradient } from 'expo-linear-gradient'; 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'; 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) - - const all = [] - const die = [{value: "Dairy free"}, {value: "Gluten free"}, {value: "Porkless"}, {value: "Vegan"}, {value: "Vegetarian"}, {value: "Pescatarian"}] - + const { colors } = useContext(ColorContext) const [visible, setVisible] = useState(false); - const [opacity, setOpacity] = useState(1); const [profiles, setProfiles] = useState([]); const [selectedProfileIndex, setSelectedProfileIndex] = useState(null); diff --git a/LeftOvers/screens/RecipeSuggestion.tsx b/LeftOvers/screens/RecipeSuggestion.tsx index d6bfa1a..ceb5025 100644 --- a/LeftOvers/screens/RecipeSuggestion.tsx +++ b/LeftOvers/screens/RecipeSuggestion.tsx @@ -25,7 +25,6 @@ export default function RecipeSuggestion(props) { const [minCpt, setMinCpt] = useState(0); const [maxCpt, setMaxCpt] = useState(4); const ingredientList = [{title: "Steak"}, {title: "Sheep Ribs"}, {title: "Rabbit Thigh"}, {title: "Ham"}, {title: "Cream (Liquid)"}, {title: "Pepper Bell"}] - const ingredientListV2 = [{title: "Smoked Salmon"}, {title: "Tomato"}, {title: "Carrot"}] const limitedList = ingredientList.slice(minCpt, maxCpt); const [colorIngredients, setColorIngredients] = useState("#59BDCD"); const [colorFilters, setColorFilters] = useState(colors.cardDetail); From f31f1451e10fb51b49222e3613105802bf0ffc6c Mon Sep 17 00:00:00 2001 From: Louison PARANT Date: Tue, 5 Dec 2023 11:45:00 +0100 Subject: [PATCH 23/27] Ingredient Management (Ingredient Selection) --- LeftOvers/screens/HomePage.tsx | 47 ++++++++++++-- LeftOvers/screens/IngredientSelection.tsx | 79 ++++++++++++++++++++--- 2 files changed, 110 insertions(+), 16 deletions(-) diff --git a/LeftOvers/screens/HomePage.tsx b/LeftOvers/screens/HomePage.tsx index 0b206b1..7e1880b 100644 --- a/LeftOvers/screens/HomePage.tsx +++ b/LeftOvers/screens/HomePage.tsx @@ -20,8 +20,10 @@ export default function HomePage({ navigation, props }) { const profilesHand = [ {name: "None", avatar: "logo.png", isActive: "none"} ] + const ingredientListHand = [{name: "None"}] const [profiles, setProfiles] = useState(profilesHand); + const [ingredientList, setIngredientList] = useState(ingredientListHand) const handleGetProfiles = async () => { try { @@ -33,6 +35,16 @@ export default function HomePage({ navigation, props }) { } } + const handleGetAvailableIngredient = async () => { + try { + const existingAvailableIngredient = await AsyncStorage.getItem('ingredient'); + return JSON.parse(existingAvailableIngredient) || []; + } catch (error) { + console.log(error); + return []; + } + } + const fetchProfiles = async () => { const existingProfiles = await handleGetProfiles(); if (existingProfiles.length != 0){ @@ -43,7 +55,17 @@ export default function HomePage({ navigation, props }) { } }; - const subscription = EventEmitter.addListener('profileAdded', async () => { + const fetchAvailableIngredient = async () => { + const existingAvailableIngredient = await handleGetAvailableIngredient(); + if (existingAvailableIngredient.length != 0){ + setIngredientList(existingAvailableIngredient); + } + else{ + setIngredientList(ingredientListHand) + } + }; + + const subscriptionAddProfile = EventEmitter.addListener('profileAdded', async () => { fetchProfiles(); }); @@ -56,15 +78,28 @@ export default function HomePage({ navigation, props }) { } }); + const subscriptionAddIngredient = EventEmitter.addListener('ingredientAdded', async () => { + fetchAvailableIngredient(); + }); + + const subscriptionDeleteIngredient = EventEmitter.addListener('ingredientDeleted', async () => { + if (ingredientList.length == 1){ + setIngredientList(ingredientListHand) + } + else{ + fetchAvailableIngredient(); + } + }); + useEffect(() => { + //AsyncStorage.clear() fetchProfiles(); if(profiles.length == 0){ setProfiles([{name: "None", avatar: "plus_small.png", isActive: "none"}]) } + fetchAvailableIngredient(); }, []); - const ingredientList = [{title: "Carrot"}, {title: "Potato"}, {title: "Peach"}] - const [cpt, setCpt] = useState(0); const decreaseCounter = () => { if (cpt > 0) { @@ -212,16 +247,16 @@ export default function HomePage({ navigation, props }) { - + - console.log('Chnge Selected Ingredient')}/> + navigation.navigate("IngredientSelection")}/> - console.log('Go and search for recipe')}/> + navigation.navigate("RecipeSuggestion")}/> diff --git a/LeftOvers/screens/IngredientSelection.tsx b/LeftOvers/screens/IngredientSelection.tsx index 9a0a1fe..9b9c24f 100644 --- a/LeftOvers/screens/IngredientSelection.tsx +++ b/LeftOvers/screens/IngredientSelection.tsx @@ -10,6 +10,8 @@ import IngredientService from '../Services/Ingredients/IngredientsServices'; import { LinearGradient } from 'expo-linear-gradient'; import ColorContext from '../theme/ColorContext'; import ValidateButton from '../components/ValidateButton'; +import AsyncStorage from '@react-native-async-storage/async-storage'; +import EventEmitter from './EventEmitter'; export default function IngredientSelection(props) { const alphabetArray: Array = ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"]; @@ -57,6 +59,8 @@ const loadIngredients = async () => { useEffect(() => { loadIngredients(); + fetchAvailableIngredient(); + ChangeAvailableSize(true) }, []); const AvailableItem = ({ value }: { value: Ingredient }) => ( @@ -83,20 +87,70 @@ const loadIngredients = async () => { ); - const SelectIngredient = (newIngredient: Ingredient) => { - const exists = selectedIngredients.find((ingredient) => ingredient.id === newIngredient.id); - if (!exists) { - setSelectedIngredients([...selectedIngredients, newIngredient]); - ChangeAvailableSize(false) + const handleGetAvailableIngredient = async () => { + try { + const existingAvailableIngredient = await AsyncStorage.getItem('ingredient'); + return JSON.parse(existingAvailableIngredient) || []; + } catch (error) { + console.log(error); + return []; + } +} + +const fetchAvailableIngredient = async () => { + const existingAvailableIngredient = await handleGetAvailableIngredient(); + if (existingAvailableIngredient.length != 0){ + setSelectedIngredients(existingAvailableIngredient); + } + else{ + setSelectedIngredients([{value: "None"}]) + } +}; + + const SelectIngredient = async (newIngredient: Ingredient) => { + try{ + const exists = selectedIngredients.find((ingredient) => ingredient.id === newIngredient.id); + if (!exists) { + let existingAvailableIngredient = await AsyncStorage.getItem('ingredient'); + existingAvailableIngredient = existingAvailableIngredient ? JSON.parse(existingAvailableIngredient) : []; + const updatedAvailableIngredient = [...existingAvailableIngredient, newIngredient]; + await AsyncStorage.setItem('ingredient', JSON.stringify(updatedAvailableIngredient)); + EventEmitter.emit('ingredientAdded'); + console.log('Ingredient Added:', newIngredient); + ChangeAvailableSize(false) + } + } + catch(error){ + console.log("Error occured during the addition of Ingredient:", error) } }; - const RemoveIngredient = (idIngredient: number) => { - const updatedIngredients = selectedIngredients.filter((ingredient) => ingredient.id !== idIngredient); - setSelectedIngredients(updatedIngredients); - ChangeAvailableSize(true) + const RemoveIngredient = async (idIngredient: number) => { + try{ + const updatedIngredients = selectedIngredients.filter((ingredient) => ingredient.id !== idIngredient); + await AsyncStorage.setItem('ingredient', JSON.stringify(updatedIngredients)); + EventEmitter.emit('ingredientDeleted'); + fetchAvailableIngredient(); + setSelectedIngredients(updatedIngredients); + ChangeAvailableSize(true) + } + catch (error){ + console.log("Error occured during the suppression of Ingredient:", error) + } }; + const subscriptionAddIngredient = EventEmitter.addListener('ingredientAdded', async () => { + fetchAvailableIngredient(); + }); + const subscriptionDeleteIngredient = EventEmitter.addListener('ingredientDeleted', async () => { + if (selectedIngredients.length == 1){ + setSelectedIngredients([{title: "None"}]) + } + else{ + fetchAvailableIngredient(); + } + }); + const ChangeAvailableSize = (remove: boolean) => { if(remove){ if (selectedIngredients.length == 1){ @@ -120,7 +174,12 @@ const loadIngredients = async () => { setAvailableSize(90) } else if (selectedIngredients.length == 1){ - setAvailableSize(180) + if(selectedIngredients[0].value == "None"){ + setAvailableSize(90) + } + else{ + setAvailableSize(180) + } } else if (selectedIngredients.length == 2){ setAvailableSize(260) From bfcd950ecb1a9d07c233463f1e73a050e63b589c Mon Sep 17 00:00:00 2001 From: Louison PARANT Date: Tue, 5 Dec 2023 14:35:07 +0100 Subject: [PATCH 24/27] Maj Profile Management --- LeftOvers/components/ProfileSelection.tsx | 1 + LeftOvers/screens/CreateProfile.tsx | 2 ++ LeftOvers/screens/HomePage.tsx | 6 +++--- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/LeftOvers/components/ProfileSelection.tsx b/LeftOvers/components/ProfileSelection.tsx index 376ee7e..a750033 100644 --- a/LeftOvers/components/ProfileSelection.tsx +++ b/LeftOvers/components/ProfileSelection.tsx @@ -6,6 +6,7 @@ import ColorContext from '../theme/ColorContext'; import bracketLeft from '../assets/images/angle_bracket_left.png'; import bracketRight from '../assets/images/angle_bracket_right.png'; +import EventEmitter from '../screens/EventEmitter'; type ProfileSelectionProps = { listProfile: Profile[] diff --git a/LeftOvers/screens/CreateProfile.tsx b/LeftOvers/screens/CreateProfile.tsx index 0f67009..3091efb 100644 --- a/LeftOvers/screens/CreateProfile.tsx +++ b/LeftOvers/screens/CreateProfile.tsx @@ -56,6 +56,7 @@ export default function CreateProfile(props) { avatar: avatar, diets: selectedDiets, allergies: all, + isActive: "flex", }; // Mettre à jour AsyncStorage avec le nouveau profil @@ -105,6 +106,7 @@ export default function CreateProfile(props) { borderColor: colors.cardElementBorder, borderRadius: 45, height: "100%", + minHeight: 35, flex: 0.04, }, textInput: { diff --git a/LeftOvers/screens/HomePage.tsx b/LeftOvers/screens/HomePage.tsx index 7e1880b..bfc5298 100644 --- a/LeftOvers/screens/HomePage.tsx +++ b/LeftOvers/screens/HomePage.tsx @@ -12,7 +12,7 @@ import bracketLeft from '../assets/images/angle_bracket_left.png'; import bracketRight from '../assets/images/angle_bracket_right.png'; import AsyncStorage from '@react-native-async-storage/async-storage'; -import EventEmitter from './EventEmitter'; +import EventEmitter from './EventEmitter'; export default function HomePage({ navigation, props }) { const {colors} = useContext(ColorContext); @@ -199,8 +199,8 @@ export default function HomePage({ navigation, props }) { const nbActiveProfiles = () => { let cpt = 0 - profiles.forEach((val) => { - if(val.isActive == "flex"){ + profiles.forEach((profile) => { + if(profile.isActive == "flex"){ cpt += 1 } }) From 6e170687bc0a1dd0971666761ff7a172ea9ccf69 Mon Sep 17 00:00:00 2001 From: Louison PARANT Date: Tue, 5 Dec 2023 15:12:52 +0100 Subject: [PATCH 25/27] Merge Master --- LeftOvers/components/FoodElementText.tsx | 2 +- LeftOvers/components/ListSelect.tsx | 1 - LeftOvers/components/ProfileDetails.tsx | 2 +- LeftOvers/screens/CreateProfile.tsx | 1 + LeftOvers/screens/Profiles.tsx | 15 +++++---------- 5 files changed, 8 insertions(+), 13 deletions(-) diff --git a/LeftOvers/components/FoodElementText.tsx b/LeftOvers/components/FoodElementText.tsx index 5928ee2..abd64a1 100644 --- a/LeftOvers/components/FoodElementText.tsx +++ b/LeftOvers/components/FoodElementText.tsx @@ -14,7 +14,7 @@ const componentHeight = 60; const componentWidth = 280; -export default function FoodElementText(props : foodElementImageProps) { +export default function FoodElementText(props : FoodElementTextProps) { const colors = useContext(ColorContext).colors const styles = StyleSheet.create({ diff --git a/LeftOvers/components/ListSelect.tsx b/LeftOvers/components/ListSelect.tsx index 2f33ee7..5a2e9e2 100644 --- a/LeftOvers/components/ListSelect.tsx +++ b/LeftOvers/components/ListSelect.tsx @@ -11,7 +11,6 @@ type ListProps = { } export default function ListSelect(props: ListProps) { - const [selected, setSelected] = React.useState([]); const colors = useContext(ColorContext).colors; const styles = StyleSheet.create({ diff --git a/LeftOvers/components/ProfileDetails.tsx b/LeftOvers/components/ProfileDetails.tsx index 2bb2c0b..1ef9c9b 100644 --- a/LeftOvers/components/ProfileDetails.tsx +++ b/LeftOvers/components/ProfileDetails.tsx @@ -137,7 +137,7 @@ export default function ProfileDetails(props) { Filters - {props.diets.length} diets selected + {/*{props.diets.length} diets selected*/} diff --git a/LeftOvers/screens/CreateProfile.tsx b/LeftOvers/screens/CreateProfile.tsx index 5eb2769..76b4bc0 100644 --- a/LeftOvers/screens/CreateProfile.tsx +++ b/LeftOvers/screens/CreateProfile.tsx @@ -15,6 +15,7 @@ import AsyncStorage from '@react-native-async-storage/async-storage'; export default function CreateProfile(props) { const colors = useContext(ColorContext).colors const profile_service = new ProfileService() + const all = [] const die = [{value: "Dairy free"}, {value: "Gluten free"}, {value: "Porkless"}, {value: "Vegan"}, {value: "Vegetarian"}, {value: "Pescatarian"}] const [name, onChangeName] = useState(); const [avatar, setAvatar] = useState(''); diff --git a/LeftOvers/screens/Profiles.tsx b/LeftOvers/screens/Profiles.tsx index e26f939..132f318 100644 --- a/LeftOvers/screens/Profiles.tsx +++ b/LeftOvers/screens/Profiles.tsx @@ -14,10 +14,7 @@ import ProfileService from '../Services/Profiles/ProfileService'; export default function Profiles({navigation, props}) { const colors = useContext(ColorContext).colors const profile_service = new ProfileService() - - const all = [] - const die = [{value: "Dairy free"}, {value: "Gluten free"}, {value: "Porkless"}, {value: "Vegan"}, {value: "Vegetarian"}, {value: "Pescatarian"}] - + const [visible, setVisible] = useState(false); const [profiles, setProfiles] = useState([]); const [selectedProfileIndex, setSelectedProfileIndex] = useState(null); @@ -45,10 +42,10 @@ export default function Profiles({navigation, props}) { const handleGetProfiles = async () => { try { - const results = await profile_service.getProfiles() - return results + const existingProfiles = await AsyncStorage.getItem('profiles'); + return JSON.parse(existingProfiles) || []; } catch (error) { - console.log(error); + console.log("Error occured during GetProfiles", error); return []; } } @@ -70,7 +67,7 @@ export default function Profiles({navigation, props}) { height: "75%", width: "100%", }; - const styles = StyleSheet.create({ + const styles = StyleSheet.create({ container: { height: "100%", width: "100%", @@ -227,8 +224,6 @@ export default function Profiles({navigation, props}) { )); - - return ( From c627d3e475a171b82ec05031c43be10115ad8f8d Mon Sep 17 00:00:00 2001 From: Louison PARANT Date: Tue, 5 Dec 2023 15:20:05 +0100 Subject: [PATCH 26/27] Code Smells Fix --- LeftOvers/Services/Profiles/IProfileService.ts | 2 +- LeftOvers/Services/Profiles/ProfileService.ts | 2 +- LeftOvers/components/ProfileDetails.tsx | 1 - LeftOvers/components/ProfileSelection.tsx | 1 - LeftOvers/screens/CreateProfile.tsx | 4 +--- LeftOvers/screens/HomePage.tsx | 2 -- LeftOvers/screens/Profiles.tsx | 2 -- 7 files changed, 3 insertions(+), 11 deletions(-) diff --git a/LeftOvers/Services/Profiles/IProfileService.ts b/LeftOvers/Services/Profiles/IProfileService.ts index a3fdfe6..425a961 100644 --- a/LeftOvers/Services/Profiles/IProfileService.ts +++ b/LeftOvers/Services/Profiles/IProfileService.ts @@ -3,5 +3,5 @@ import Profil from "../../Models/Profil"; export default interface IProfileService { getProfiles(): Promise, addProfile(new_profile: Profil): Promise, - delProfile(profile_name_to_del: String): Promise + delProfile(profile_name_to_del: string): Promise } \ No newline at end of file diff --git a/LeftOvers/Services/Profiles/ProfileService.ts b/LeftOvers/Services/Profiles/ProfileService.ts index e013180..30646bf 100644 --- a/LeftOvers/Services/Profiles/ProfileService.ts +++ b/LeftOvers/Services/Profiles/ProfileService.ts @@ -25,7 +25,7 @@ export default class ProfileService implements IProfileService { return true } - async delProfile(profile_name_to_del: String): Promise { + async delProfile(profile_name_to_del: string): Promise { const existing_profiles = await this.getProfiles() let key: number = -1 for (let current_profile of existing_profiles) { diff --git a/LeftOvers/components/ProfileDetails.tsx b/LeftOvers/components/ProfileDetails.tsx index 1ef9c9b..f9dafb3 100644 --- a/LeftOvers/components/ProfileDetails.tsx +++ b/LeftOvers/components/ProfileDetails.tsx @@ -16,7 +16,6 @@ type ProfileProps = { export default function ProfileDetails(props) { const colors = useContext(ColorContext).colors - const navigation = useNavigation() const [display, setDisplay] = useState("none") const changeListVisibility = () => { if (display == "none"){ diff --git a/LeftOvers/components/ProfileSelection.tsx b/LeftOvers/components/ProfileSelection.tsx index f748365..daf409e 100644 --- a/LeftOvers/components/ProfileSelection.tsx +++ b/LeftOvers/components/ProfileSelection.tsx @@ -6,7 +6,6 @@ import ColorContext from '../theme/ColorContext'; import bracketLeft from '../assets/images/angle_bracket_left.png'; import bracketRight from '../assets/images/angle_bracket_right.png'; -import EventEmitter from '../screens/EventEmitter'; type ProfileSelectionProps = { listProfile: Profile[] diff --git a/LeftOvers/screens/CreateProfile.tsx b/LeftOvers/screens/CreateProfile.tsx index 76b4bc0..72a37c7 100644 --- a/LeftOvers/screens/CreateProfile.tsx +++ b/LeftOvers/screens/CreateProfile.tsx @@ -8,19 +8,17 @@ import ListWithoutSelect from '../components/ListWithoutSelect'; import ListSelect from '../components/ListSelect'; import EventEmitter from './EventEmitter'; import * as ImagePicker from 'expo-image-picker'; -import ProfileService from '../Services/Profiles/ProfileService'; import AsyncStorage from '@react-native-async-storage/async-storage'; export default function CreateProfile(props) { const colors = useContext(ColorContext).colors - const profile_service = new ProfileService() const all = [] const die = [{value: "Dairy free"}, {value: "Gluten free"}, {value: "Porkless"}, {value: "Vegan"}, {value: "Vegetarian"}, {value: "Pescatarian"}] const [name, onChangeName] = useState(); const [avatar, setAvatar] = useState(''); const [selectedDiets, setSelectedDiets] = useState([]); - const [selectedAllergies, setSelectedAllergies] = useState([]) + const [selectedAllergies] = useState([]) const handleSelectedDiets = (selectedValues) => { setSelectedDiets(selectedValues); diff --git a/LeftOvers/screens/HomePage.tsx b/LeftOvers/screens/HomePage.tsx index 0206991..622330a 100644 --- a/LeftOvers/screens/HomePage.tsx +++ b/LeftOvers/screens/HomePage.tsx @@ -8,7 +8,6 @@ import ProfileSelection from '../components/ProfileSelection'; import FoodElementText from '../components/FoodElementText'; import ColorContext from '../theme/ColorContext'; import ProfileService from '../Services/Profiles/ProfileService'; -import Profil from '../Models/Profil'; import bracketLeft from '../assets/images/angle_bracket_left.png'; import bracketRight from '../assets/images/angle_bracket_right.png'; @@ -18,7 +17,6 @@ import EventEmitter from './EventEmitter'; export default function HomePage({ navigation, props }) { const colors = useContext(ColorContext).colors - const profile_service = new ProfileService() const profilesHand = [ {name: "None", avatar: "logo.png", isActive: "none"} diff --git a/LeftOvers/screens/Profiles.tsx b/LeftOvers/screens/Profiles.tsx index 132f318..4a18bb7 100644 --- a/LeftOvers/screens/Profiles.tsx +++ b/LeftOvers/screens/Profiles.tsx @@ -9,11 +9,9 @@ import ColorContext from '../theme/ColorContext'; import AsyncStorage from '@react-native-async-storage/async-storage'; import EventEmitter from './EventEmitter'; import { PaperProvider, Portal } from 'react-native-paper'; -import ProfileService from '../Services/Profiles/ProfileService'; export default function Profiles({navigation, props}) { const colors = useContext(ColorContext).colors - const profile_service = new ProfileService() const [visible, setVisible] = useState(false); const [profiles, setProfiles] = useState([]); From e9c82072c2b8d4519701c654197aa193846f57bb Mon Sep 17 00:00:00 2001 From: Louison PARANT Date: Tue, 5 Dec 2023 15:24:47 +0100 Subject: [PATCH 27/27] Code Smells Fix --- LeftOvers/components/ProfileDetails.tsx | 1 - LeftOvers/screens/HomePage.tsx | 1 - 2 files changed, 2 deletions(-) diff --git a/LeftOvers/components/ProfileDetails.tsx b/LeftOvers/components/ProfileDetails.tsx index f9dafb3..750c48c 100644 --- a/LeftOvers/components/ProfileDetails.tsx +++ b/LeftOvers/components/ProfileDetails.tsx @@ -1,6 +1,5 @@ import React, { useContext, useState } from 'react'; import { StyleSheet, Text, View, Image, Pressable } from 'react-native'; -import { useNavigation } from '@react-navigation/native'; import ListWithoutSelect from './ListWithoutSelect'; import ColorContext from '../theme/ColorContext'; diff --git a/LeftOvers/screens/HomePage.tsx b/LeftOvers/screens/HomePage.tsx index 622330a..697dd82 100644 --- a/LeftOvers/screens/HomePage.tsx +++ b/LeftOvers/screens/HomePage.tsx @@ -7,7 +7,6 @@ import ValidateButton from '../components/ValidateButton'; import ProfileSelection from '../components/ProfileSelection'; import FoodElementText from '../components/FoodElementText'; import ColorContext from '../theme/ColorContext'; -import ProfileService from '../Services/Profiles/ProfileService'; import bracketLeft from '../assets/images/angle_bracket_left.png'; import bracketRight from '../assets/images/angle_bracket_right.png';