Skip to content

Commit dc1008e

Browse files
authored
Merge pull request #23 from CodingFactory-Repos/feature/plate
Feature/plate
2 parents 8bbf11e + c13efa7 commit dc1008e

File tree

13 files changed

+1785
-1411
lines changed

13 files changed

+1785
-1411
lines changed

src/App.tsx

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,11 @@ import {
55
} from '@react-navigation/native';
66

77
import {useCameraPermission} from 'react-native-vision-camera';
8-
import AsyncStorage from '@react-native-async-storage/async-storage';
9-
import {logger} from 'react-native-logs';
108
import {Provider} from 'react-redux';
119
import store from './service/redux/store.ts';
1210
import RootNavigator from './components/navigators/RootNavigator/RootNavigator.tsx';
1311
import {GestureHandlerRootView} from 'react-native-gesture-handler';
1412

15-
const log = logger.createLogger();
16-
1713
const App = () => {
1814
const {hasPermission, requestPermission} = useCameraPermission();
1915
const routeNameRef = useRef<string>();
@@ -33,17 +29,6 @@ const App = () => {
3329
navigationRef.current?.getCurrentRoute?.()?.name ?? 'UNKNOWN';
3430
};
3531

36-
useEffect(() => {
37-
AsyncStorage.getItem('user').then(user => {
38-
if (user) {
39-
log.info('user token', {user});
40-
} else {
41-
// navigator.push('Account');
42-
log.info('user token not found');
43-
}
44-
});
45-
}, []);
46-
4732
return (
4833
<GestureHandlerRootView style={{flex: 1}}>
4934
<Provider store={store}>

src/components/navigators/RootNavigator/RootNavigator.tsx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
import AsyncStorage from '@react-native-async-storage/async-storage';
1111
import AuthStackNavigator from '../AuthNavigator/AuthStackNavigator.tsx';
1212
import {login} from '../../../service/redux/slices/userSlice.ts';
13+
import {setProductList} from '../../../service/redux/slices/productSlice.ts';
1314

1415
const RootStack = createNativeStackNavigator<RootNavigatorInterfaces>();
1516

@@ -27,7 +28,15 @@ const RootNavigator = () => {
2728
dispatch(login({email: user}));
2829
}
2930
});
30-
}, [isLogged, setIsLogged]);
31+
if (isLogged) {
32+
AsyncStorage.getItem('productList').then(productList => {
33+
if (productList) {
34+
// console.log('productList', productList);
35+
dispatch(setProductList(JSON.parse(productList)));
36+
}
37+
});
38+
}
39+
}, [dispatch, isLogged, setIsLogged]);
3140

3241
useEffect(() => {
3342
if (isAuth) {

src/screens/carrot/CarrotScreen.tsx

Lines changed: 16 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,13 @@
11
import React, {useCallback, useEffect, useRef, useState} from 'react';
2-
import {
3-
FlatList,
4-
SafeAreaView,
5-
Text,
6-
TouchableOpacity,
7-
View,
8-
} from 'react-native';
9-
import {useSelector, useDispatch} from 'react-redux';
2+
import {FlatList, SafeAreaView, TouchableOpacity} from 'react-native';
3+
import {useSelector} from 'react-redux';
104

115
import ProductItem from './components/productItem/ProductItem.tsx';
126
import {styles} from './CarrotScreen.styles.ts';
137
import BottomSheet, {BottomSheetView} from '@gorhom/bottom-sheet';
148
import NutritionInfo from './components/NutritionInfo.tsx';
15-
import {setProduct} from '../../service/redux/slices/productSlice.ts';
169

1710
const CarrotScreen = () => {
18-
const dispatch = useDispatch();
1911
const {productList} = useSelector(state => state.product);
2012
const [isBottomSheetModalVisible, setBottomSheetModalVisible] =
2113
useState(false);
@@ -35,70 +27,27 @@ const CarrotScreen = () => {
3527

3628
useEffect(() => {
3729
console.log('product', productList);
38-
}, [productList]);
39-
40-
const fakeProductList = [
41-
{
42-
name: 'Carotte',
43-
categories: ['Légume', 'Bio'],
44-
nutriments: {
45-
carbohydrates: 54,
46-
proteins: 7,
47-
fat: 30,
48-
sugars: 100,
49-
salt: 0.2,
50-
},
51-
image_front_small_url:
52-
'https://static.openfoodfacts.org/images/products/327/655/000/5003/front_fr.3.200.jpg',
53-
nutriscore_score: 3,
54-
nutriscore_grade: 'c',
55-
},
56-
{
57-
name: 'Carotte',
58-
categories: ['Légume', 'Bio'],
59-
nutriments: {
60-
carbohydrates: 54,
61-
proteins: 7,
62-
fat: 30,
63-
sugars: 100,
64-
salt: 0.2,
65-
},
66-
image_front_small_url:
67-
'https://static.openfoodfacts.org/images/products/327/655/000/5003/front_fr.3.200.jpg',
68-
nutriscore_score: 3,
69-
nutriscore_grade: 'c',
70-
},
71-
{
72-
name: 'Carotte',
73-
categories: ['Légume', 'Bio'],
74-
nutriments: {
75-
carbohydrates: 54,
76-
proteins: 7,
77-
fat: 30,
78-
sugars: 100,
79-
salt: 0.2,
80-
},
81-
image_front_small_url:
82-
'https://static.openfoodfacts.org/images/products/327/655/000/5003/front_fr.3.200.jpg',
83-
nutriscore_score: 3,
84-
nutriscore_grade: 'c',
85-
},
86-
];
30+
}, [productList, selectedProduct]);
8731

8832
const renderList = product => {
8933
return (
9034
<TouchableOpacity onPress={() => handlePress(product)}>
9135
<ProductItem
9236
title={product.item.name ?? product.name}
93-
subtitle="Blablatest"
94-
badgeText="4/100 Mauvais"
95-
defects={['Additifs', 'Sucre']}
37+
subtitle={product.categories}
38+
badgeText={product.nutriscore_score}
39+
defects={
40+
product.item.negative_nutrients ?? product.negative_nutrients
41+
}
9642
categories={product.item.categories ?? product.categories}
43+
ingredients_text={
44+
product.item.ingredients_text ?? product.ingredients_text
45+
}
9746
nutriments={product.item.nutriments ?? product.nutriments}
98-
qualities={['Protéines', 'Fibres', 'Graisses saturées']}
99-
image_front_small_url={
100-
product.item.image_front_small_url ?? product.image_front_small_url
47+
qualities={
48+
product.item.positive_nutrients ?? product.positive_nutrients
10149
}
50+
image={product.item.image ?? product.image}
10251
nutriscore_score={
10352
product.item.nutriscore_score ?? product.nutriscore_score
10453
}
@@ -112,29 +61,18 @@ const CarrotScreen = () => {
11261

11362
return (
11463
<SafeAreaView style={styles.screen}>
115-
{(productList && productList[0] && (
64+
{productList && productList[0] && (
11665
<FlatList
11766
data={productList}
11867
renderItem={renderList}
11968
keyExtractor={(item, index) => index.toString()}
12069
/>
121-
)) ?? (
122-
<FlatList
123-
data={fakeProductList}
124-
renderItem={renderList}
125-
keyExtractor={(item, index) => index.toString()}
126-
/>
12770
)}
128-
<View style={styles.buttonContainer}>
129-
<TouchableOpacity style={styles.button} onPress={() => handlePress()}>
130-
<Text style={styles.buttonText}>Détails</Text>
131-
</TouchableOpacity>
132-
</View>
13371
{isBottomSheetModalVisible && (
13472
<BottomSheet
13573
ref={bottomSheetRef}
13674
onChange={handleSheetChanges}
137-
snapPoints={['50%']}
75+
snapPoints={['50%', '80%']}
13876
enablePanDownToClose={true}
13977
style={styles.bottomModal}>
14078
<BottomSheetView>

src/screens/carrot/components/NutritionInfo.tsx

Lines changed: 71 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,100 @@
11
import React from 'react';
2-
import {View, Text, StyleSheet} from 'react-native';
2+
import {Image, StyleSheet, Text, View} from 'react-native';
33

44
const NutritionInfo = ({data}) => {
5+
console.log('data', data);
56
const {
67
name,
78
ingredients_text,
89
nutriments,
9-
ecoscore_score,
10+
nutriscore_score,
1011
nutriscore_grade,
1112
item,
13+
image,
1214
} = data;
1315

1416
return (
15-
<View style={styles.container}>
16-
<Text style={styles.title}>{name || item.name}</Text>
17-
<Text style={styles.subtitle}>
18-
Ingrédients: {ingredients_text || item.ingredients_text}
19-
</Text>
20-
<View style={styles.section}>
21-
<Text style={styles.sectionTitle}>Informations Nutritionnelles:</Text>
22-
<Text>
23-
Carbohydrates:{' '}
24-
{nutriments?.carbohydrates || item?.nutriments?.carbohydrates}g
25-
</Text>
26-
<Text>
27-
Protéines: {nutriments?.proteins || item?.nutriments?.proteins}g
28-
</Text>
29-
<Text>Graisses: {nutriments?.fat || item?.nutriments?.fat}g</Text>
30-
<Text>Sucres: {nutriments?.sugars || item?.nutriments?.sugars}g</Text>
31-
<Text>Sel: {nutriments?.salt || item?.nutriments?.salt}g</Text>
32-
</View>
33-
<View style={styles.section}>
34-
<Text style={styles.sectionTitle}>Scores:</Text>
35-
<Text>Eco-Score: {ecoscore_score || item.ecoscore_score}</Text>
36-
<Text>Nutri-Score: {nutriscore_grade || item.nutriscore_grade}</Text>
37-
</View>
38-
</View>
17+
<>
18+
{item ? (
19+
<View style={styles.container}>
20+
<View style={styles.upperPartContainer}>
21+
<Image style={styles.image} source={{uri: item.image}} />
22+
<Text style={styles.title}>{item.name}</Text>
23+
</View>
24+
<View style={styles.subtitle}>
25+
<Text style={{fontWeight: 'bold'}}>Ingrédients:</Text>
26+
<Text>{item.ingredients_text}</Text>
27+
</View>
28+
<View style={styles.section}>
29+
<Text style={styles.sectionTitle}>
30+
Informations Nutritionnelles:
31+
</Text>
32+
<Text>Carbohydrates: {item.nutriments?.carbohydrates}g</Text>
33+
<Text>Protéines: {item.nutriments?.proteins}g</Text>
34+
<Text>Graisses: {item.nutriments?.fat}g</Text>
35+
<Text>Sucres: {item.nutriments?.sugars}g</Text>
36+
<Text>Sel: {item.nutriments?.salt}g</Text>
37+
</View>
38+
<View style={styles.section}>
39+
<Text style={styles.sectionTitle}>Scores:</Text>
40+
<Text>Eco-Score: {item.nutriscore_score} / 100</Text>
41+
<Text>Nutri-Score: {item.nutriscore_grade}</Text>
42+
</View>
43+
</View>
44+
) : (
45+
<View style={styles.container}>
46+
<View style={styles.upperPartContainer}>
47+
<Image style={styles.image} source={{uri: image}} />
48+
<Text style={styles.title}>{name}</Text>
49+
</View>
50+
<View style={styles.subtitle}>
51+
<Text style={{fontWeight: 'bold'}}>Ingrédients:</Text>
52+
<Text>{ingredients_text}</Text>
53+
</View>
54+
<View style={styles.section}>
55+
<Text style={styles.sectionTitle}>
56+
Informations Nutritionnelles:
57+
</Text>
58+
<Text>Carbohydrates: {nutriments?.carbohydrates}g</Text>
59+
<Text>Protéines: {nutriments?.proteins}g</Text>
60+
<Text>Graisses: {nutriments?.fat}g</Text>
61+
<Text>Sucres: {nutriments?.sugars}g</Text>
62+
<Text>Sel: {nutriments?.salt}g</Text>
63+
</View>
64+
<View style={styles.section}>
65+
<Text style={styles.sectionTitle}>Scores:</Text>
66+
<Text>Eco-Score: {nutriscore_score} / 100</Text>
67+
<Text>Nutri-Score: {nutriscore_grade}</Text>
68+
</View>
69+
</View>
70+
)}
71+
</>
3972
);
4073
};
4174

4275
const styles = StyleSheet.create({
76+
upperPartContainer: {
77+
flexDirection: 'row',
78+
alignItems: 'center',
79+
},
4380
container: {
4481
padding: 20,
4582
},
4683
title: {
4784
fontSize: 18,
4885
fontWeight: 'bold',
86+
marginLeft: 10,
87+
},
88+
image: {
89+
width: 80,
90+
height: 80,
91+
borderRadius: 40,
92+
borderWidth: 1,
4993
},
5094
subtitle: {
5195
fontSize: 14,
5296
marginVertical: 10,
97+
flexDirection: 'column',
5398
},
5499
section: {
55100
marginVertical: 10,

src/screens/carrot/components/productItem/ProductItem.interfaces.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,10 @@ export interface ProductItemProps {
1010
sugars: number;
1111
salt: number;
1212
};
13+
ingredients_text: string;
1314
categories: string;
1415
qualities: string[];
15-
image_front_small_url: string;
16+
image: string;
1617
nutriscore_grade: number;
1718
nutriscore_score: string;
1819
}

src/screens/carrot/components/productItem/ProductItem.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,18 @@ import {ProductItemProps} from './ProductItem.interfaces.ts';
88
const ProductItem = ({
99
title,
1010
subtitle,
11-
badgeText,
12-
categories,
1311
defects,
1412
qualities,
15-
image_front_small_url,
13+
image,
1614
nutriscore_grade,
1715
nutriscore_score,
1816
}: ProductItemProps) => {
17+
18+
1919
return (
2020
<View style={styles.card}>
2121
<View style={styles.header}>
22-
<Image style={styles.image} source={{uri: image_front_small_url}} />
22+
<Image style={styles.image} source={{uri: image}} />
2323
<View style={styles.headerText}>
2424
<Text style={styles.title}>{title}</Text>
2525
<Text style={styles.subtitle}>{subtitle}</Text>
@@ -31,12 +31,12 @@ const ProductItem = ({
3131

3232
<View style={styles.content}>
3333
<Text style={styles.sectionTitle}>Défauts</Text>
34-
{defects.map((defect, index) => (
34+
{/* {defects.map((defect, index) => (
3535
<View key={index} style={styles.listItem}>
3636
<Icon name="circle" size={10} color="#EF4444" />
3737
<Text style={styles.listText}>{defect}</Text>
3838
</View>
39-
))}
39+
))} */}
4040

4141
<Text style={styles.sectionTitle}>Qualités</Text>
4242
{qualities.map((quality, index) => (

0 commit comments

Comments
 (0)