-
Notifications
You must be signed in to change notification settings - Fork 10
Began working on Search functionality #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 1 commit
1f3e098
47eabd3
db1b069
51c5a83
f71a225
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,36 @@ | ||
| import cheerio from 'cheerio-without-node-native'; | ||
| import config from '../config/default'; | ||
|
|
||
| /** | ||
| * Gets post from given query | ||
| * @param {String} query The query string to search for | ||
| * @param {Object} options The options for the search, see the 'searchOptions' variable in helpers/api.js | ||
| * @return {Promise} Returns a promise | ||
| */ | ||
|
|
||
| const searchPost = (options = defaultSearchOptions, query='') => { | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Where does |
||
|
|
||
| const searchOptions = { | ||
| sortByDate: false || options.sortByDate, | ||
| pageNumber: 1 || options.pageNumber, | ||
| tags: 'story' || options.tag, | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For these variables see my comments below: const searchOptions = {
sortByDate: false || options.sortByDate, // will always be options.sortByDate or undefined as false || <anything> will always be <anything>
pageNumber: 1 || options.pageNumber, // will always be 1
tags: 'story' || options.tag, // will always be 'story`
}Better to do change the condition for all three, e.g: |
||
| }; | ||
|
|
||
| const hitsPerPage = '&hitsPerPage=25'; | ||
|
|
||
| // There has to be better way to do this | ||
| // TODO: Refactor this | ||
| const dateParameter = searchOptions.sortByDate ? 'search_by_date' : 'search'; | ||
| const queryParameter = `query=${query}`; | ||
| const tagParameter = `&tags=${searchOptions.tags}` | ||
|
|
||
| const searchUrl = `${config.apiSearch}${dateParameter}?${queryParameter}${hitsPerPage}${tagParameter}`; | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Change |
||
|
|
||
| return fetch(searchUrl) | ||
| .then(response => response.json()) | ||
| .catch(error => error); | ||
| } | ||
|
|
||
| /** | ||
| * Get item from given ID | ||
| * @param {String} itemId The ID of the item to fetch | ||
|
|
@@ -364,4 +394,5 @@ export { | |
| logout, | ||
| getComments, | ||
| toggleComments, | ||
| searchPost, | ||
| }; | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we rename
apiSearchtosearchto fit in withapiandbase