-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #37 from benfluleck/chore/153149549/users-should-b…
…e-able-to-search-for-books feature(search): Implement search feature app
- Loading branch information
Showing
15 changed files
with
184 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { showErrorNotification } from './notifications'; | ||
import { | ||
SEARCH_BOOKS_SUCCESS, | ||
SEARCH_BOOKS_FAILURE | ||
} from './actiontype'; | ||
import api from './api'; | ||
|
||
export const SearchBookSuccess = books => ({ type: SEARCH_BOOKS_SUCCESS, books }); | ||
export const SearchBookFailure = error => ({ type: SEARCH_BOOKS_FAILURE, error }); | ||
|
||
|
||
/** | ||
* async helper function: search Books | ||
* @function SearchBooks | ||
* @param {object} value | ||
* @returns {function} asynchronous action | ||
*/ | ||
export const searchAllBooks = value => dispatch => api | ||
.book | ||
.searchBooks(value) | ||
.then((response) => { | ||
dispatch(SearchBookSuccess(response.booksFound)); | ||
return (response); | ||
}) | ||
.catch((error) => { | ||
dispatch(showErrorNotification({ error })); | ||
dispatch(SearchBookFailure({ error })); | ||
return error; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 0 additions & 1 deletion
1
client/src/app/components/presentation/common/book/DisplayBook.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
client/src/app/components/presentation/common/book/SearchBooks.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { connect } from 'react-redux'; | ||
import { Col, Icon,Autocomplete } from 'react-materialize'; | ||
import { searchAllBooks } from '../../../../actions/searchbooks'; | ||
import { fetchAllBooks } from '../../../../actions/fetchbooks'; | ||
|
||
|
||
/** | ||
* | ||
* | ||
* @class SearchBooks | ||
* @extends {React.Component} | ||
*/ | ||
class SearchBooks extends React.Component { | ||
/** | ||
* Creates an instance of SearchBooks. | ||
* @param {any} props | ||
* | ||
* @memberOf SearchBooks | ||
*/ | ||
constructor(props) { | ||
super(props); | ||
|
||
this.state = { | ||
searchTerm:'', | ||
offset: 0, | ||
limit:8, | ||
dataSource: {} | ||
}; | ||
this.onChange = this.onChange.bind(this) | ||
} | ||
|
||
onChange = (event, value ) => { | ||
event.preventDefault(); | ||
this.setState({ | ||
searchTerm: value | ||
}); | ||
if(value.length> 1){ | ||
this.props.searchAllBooks(value) | ||
} | ||
else{ | ||
this.props.fetchAllBooks(this.state.offset, this.state.limit); | ||
} | ||
|
||
}; | ||
|
||
render() { | ||
return ( | ||
<Col s={12} m={3} l={3}> | ||
<div className='autocomplete'> | ||
<Col s={2}> | ||
<div className='autocomplete-icon'> | ||
<Icon medium>search | ||
</Icon> | ||
</div> | ||
</Col> | ||
<Col s={10}> | ||
<Autocomplete | ||
placeholder='Search.....' | ||
data ={this.state.dataSource} | ||
onChange= {this.onChange} | ||
/> | ||
</Col> | ||
|
||
</div> | ||
</Col> | ||
|
||
); | ||
} | ||
} | ||
|
||
|
||
export default connect(null, { fetchAllBooks, searchAllBooks })(SearchBooks); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters