@@ -6,29 +6,29 @@ import Navbar from '../../NavBar/Navbar'
66import { styled , alpha } from '@mui/material/styles' ;
77import InputBase from '@mui/material/InputBase' ;
88import SearchIcon from '@mui/icons-material/Search' ;
9-
9+ import AddProductDialog from "./AddProductDialog" ;
1010
1111const input = [
12- { id : 1 , prod : 'Apple' , price : '$3.00' , store : 'Walmart' } ,
13- { id : 2 , prod : 'Orange' , price : '$5.00' , store : 'Target' } ,
14- { id : 3 , prod : 'Cereal' , price : '$2.00' , store : 'Fresh Grocer' } ,
15- { id : 4 , prod : 'Apple' , price : '$3.00' , store : 'Walmart' } ,
16- { id : 5 , prod : 'Orange' , price : '$5.00' , store : 'Target' } ,
17- { id : 6 , prod : 'Cereal' , price : '$2.00' , store : 'Fresh Grocer' } ,
18- { id : 7 , prod : 'Apple' , price : '$3.00' , store : 'Walmart' } ,
19- { id : 8 , prod : 'Orange' , price : '$5.00' , store : 'Target' } ,
20- { id : 9 , prod : 'Cereal' , price : '$2.00' , store : 'Fresh Grocer' } ,
21- { id : 10 , prod : 'Apple' , price : '$3.00' , store : 'Walmart' } ,
22- { id : 11 , prod : 'Orange' , price : '$5.00' , store : 'Target' } ,
23- { id : 12 , prod : 'Cereal' , price : '$2.00' , store : 'Fresh Grocer' } ,
24- { id : 13 , prod : 'Orange' , price : '$5.00' , store : 'Target' } ,
25- { id : 14 , prod : 'Cereal' , price : '$2.00' , store : 'Fresh Grocer' } ,
26- { id : 15 , prod : 'Apple' , price : '$3.00' , store : 'Walmart' } ,
27- { id : 16 , prod : 'Orange' , price : '$5.00' , store : 'Target' } ,
28- { id : 17 , prod : 'Cereal' , price : '$2.00' , store : 'Fresh Grocer' } ,
29- { id : 18 , prod : 'Apple' , price : '$3.00' , store : 'Walmart' } ,
30- { id : 18 , prod : 'Orange' , price : '$5.00' , store : 'Target' } ,
31- { id : 19 , prod : 'Cereal' , price : '$2.00' , store : 'Fresh Grocer' } ,
12+ { id : 1 , prod : 'Apple' , price : 3.99 , store : 'Walmart' , weight : 5.1 } ,
13+ { id : 2 , prod : 'Orange' , price : 5.99 , store : 'Target' , weight : 6.7 } ,
14+ { id : 3 , prod : 'Cereal' , price : 2.99 , store : 'Fresh Grocer' , weight : 14 } ,
15+ { id : 4 , prod : 'Apple' , price : 3.99 , store : 'Walmart' , weight : 5.1 } ,
16+ { id : 5 , prod : 'Orange' , price : 5.99 , store : 'Target' , weight : 6.7 } ,
17+ { id : 6 , prod : 'Cereal' , price : 2.99 , store : 'Fresh Grocer' , weight : 14 } ,
18+ { id : 7 , prod : 'Apple' , price : 3.99 , store : 'Walmart' , weight : 5.1 } ,
19+ { id : 8 , prod : 'Orange' , price : 5.99 , store : 'Target' , weight : 6.7 } ,
20+ { id : 9 , prod : 'Cereal' , price : 2.99 , store : 'Fresh Grocer' , weight : 14 } ,
21+ { id : 10 , prod : 'Apple' , price : 3.99 , store : 'Walmart' , weight : 5.1 } ,
22+ { id : 11 , prod : 'Orange' , price : 5.99 , store : 'Target' , weight : 6.7 } ,
23+ { id : 12 , prod : 'Cereal' , price : 2.99 , store : 'Fresh Grocer' , weight : 14 } ,
24+ { id : 13 , prod : 'Orange' , price : 5.99 , store : 'Target' , weight : 6.7 } ,
25+ { id : 14 , prod : 'Cereal' , price : 2.99 , store : 'Fresh Grocer' , weight : 14 } ,
26+ { id : 15 , prod : 'Apple' , price : 3.99 , store : 'Walmart' , weight : 5.1 } ,
27+ { id : 16 , prod : 'Orange' , price : 5.99 , store : 'Target' , weight : 6.7 } ,
28+ { id : 17 , prod : 'Cereal' , price : 2.99 , store : 'Fresh Grocer' , weight : 14 } ,
29+ { id : 18 , prod : 'Apple' , price : 3.99 , store : 'Walmart' , weight : 5.1 } ,
30+ { id : 19 , prod : 'Orange' , price : 5.99 , store : 'Target' , weight : 6.7 } ,
31+ { id : 20 , prod : 'Cereal' , price : 2.99 , store : 'Fresh Grocer' , weight : 14 } ,
3232]
3333
3434const Search = styled ( 'div' ) ( ( { theme } ) => ( {
@@ -78,19 +78,30 @@ const StyledInputBase = styled(InputBase)(({ theme }) => ({
7878
7979const columns = [
8080 { field : 'prod' , headerName : 'Product' , width : 150 } ,
81- { field : 'price' , headerName : 'Price' , width : 150 } ,
81+ { field : 'price' , headerName : 'Price ($) ' , width : 150 } ,
8282 { field : 'store' , headerName : 'Store' , width : 150 } ,
83+ { field : 'weight' , headerName : 'Weight (oz.)' , width : 150 }
8384] ;
8485
85- export function ProductSearch ( ) {
86+ export function ProductSearch ( props ) {
8687 const [ rows , setRows ] = React . useState ( input ) ;
88+ const [ message , setMessage ] = React . useState ( "" ) ;
8789
8890 const handleSearchTextChange = ( event ) => {
8991 const searchText = event . target . value . toLowerCase ( )
9092 setRows ( input . filter ( item => item . prod . toLowerCase ( ) . includes ( searchText ) ) )
9193 console . log ( 'searchtext: ' + searchText )
9294 } ;
9395
96+ function productClicked ( param , event ) {
97+ //alert(JSON.stringify(param.row.prod));
98+ props . addProduct ( param . row . prod , param . row . weight , param . row . price , param . row . store ) ;
99+ setMessage ( param . row . prod + " added to " + props . lists [ props . listIndex ] . name + "!" ) ;
100+ //alert(JSON.stringify(props.lists[props.listIndex].name));
101+ setTimeout ( ( ) => setMessage ( "" ) , 3000 ) ;
102+
103+ }
104+
94105 return (
95106 < >
96107 < Navbar />
@@ -107,7 +118,10 @@ export function ProductSearch() {
107118 inputProps = { { 'aria-label' : 'search' } }
108119 />
109120 </ Search >
110- < DataGrid rows = { rows } columns = { columns } autoPageSize />
121+ < AddProductDialog lists = { props . lists } selectedList = { props . lists [ props . listIndex ] } changeList = { props . changeList } />
122+ { message }
123+ < br />
124+ < DataGrid rows = { rows } columns = { columns } onRowClick = { productClicked } autoPageSize />
111125 </ div >
112126 </ div >
113127 </ >
0 commit comments