@@ -13,6 +13,18 @@ const PARAM_SEARCH = 'query=';
1313const PARAM_PAGE = 'page=' ;
1414const PARAM_HPP = 'hitsPerPage=' ;
1515
16+ const largeColumn = {
17+ width : '40%' ,
18+ } ;
19+
20+ const midColumn = {
21+ width : '30%' ,
22+ } ;
23+
24+ const smallColumn = {
25+ width : '10%' ,
26+ } ;
27+
1628const SORTS = {
1729 NONE : list => list ,
1830 TITLE : list => sortBy ( list , 'title' ) ,
@@ -43,8 +55,6 @@ const updateSearchTopStoriesState = (hits, page) => (prevState) => {
4355} ;
4456
4557class App extends Component {
46- _isMounted = false ;
47-
4858 constructor ( props ) {
4959 super ( props ) ;
5060
@@ -54,8 +64,6 @@ class App extends Component {
5464 searchTerm : DEFAULT_QUERY ,
5565 error : null ,
5666 isLoading : false ,
57- sortKey : 'NONE' ,
58- isSortReverse : false ,
5967 } ;
6068
6169 this . needsToSearchTopStories = this . needsToSearchTopStories . bind ( this ) ;
@@ -80,21 +88,15 @@ class App extends Component {
8088
8189 axios ( `${ PATH_BASE } ${ PATH_SEARCH } ?${ PARAM_SEARCH } ${ searchTerm } &${ PARAM_PAGE } ${ page } &${ PARAM_HPP } ${ DEFAULT_HPP } ` )
8290 . then ( result => this . setSearchTopStories ( result . data ) )
83- . catch ( error => this . _isMounted && this . setState ( { error } ) ) ;
91+ . catch ( error => this . setState ( { error } ) ) ;
8492 }
8593
8694 componentDidMount ( ) {
87- this . _isMounted = true ;
88-
8995 const { searchTerm } = this . state ;
9096 this . setState ( { searchKey : searchTerm } ) ;
9197 this . fetchSearchTopStories ( searchTerm ) ;
9298 }
9399
94- componentWillUnmount ( ) {
95- this . _isMounted = false ;
96- }
97-
98100 onSearchChange ( event ) {
99101 this . setState ( { searchTerm : event . target . value } ) ;
100102 }
@@ -169,7 +171,8 @@ class App extends Component {
169171 < div className = "interactions" >
170172 < ButtonWithLoading
171173 isLoading = { isLoading }
172- onClick = { ( ) => this . fetchSearchTopStories ( searchKey , page + 1 ) } >
174+ onClick = { ( ) => this . fetchSearchTopStories ( searchKey , page + 1 ) }
175+ >
173176 More
174177 </ ButtonWithLoading >
175178 </ div >
@@ -208,7 +211,9 @@ class Table extends Component {
208211 }
209212
210213 onSort ( sortKey ) {
211- const isSortReverse = this . state . sortKey === sortKey && ! this . state . isSortReverse ;
214+ const isSortReverse = this . state . sortKey === sortKey &&
215+ ! this . state . isSortReverse ;
216+
212217 this . setState ( { sortKey, isSortReverse } ) ;
213218 }
214219
@@ -273,19 +278,19 @@ class Table extends Component {
273278 </ div >
274279 { reverseSortedList . map ( item =>
275280 < div key = { item . objectID } className = "table-row" >
276- < span style = { { width : '40%' } } >
281+ < span style = { largeColumn } >
277282 < a href = { item . url } > { item . title } </ a >
278283 </ span >
279- < span style = { { width : '30%' } } >
284+ < span style = { midColumn } >
280285 { item . author }
281286 </ span >
282- < span style = { { width : '10%' } } >
287+ < span style = { smallColumn } >
283288 { item . num_comments }
284289 </ span >
285- < span style = { { width : '10%' } } >
290+ < span style = { smallColumn } >
286291 { item . points }
287292 </ span >
288- < span style = { { width : '10%' } } >
293+ < span style = { smallColumn } >
289294 < Button
290295 onClick = { ( ) => onDismiss ( item . objectID ) }
291296 className = "button-inline"
@@ -344,10 +349,10 @@ const withLoading = (Component) => ({ isLoading, ...rest }) =>
344349
345350const ButtonWithLoading = withLoading ( Button ) ;
346351
352+ export default App ;
353+
347354export {
348355 Button ,
349356 Search ,
350357 Table ,
351- } ;
352-
353- export default App ;
358+ } ;
0 commit comments