-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.js
More file actions
45 lines (39 loc) · 1.16 KB
/
Copy pathApp.js
File metadata and controls
45 lines (39 loc) · 1.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import React from 'react';
import { View, StyleSheet } from 'react-native';
import CarModelGallery from './components/CarModelGallery';
import CarDetails from './components/CarDetails';
import carData from './data/carData';
const App = () => {
const [selectedCar, setSelectedCar] = React.useState(null);
const [favoriteCars, setFavoriteCars] = React.useState([]);
const handleCarSelect = (car) => {
setSelectedCar(car);
};
const handleToggleFavorite = (car) => {
const isCarFavorite = favoriteCars.some((favCar) => favCar.id === car.id);
if (isCarFavorite) {
setFavoriteCars(favoriteCars.filter((favCar) => favCar.id !== car.id));
} else {
setFavoriteCars([...favoriteCars, car]);
}
};
return (
<View style={styles.container}>
<CarModelGallery
carData={carData}
onCarSelect={handleCarSelect}
favoriteCars={favoriteCars}
onToggleFavorite={handleToggleFavorite}
/>
{selectedCar && <CarDetails selectedCar={selectedCar} />}
</View>
);
};
const styles = StyleSheet.create({
container: {
flex: 1,
padding: 20,
backgroundColor: '#fff',
},
});
export default App;