This repository was archived by the owner on Jul 24, 2018. It is now read-only.
File tree Expand file tree Collapse file tree 5 files changed +28
-29
lines changed Expand file tree Collapse file tree 5 files changed +28
-29
lines changed Original file line number Diff line number Diff line change @@ -4,9 +4,9 @@ import {render} from 'react-dom';
4
4
import FilterableProductTable from './src/filterable-product-table' ;
5
5
6
6
// init shell
7
- renderShell ( ) ;
7
+ initShell ( ) ;
8
8
9
- function renderShell ( ) {
9
+ function initShell ( ) {
10
10
var shell = document . createElement ( 'main' ) ;
11
11
shell . className = 'app-shell' ;
12
12
document . body . appendChild ( shell ) ;
Original file line number Diff line number Diff line change 1
1
import React from 'react' ;
2
2
3
- const CategoryRow = ( { category} ) => (
3
+ export default ( { category} ) => (
4
4
< tr >
5
5
< th colSpan = "2" > { category } </ th >
6
6
</ tr >
7
- ) ;
8
-
9
- export default CategoryRow ;
7
+ ) ;
Original file line number Diff line number Diff line change 1
1
import React from 'react' ;
2
2
3
- const ProductRow = ( { product} ) => {
3
+ export default ( { product} ) => {
4
4
var name = product . stocked ? product . name : < span style = { { color : 'red' } } > { product . name } </ span > ;
5
5
return (
6
6
< tr >
7
7
< td > { name } </ td >
8
8
< td > { product . price } </ td >
9
9
</ tr >
10
10
) ;
11
- } ;
12
-
13
- export default ProductRow ;
11
+ } ;
Original file line number Diff line number Diff line change @@ -4,32 +4,35 @@ import ProductRow from './product-row';
4
4
5
5
export default ( { products, filterText, inStockOnly} ) => {
6
6
7
- let rows = [ ] ,
8
- lastCategory = null ;
7
+ let rows = [ ] , lastCategory = null ;
9
8
10
9
products . map ( ( product ) => {
11
- if ( product . name . indexOf ( filterText ) === - 1 || ( ! product . stocked && inStockOnly ) ) {
10
+ if ( product . name . toLowerCase ( ) . indexOf ( filterText . toLowerCase ( ) ) === - 1 || ( ! product . stocked && inStockOnly ) ) {
12
11
return ;
13
12
}
14
13
15
14
if ( product . category !== lastCategory ) {
16
- rows . push (
17
- < CategoryRow category = { product . category } key = { product . category } />
18
- ) ;
15
+ rows . push ( < CategoryRow category = { product . category } key = { product . category } /> ) ;
19
16
}
17
+
20
18
rows . push ( < ProductRow product = { product } key = { product . name } /> ) ;
21
19
lastCategory = product . category ;
20
+
22
21
} ) ;
23
22
24
- return (
25
- < table >
26
- < thead >
27
- < tr >
28
- < th > Name</ th >
29
- < th > Price</ th >
30
- </ tr >
31
- </ thead >
32
- < tbody > { rows } </ tbody >
33
- </ table >
34
- ) ;
23
+ if ( rows . length > 0 ) {
24
+ return (
25
+ < table >
26
+ < thead >
27
+ < tr >
28
+ < th > Name</ th >
29
+ < th > Price</ th >
30
+ </ tr >
31
+ </ thead >
32
+ < tbody > { rows } </ tbody >
33
+ </ table >
34
+ ) ;
35
+ } else {
36
+ return ( < p > No results found</ p > ) ;
37
+ }
35
38
}
Original file line number Diff line number Diff line change 1
- import React from 'react' ;
1
+ import React , { Component } from 'react' ;
2
2
3
- class SearchBar extends React . Component {
3
+ class SearchBar extends Component {
4
4
5
5
constructor ( ) {
6
6
super ( ) ;
You can’t perform that action at this time.
0 commit comments