pull/23/head
Louison PARANT 1 year ago
commit 5802f0038f

@ -12,7 +12,8 @@ steps:
commands: commands:
- cd ./LeftOvers/ - cd ./LeftOvers/
- npm install - npm install
- npm run - 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 - name: code-analysis
image: node:latest image: node:latest

@ -0,0 +1,7 @@
import Profil from "../../Models/Profil";
export default interface IProfileService {
getProfiles(): Promise<Profil[]>,
addProfile(new_profile: Profil): Promise<boolean>,
delProfile(profile_name_to_del: String): Promise<boolean>
}

@ -0,0 +1,41 @@
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<Profil[]> {
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<boolean> {
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
}
async delProfile(profile_name_to_del: String): Promise<boolean> {
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
}
}

@ -14,8 +14,8 @@ const componentHeight = 60;
const componentWidth = 280; const componentWidth = 280;
export default function FoodElementText(props : any) { export default function FoodElementText(props : foodElementImageProps) {
const {colors} = useContext(ColorContext) const colors = useContext(ColorContext).colors
const styles = StyleSheet.create({ const styles = StyleSheet.create({
button: { button: {

@ -1,6 +1,6 @@
import React, { useContext } from 'react'; import React, { useContext } from 'react';
import {StyleSheet, Image} from 'react-native'; import { StyleSheet, Image } from 'react-native';
import {MultipleSelectList} from 'react-native-dropdown-select-list' import { MultipleSelectList } from 'react-native-dropdown-select-list'
import ColorContext from '../theme/ColorContext'; import ColorContext from '../theme/ColorContext';
type ListProps = { type ListProps = {
@ -11,8 +11,8 @@ type ListProps = {
} }
export default function ListSelect(props: ListProps) { export default function ListSelect(props: ListProps) {
const [selected, setSelected] = React.useState([]);
const {colors} = useContext(ColorContext); const colors = useContext(ColorContext).colors;
const styles = StyleSheet.create({ const styles = StyleSheet.create({
titleBar: { titleBar: {

@ -1,6 +1,6 @@
import React, { useContext } from 'react'; import React, { useContext } from 'react';
import {StyleSheet, Image} from 'react-native'; import { StyleSheet, Image } from 'react-native';
import {MultipleSelectList} from 'react-native-dropdown-select-list' import { MultipleSelectList } from 'react-native-dropdown-select-list'
import ColorContext from '../theme/ColorContext'; import ColorContext from '../theme/ColorContext';
type ListProps = { type ListProps = {
@ -10,8 +10,7 @@ type ListProps = {
export default function ListWithoutSelect(props: ListProps) { export default function ListWithoutSelect(props: ListProps) {
const [selected, setSelected] = React.useState([]); const [selected, setSelected] = React.useState([]);
const { colors } = useContext(ColorContext); const colors = useContext(ColorContext).colors;
const styles = StyleSheet.create({ const styles = StyleSheet.create({
titleBar: { titleBar: {

@ -1,5 +1,6 @@
import React, { useContext, useState } from 'react'; import React, { useContext, useState } from 'react';
import { StyleSheet, Text, View, Image, Pressable } from 'react-native'; import { StyleSheet, Text, View, Image, Pressable } from 'react-native';
import { useNavigation } from '@react-navigation/native';
import ListWithoutSelect from './ListWithoutSelect'; import ListWithoutSelect from './ListWithoutSelect';
import ColorContext from '../theme/ColorContext'; import ColorContext from '../theme/ColorContext';
@ -14,7 +15,8 @@ type ProfileProps = {
} }
export default function ProfileDetails(props) { export default function ProfileDetails(props) {
const { colors } = useContext(ColorContext) const colors = useContext(ColorContext).colors
const navigation = useNavigation()
const [display, setDisplay] = useState("none") const [display, setDisplay] = useState("none")
const changeListVisibility = () => { const changeListVisibility = () => {
if (display == "none"){ if (display == "none"){

@ -10,7 +10,7 @@ type Profile = {
} }
export default function ProfileElement(props : Profile) { export default function ProfileElement(props : Profile) {
const { colors } = useContext(ColorContext) const colors = useContext(ColorContext).colors
const [waiting, setWaiting] = useState("none") const [waiting, setWaiting] = useState("none")
const [separator, setSeparator] = useState("none") const [separator, setSeparator] = useState("none")

@ -15,7 +15,7 @@ type ProfileProps = {
export default function ProfileModification(props: ProfileProps) { export default function ProfileModification(props: ProfileProps) {
const [name, onChangeName] = useState(props.name); const [name, onChangeName] = useState(props.name);
const { colors } = useContext(ColorContext); const colors = useContext(ColorContext).colors;
let imageSource let imageSource
if (props.avatar == "plus.png"){ if (props.avatar == "plus.png"){

@ -20,7 +20,7 @@ type Profile = {
} }
export default function ProfileSelection(props: ProfileSelectionProps) { export default function ProfileSelection(props: ProfileSelectionProps) {
const { colors } = useContext(ColorContext); const colors = useContext(ColorContext).colors;
const [cpt, setCpt] = useState(0); const [cpt, setCpt] = useState(0);
const decreaseCounter = () => { const decreaseCounter = () => {

@ -15,7 +15,7 @@ import DarkIcon from '../assets/images/moon.png';
export default function BottomBar({ state, descriptors, navigation }) { export default function BottomBar({ state, descriptors, navigation }) {
const {theme, toggleTheme} = useContext(ThemeContext); const {theme, toggleTheme} = useContext(ThemeContext);
const {colors, toggleColors} = useContext(ColorContext) const { colors, toggleColors } = useContext(ColorContext);
const [iconThemeButton, setThemeIconButton] = useState(( theme === 'dark' ) ? LightIcon : DarkIcon) const [iconThemeButton, setThemeIconButton] = useState(( theme === 'dark' ) ? LightIcon : DarkIcon)
const [textThemeButton, setTextThemeButton] = useState(( theme === 'dark' ) ? 'Light' : 'Dark'); const [textThemeButton, setTextThemeButton] = useState(( theme === 'dark' ) ? 'Light' : 'Dark');
@ -47,10 +47,10 @@ export default function BottomBar({ state, descriptors, navigation }) {
flexDirection: 'row', flexDirection: 'row',
alignItems: 'center', alignItems: 'center',
alignContent: 'space-around', alignContent: 'space-around',
borderBlockColor: theme === 'light' ? '#F2F0E4' : '#222222', borderBlockColor: colors.blocBorder,
borderWidth: 2, borderWidth: 2,
borderLeftColor: theme === 'light'? '#F2F0E4' : '#222222', borderLeftColor: colors.blocBorder,
borderRightColor: theme === 'light'? '#F2F0E4' : '#222222', borderRightColor: colors.blocBorder,
}, },
BottomBarIcon: { BottomBarIcon: {
width: 25, width: 25,

@ -1,5 +1,4 @@
import React, { useContext } from 'react' import React, { useContext } from 'react'
import { StyleSheet } from 'react-native'
import { createNativeStackNavigator } from '@react-navigation/native-stack'; import { createNativeStackNavigator } from '@react-navigation/native-stack';
import IngredientSelection from '../screens/IngredientSelection'; import IngredientSelection from '../screens/IngredientSelection';
@ -11,7 +10,7 @@ import RecipeDetails from '../screens/RecipeDetails';
const CookingStack = createNativeStackNavigator() const CookingStack = createNativeStackNavigator()
export default function CookingStackScreen() { export default function CookingStackScreen() {
const {theme} = useContext(ThemeContext); const theme = useContext(ThemeContext).theme;
return ( return (
<CookingStack.Navigator> <CookingStack.Navigator>
@ -47,10 +46,4 @@ export default function CookingStackScreen() {
/> />
</CookingStack.Navigator> </CookingStack.Navigator>
) )
} }
const styles = StyleSheet.create({
headerBarContainer: {
backgroundColor: '#F2F0E4',
},
})

@ -25,7 +25,7 @@ function AppIcon() {
} }
export default function HomeStackScreen() { export default function HomeStackScreen() {
const {colors} = useContext(ColorContext) const colors = useContext(ColorContext).colors
return ( return (
<HomeStack.Navigator> <HomeStack.Navigator>

@ -5,7 +5,7 @@ import { createNativeStackNavigator } from '@react-navigation/native-stack';
import Profiles from '../screens/Profiles'; import Profiles from '../screens/Profiles';
import CreateProfile from '../screens/CreateProfile'; import CreateProfile from '../screens/CreateProfile';
import ModifyProfile from '../screens/ModifyProfile'; import ModifyProfile from '../screens/ModifyProfile';
import ThemeContext from '../theme/ThemeContext'; import ColorContext from '../theme/ColorContext';
import { HeaderTitle } from './Utils'; import { HeaderTitle } from './Utils';
@ -15,11 +15,11 @@ import AddIcon from '../assets/images/plus.png'
const ProfilesStack = createNativeStackNavigator() const ProfilesStack = createNativeStackNavigator()
export default function ProfilesStackScreen({ navigation }) { export default function ProfilesStackScreen({ navigation }) {
const {theme} = useContext(ThemeContext); const colors = useContext(ColorContext).colors;
const styles = StyleSheet.create({ const styles = StyleSheet.create({
headerBarContainer: { headerBarContainer: {
backgroundColor: theme === 'light' ? '#F2F0E4' : '#3F3C42', backgroundColor: colors.cardBackground,
}, },
headerBarRightContainer: { headerBarRightContainer: {
display: 'flex', display: 'flex',
@ -55,13 +55,13 @@ export default function ProfilesStackScreen({ navigation }) {
<Image <Image
source={SearchIcon} source={SearchIcon}
style={styles.headerBarIcon} style={styles.headerBarIcon}
tintColor={theme === 'light' ? '#3F3C42' : '#F2F0E4'}/> tintColor={colors.cardDetail}/>
</Pressable> </Pressable>
<Pressable onPress={_handleHeaderAdd}> <Pressable onPress={_handleHeaderAdd}>
<Image <Image
source={AddIcon} source={AddIcon}
style={styles.headerBarIcon} style={styles.headerBarIcon}
tintColor={theme === 'light' ? '#3F3C42' : '#F2F0E4'}/> tintColor={colors.cardDetail}/>
</Pressable> </Pressable>
</View> </View>
) )

@ -4,7 +4,7 @@ import { Text, StyleSheet } from 'react-native';
import ColorContext from '../theme/ColorContext'; import ColorContext from '../theme/ColorContext';
export function HeaderTitle(props) { export function HeaderTitle(props) {
const {colors} = useContext(ColorContext) const colors = useContext(ColorContext).colors
const styles = StyleSheet.create({ const styles = StyleSheet.create({
headerTitle: { headerTitle: {

@ -6,18 +6,20 @@ import ValidateButton from '../components/ValidateButton';
import ColorContext from '../theme/ColorContext'; import ColorContext from '../theme/ColorContext';
import ListWithoutSelect from '../components/ListWithoutSelect'; import ListWithoutSelect from '../components/ListWithoutSelect';
import ListSelect from '../components/ListSelect'; import ListSelect from '../components/ListSelect';
import AsyncStorage from '@react-native-async-storage/async-storage';
import EventEmitter from './EventEmitter'; import EventEmitter from './EventEmitter';
import * as ImagePicker from 'expo-image-picker'; 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) { export default function CreateProfile(props) {
const { colors } = useContext(ColorContext) 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 die = [{value: "Dairy free"}, {value: "Gluten free"}, {value: "Porkless"}, {value: "Vegan"}, {value: "Vegetarian"}, {value: "Pescatarian"}]
const [name, onChangeName] = useState(); const [name, onChangeName] = useState();
const [avatar, setAvatar] = useState<string>(''); const [avatar, setAvatar] = useState<string>('');
const [selectedDiets, setSelectedDiets] = useState([]); const [selectedDiets, setSelectedDiets] = useState([]);
const [selectedAllergies, setSelectedAllergies] = useState([])
const handleSelectedDiets = (selectedValues) => { const handleSelectedDiets = (selectedValues) => {
setSelectedDiets(selectedValues); setSelectedDiets(selectedValues);
@ -26,16 +28,16 @@ export default function CreateProfile(props) {
const pickImage = async () => { const pickImage = async () => {
// No permissions request is necessary for launching the image library // No permissions request is necessary for launching the image library
let result = await ImagePicker.launchImageLibraryAsync({ let result = await ImagePicker.launchImageLibraryAsync({
mediaTypes: ImagePicker.MediaTypeOptions.All, mediaTypes: ImagePicker.MediaTypeOptions.All,
allowsEditing: true, allowsEditing: true,
aspect: [4, 3], aspect: [4, 3],
quality: 1, quality: 1,
}); });
console.log(result); console.log(result);
if (!result.canceled) { if (!result.canceled) {
setAvatar(result.assets[0].uri); setAvatar(result.assets[0].uri);
} }
}; };
@ -68,7 +70,7 @@ export default function CreateProfile(props) {
console.log('Profil créé :', newProfile); console.log('Profil créé :', newProfile);
props.navigation.goBack(); props.navigation.goBack();
} catch (error) { } catch (error) {
console.error('Erreur lors de la création du profil :', error); console.error('Erreur lors de la création du profil :', error);
} }
}; };
@ -167,7 +169,7 @@ export default function CreateProfile(props) {
</View> </View>
<ListSelect title="Diets" content={die} setSelected={handleSelectedDiets}></ListSelect> <ListSelect title="Diets" content={die} setSelected={handleSelectedDiets}></ListSelect>
<View style={{marginTop: "6%"}}/> <View style={{marginTop: "6%"}}/>
<ListWithoutSelect title="Allergies" content={all}></ListWithoutSelect> <ListWithoutSelect title="Allergies" content={selectedAllergies}></ListWithoutSelect>
<View style={{marginTop: "3%"}}/> <View style={{marginTop: "3%"}}/>
</View> </View>
<View style={{marginTop: "3%"}}/> <View style={{marginTop: "3%"}}/>

@ -7,6 +7,8 @@ import ValidateButton from '../components/ValidateButton';
import ProfileSelection from '../components/ProfileSelection'; import ProfileSelection from '../components/ProfileSelection';
import FoodElementText from '../components/FoodElementText'; import FoodElementText from '../components/FoodElementText';
import ColorContext from '../theme/ColorContext'; 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 bracketLeft from '../assets/images/angle_bracket_left.png';
import bracketRight from '../assets/images/angle_bracket_right.png'; import bracketRight from '../assets/images/angle_bracket_right.png';
@ -15,7 +17,8 @@ import AsyncStorage from '@react-native-async-storage/async-storage';
import EventEmitter from './EventEmitter'; import EventEmitter from './EventEmitter';
export default function HomePage({ navigation, props }) { export default function HomePage({ navigation, props }) {
const {colors} = useContext(ColorContext); const colors = useContext(ColorContext).colors
const profile_service = new ProfileService()
const profilesHand = [ const profilesHand = [
{name: "None", avatar: "logo.png", isActive: "none"} {name: "None", avatar: "logo.png", isActive: "none"}

@ -2,24 +2,27 @@ import React, { useEffect, useState, useContext } from 'react';
import { View, StyleSheet, Text, Image, Pressable, ActivityIndicator, FlatList, useWindowDimensions } from 'react-native'; import { View, StyleSheet, Text, Image, Pressable, ActivityIndicator, FlatList, useWindowDimensions } from 'react-native';
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 { LinearGradient } from 'expo-linear-gradient';
import FoodElementText from '../components/FoodElementText'; import FoodElementText from '../components/FoodElementText';
import plus from '../assets/images/plus.png';
import moins from '../assets/images/minus.png';
import Ingredient from '../Models/Ingredient'; import Ingredient from '../Models/Ingredient';
import IngredientService from '../Services/Ingredients/IngredientsServices'; import IngredientService from '../Services/Ingredients/IngredientsServices';
import { LinearGradient } from 'expo-linear-gradient';
import ColorContext from '../theme/ColorContext'; import ColorContext from '../theme/ColorContext';
import ValidateButton from '../components/ValidateButton'; import ValidateButton from '../components/ValidateButton';
import AsyncStorage from '@react-native-async-storage/async-storage'; import AsyncStorage from '@react-native-async-storage/async-storage';
import EventEmitter from './EventEmitter'; import EventEmitter from './EventEmitter';
import plus from '../assets/images/plus.png';
import moins from '../assets/images/minus.png';
export default function IngredientSelection(props) { export default function IngredientSelection(props) {
const colors = useContext(ColorContext).colors
const alphabetArray: Array<string> = ["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 alphabetArray: Array<string> = ["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 [isLoading, setIsLoading] = useState(true);
const [response, setResponse] = useState<Ingredient[] | undefined>(undefined); const [response, setResponse] = useState<Ingredient[] | undefined>(undefined);
const [selectedIngredients, setSelectedIngredients] = useState([]); const [selectedIngredients, setSelectedIngredients] = useState([]);
const ingredientService = new IngredientService(); const ingredientService = new IngredientService();
const {colors} = useContext(ColorContext);
const [availableSize, setAvailableSize] = useState(0); const [availableSize, setAvailableSize] = useState(0);
const [listVisibility, setListVisibility] = useState("flex"); const [listVisibility, setListVisibility] = useState("flex");
const [availableVisibility, setAvailableVisibility] = useState("none"); const [availableVisibility, setAvailableVisibility] = useState("none");

@ -9,9 +9,15 @@ import ColorContext from '../theme/ColorContext';
import AsyncStorage from '@react-native-async-storage/async-storage'; import AsyncStorage from '@react-native-async-storage/async-storage';
import EventEmitter from './EventEmitter'; import EventEmitter from './EventEmitter';
import { PaperProvider, Portal } from 'react-native-paper'; import { PaperProvider, Portal } from 'react-native-paper';
import ProfileService from '../Services/Profiles/ProfileService';
export default function Profiles({navigation, props}) { export default function Profiles({navigation, props}) {
const { colors } = useContext(ColorContext) 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 [visible, setVisible] = useState(false);
const [profiles, setProfiles] = useState([]); const [profiles, setProfiles] = useState([]);
const [selectedProfileIndex, setSelectedProfileIndex] = useState(null); const [selectedProfileIndex, setSelectedProfileIndex] = useState(null);
@ -37,10 +43,10 @@ export default function Profiles({navigation, props}) {
} }
}; };
const handleGetProfiles = async () => { const handleGetProfiles = async () => {
try { try {
const existingProfiles = await AsyncStorage.getItem('profiles'); const results = await profile_service.getProfiles()
return JSON.parse(existingProfiles) || []; return results
} catch (error) { } catch (error) {
console.log(error); console.log(error);
return []; return [];
@ -63,9 +69,7 @@ export default function Profiles({navigation, props}) {
const containerStyle = { const containerStyle = {
height: "75%", height: "75%",
width: "100%", width: "100%",
}; };
const styles = StyleSheet.create({ const styles = StyleSheet.create({
container: { container: {
height: "100%", height: "100%",

Loading…
Cancel
Save