@ -1,4 +1,4 @@
import React , { useContext , use Effect, useState } from 'react' ;
import React , { useContext , use State, useEffect } 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' ;
@ -13,33 +13,51 @@ import Profil from '../Models/Profil';
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' ;
export default function HomePage ( { navigation , props } ) {
const colors = useContext ( ColorContext ) . colors
const profile_service = new ProfileService ( )
const profiles = [
const profiles Hand = [
{ 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" } ,
]
const [ existingProfiles , setExistingProfiles ] : [ Profil [ ] , React . Dispatch < Profil [ ] > ] = 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"})
// }
const [ profiles , setProfiles ] = useState ( [ { name : "None" , avatar : "plus_small.png" , isActive : "none" } ] ) ;
console . log ( profiles , profiles . length )
const handleGetProfiles = async ( ) = > {
try {
const existingProfiles = await AsyncStorage . getItem ( 'profiles' ) ;
return JSON . parse ( existingProfiles ) || [ ] ;
} catch ( error ) {
console . log ( error ) ;
return [ ] ;
}
}
useEffect ( ( ) = > {
loadProfiles ( )
} , [ ] )
const fetchProfiles = async ( ) = > {
const existingProfiles = await handleGetProfiles ( ) ;
setProfiles ( existingProfiles ) ;
} ;
const subscription = EventEmitter . addListener ( 'profileAdded' , async ( ) = > {
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" } ]
@ -197,9 +215,9 @@ export default function HomePage({ navigation, props }) {
< / View >
< / View >
< View style = { { marginTop : "4%" } } / >
< ValidateButton title = "Change Selected Ingredients" image = "cook.png" colour = { colors . buttonDetail } backColour = { colors . buttonBackground } todo = { ( ) = > navigation . navigate ( 'IngredientSelection ') } / >
< ValidateButton title = "Change Selected Ingredients" image = "cook.png" colour = { colors . buttonDetail } backColour = { colors . buttonBackground } todo = { ( ) = > console . log ( 'Chnge Selected Ingredient ') } / >
< View style = { { marginTop : "3%" } } / >
< ValidateButton title = "Search Recipes" image = "search.png" colour = { colors . buttonDetail } backColour = { colors . buttonBackground } todo = { ( ) = > navigation . navigate ( 'RecipeSuggestion ') } / >
< ValidateButton title = "Search Recipes" image = "search.png" colour = { colors . buttonDetail } backColour = { colors . buttonBackground } todo = { ( ) = > console . log ( 'Go and search for recipe ') } / >
< / View >
< View style = { { marginBottom : "20%" } } / >
< / LinearGradient >