Skip to content

Commit 814ea6a

Browse files
committed
created parent component for shopping lists and product search
1 parent 9a50628 commit 814ea6a

3 files changed

Lines changed: 56 additions & 3 deletions

File tree

src/App.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import ShoppingListView from './Components/Pages/ShoppingLists/ShoppingListView'
1212
import { ProductSearch } from './Components/Pages/ProductSearch/ProductSearch';
1313
import ErrorPage from "./Components/Pages/404Page/ErrorPage"
1414
import Logout from './Components/Pages/Logout/logout';
15+
import ProductListParent from './Components/Pages/ProductListParent';
1516

1617
import {
1718
BrowserRouter,
@@ -27,8 +28,8 @@ export default function App() {
2728
<Route index element={<LoginForm />} />
2829
<Route path="/register" element={<RegisterForm />} />
2930
<Route path="/home" element={<HomeForm />} />
30-
<Route path="/lists" element={<ShoppingListView />} />
31-
<Route path="/search" element={<ProductSearch />} />
31+
<Route path="/lists" element={<ProductListParent pageIndex={1} />} />
32+
<Route path="/search" element={<ProductListParent pageIndex={0} />} />
3233
<Route path="/logout" element={<Logout />} />
3334
<Route path="*" element={<ErrorPage />} />
3435
</Routes>
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import React from 'react';
2+
import { ShoppingList, ShoppingListCollection, Product } from './ShoppingLists/ShoppingList.js'
3+
import ShoppingListView from './ShoppingLists/ShoppingListView';
4+
import { ProductSearch } from './ProductSearch/ProductSearch';
5+
import ErrorPage from "./404Page/ErrorPage"
6+
7+
class ProductListParent extends React.Component {
8+
constructor(props) {
9+
super(props);
10+
this.state = {
11+
shoppingList: ShoppingListCollection.collection,
12+
};
13+
}
14+
15+
updateShoppingList(updatedList) {
16+
this.setState({shoppingList: updatedList})
17+
}
18+
19+
20+
21+
22+
23+
render() {
24+
let component = null;
25+
26+
switch(this.props.pageIndex) {
27+
case 0:
28+
component = <ProductSearch />;
29+
break;
30+
case 1:
31+
component = <ShoppingListView />;
32+
break;
33+
default:
34+
component = <ErrorPage />
35+
}
36+
37+
return (
38+
<div>
39+
{component}
40+
</div>
41+
42+
);
43+
}
44+
}
45+
46+
47+
48+
export default ProductListParent;

src/Components/Pages/ProductSearch/ProductSearch.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,10 @@ export function ProductSearch() {
9191
console.log('searchtext: ' + searchText)
9292
};
9393

94+
function productClicked(param, event) {
95+
alert(JSON.stringify(param.row));
96+
}
97+
9498
return (
9599
<>
96100
<Navbar />
@@ -107,7 +111,7 @@ export function ProductSearch() {
107111
inputProps={{ 'aria-label': 'search' }}
108112
/>
109113
</Search>
110-
<DataGrid rows={rows} columns={columns} autoPageSize />
114+
<DataGrid rows={rows} columns={columns} onRowClick={productClicked} autoPageSize />
111115
</div>
112116
</div>
113117
</>

0 commit comments

Comments
 (0)