File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -12,6 +12,7 @@ import ShoppingListView from './Components/Pages/ShoppingLists/ShoppingListView'
1212import { ProductSearch } from './Components/Pages/ProductSearch/ProductSearch' ;
1313import ErrorPage from "./Components/Pages/404Page/ErrorPage"
1414import Logout from './Components/Pages/Logout/logout' ;
15+ import ProductListParent from './Components/Pages/ProductListParent' ;
1516
1617import {
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 >
Original file line number Diff line number Diff line change 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 ;
Original file line number Diff line number Diff 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 </ >
You can’t perform that action at this time.
0 commit comments