-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Expand file tree
/
Copy pathApp.tsx
More file actions
72 lines (68 loc) · 2.29 KB
/
App.tsx
File metadata and controls
72 lines (68 loc) · 2.29 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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import './App.scss';
import { Routes, Route } from 'react-router-dom';
import { Frame } from './components/Frame';
import { HomePage } from './modules/HomePage';
import { ProductsPage } from './modules/ProductsPage';
import phones from '../public/api/phones.json';
import tablets from '../public/api/tablets.json';
import accessories from '../public/api/accessories.json';
import products from '../public/api/products.json';
import { ProductPage } from './modules/ProductPage';
import { useContext } from 'react';
import { AddToFavContext } from './contexts/AddToFavContext';
import { NotFoundPage } from './modules/NotFoundPage';
import { CartPage } from './modules/CartPage/CartPage';
export const App = () => {
const phonesForCat = products.filter(
product => product.category === 'phones',
);
const tabletsForCat = products.filter(
product => product.category === 'tablets',
);
const accessoriesForCat = products.filter(
product => product.category === 'accessories',
);
const { fav } = useContext(AddToFavContext);
return (
<Routes>
<Route path="/" element={<Frame />}>
<Route index element={<HomePage products={products} />} />
<Route path="phones">
<Route
index
element={
<ProductsPage products={phonesForCat} title="Mobile phones" />
}
/>
<Route path=":product" element={<ProductPage products={phones} />} />
</Route>
<Route path="tablets">
<Route
index
element={<ProductsPage products={tabletsForCat} title="Tablets" />}
/>
<Route path=":product" element={<ProductPage products={tablets} />} />
</Route>
<Route path="accessories">
<Route
index
element={
<ProductsPage products={accessoriesForCat} title="Accessories" />
}
/>
<Route
path=":product"
element={<ProductPage products={accessories} />}
/>
</Route>
<Route
path="favourites"
index
element={<ProductsPage products={fav} title="Favourites" />}
/>
<Route path="cart" element={<CartPage />} />
<Route path="*" element={<NotFoundPage />} />
</Route>
</Routes>
);
};