-
Notifications
You must be signed in to change notification settings - Fork 5
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
Ndlano/issue#474 lydvelger som egen pakke #76
Merged
Merged
Changes from 25 commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
d67ea79
#474 Audio search with basic response
sirhaug 8734e41
#474 Result list now showing basic preview
sirhaug 449f8a1
Merge branch 'master' into NDLANO/Issue#474-Lydvelger-som-egen-pakke
sirhaug 894f40e
#474 Search bar with simple results and an functional audio player
sirhaug 5c5bfa8
Merge branch 'master' into NDLANO/Issue#474-Lydvelger-som-egen-pakke
sirhaug d23b3f2
#474 Remove some 'console.log's
sirhaug 9b0de64
#474 New fetch methods, with latest 'test' instead of 'staging'
sirhaug 8622dbc
#474 Audio search with language, and lazy loading of audio sources.
sirhaug a326a8c
#474 Added new button
sirhaug 0f88b0a
#474 Changed copyright for audio search from 2016-> to 2017->
sirhaug 480bdd9
#474 Switched from text field to drop down menu for langugae selection
sirhaug 0f18b2a
#474 Update query and results before state
sirhaug 9d7ae9e
#474 Hide download button on audio bar in Chrome
sirhaug 6191116
#474 Prettier via Atom
sirhaug 1ab4a52
#474 Prettier with other rules
sirhaug 9d6f145
Merge branch 'master' into NDLANO/Issue#474-Lydvelger-som-egen-pakke
chrpeter f3cc0eb
Merge branch 'NDLANO/Issue#474-Lydvelger-som-egen-pakke' of github.co…
chrpeter 73e51e3
#474 Lint errors fixed
sirhaug 004630f
#474 Cleanup
sirhaug b6421e4
#474 Don't store '<source>' in state
sirhaug 30ba799
#474 Check on 'audioSource', not 'loaded'
sirhaug d567a91
#474 Remove drop down menu for language selection
sirhaug de11abc
Cosmetic fixes for audio #474
chrpeter 2cb7944
#474 Added spinner
sirhaug b081c4d
#474 Added missing 'AudioSearchList'
sirhaug 338b2a0
#474 Code review
sirhaug a7f5b15
#474 Added content to README
sirhaug File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Empty file.
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,47 @@ | ||
{ | ||
"name": "ndla-audio-search", | ||
"version": "0.1.1-0", | ||
"description": "A simple library for searching for audio files from NDLA", | ||
"license": "GPL-3.0", | ||
"main": "lib/index.js", | ||
"module": "es/index.js", | ||
"jsnext:main": "es/index.js", | ||
"scripts": { | ||
"build": "npm run build:commonjs && npm run build:es", | ||
"build:commonjs": "$(cd ..; npm bin)/cross-env BABEL_ENV=commonjs $(cd ..; npm bin)/babel src --out-dir lib --ignore __tests__", | ||
"build:es": "$(cd ..; npm bin)/cross-env BABEL_ENV=es $(cd ..; npm bin)/babel src --out-dir es --ignore __tests__", | ||
"clean": "$(cd ..; npm bin)/rimraf lib es", | ||
"test": "$(cd ..; npm bin)/jest", | ||
"prepublish": "npm run clean && npm run build" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/NDLANO/frontend-packages.git/ndla-ui/" | ||
}, | ||
"keywords": [ | ||
"ndla" | ||
], | ||
"author": "[email protected]", | ||
"files": [ | ||
], | ||
"devDependencies": { | ||
"ndla-article-scripts": "^0.0.3", | ||
"ndla-licenses": "^0.0.7", | ||
"ndla-ui": "^0.7.4", | ||
"ndla-util": "^0.1.3", | ||
"defined": "1.0.0", | ||
"react-bem-helper": "^1.2.0" | ||
}, | ||
"peerDependencies": { | ||
"classnames": "^2.2.5", | ||
"ndla-article-scripts": "^0.0.3", | ||
"ndla-licenses": "^0.0.7", | ||
"ndla-ui": "^0.7.4", | ||
"ndla-util": "^0.1.3", | ||
"react": "^15.0.0", | ||
"react-bem-helper": "^1.2.0", | ||
"react-dom": "^15.0.0" | ||
}, | ||
"dependencies": { | ||
} | ||
} |
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,67 @@ | ||
/** | ||
* Copyright (c) 2017-present, NDLA. | ||
* | ||
* This source code is licensed under the GPLv3 license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
*/ | ||
|
||
/* eslint jsx-a11y/media-has-caption: 0 */ | ||
|
||
import React, { Component } from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import BEMHelper from 'react-bem-helper'; | ||
|
||
const classes = new BEMHelper({ | ||
name: 'audio-component', | ||
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. prefix c står for component, så ville heller hatt audio-preview eller noe sånt i stedet. |
||
prefix: 'c-', | ||
}); | ||
|
||
class AudioComponent extends Component { | ||
constructor(props) { | ||
super(props); | ||
this.state = { | ||
audioSource: undefined, | ||
audioType: undefined, | ||
}; | ||
|
||
this.loadAudio = this.loadAudio.bind(this); | ||
} | ||
|
||
loadAudio() { | ||
this.props | ||
.fetchAudio(this.props.audio.id) | ||
.then(result => { | ||
this.setState({ | ||
audioSource: result.audioFile.url, | ||
audioType: result.audioFile.mimeType, | ||
}); | ||
}) | ||
.catch(err => { | ||
this.props.onError(err); | ||
}); | ||
} | ||
|
||
render() { | ||
const { audioSource, audioType } = this.state; | ||
return ( | ||
<div {...classes()}> | ||
<audio controls autoPlay onPlay={!audioSource && this.loadAudio}> | ||
{audioSource | ||
? <source src={audioSource} type={audioType} /> | ||
: undefined} | ||
</audio> | ||
</div> | ||
); | ||
} | ||
} | ||
|
||
AudioComponent.propTypes = { | ||
audio: PropTypes.shape({ | ||
id: PropTypes.number.isRequired, | ||
}), | ||
fetchAudio: PropTypes.func.isRequired, | ||
onError: PropTypes.func.isRequired, | ||
}; | ||
|
||
export default AudioComponent; |
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,126 @@ | ||
/** | ||
* Copyright (c) 2017-present, NDLA. | ||
* | ||
* This source code is licensed under the GPLv3 license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
*/ | ||
|
||
import React, { Component } from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { Pager } from 'ndla-ui'; | ||
import BEMHelper from 'react-bem-helper'; | ||
|
||
import AudioSearchForm from './AudioSearchForm'; | ||
import AudioSearchList from './AudioSearchList'; | ||
|
||
const classes = new BEMHelper({ | ||
name: 'audio-search', | ||
prefix: 'c-', | ||
}); | ||
|
||
class AudioSearch extends Component { | ||
constructor(props) { | ||
super(props); | ||
this.state = { | ||
queryObject: props.queryObject, | ||
audios: [], | ||
lastPage: 0, | ||
totalCount: 0, | ||
searching: false, | ||
}; | ||
|
||
this.submitAudioSearchQuery = this.submitAudioSearchQuery.bind(this); | ||
this.searchAudios = this.searchAudios.bind(this); | ||
} | ||
|
||
componentDidMount() { | ||
this.searchAudios(this.state.queryObject); | ||
} | ||
|
||
submitAudioSearchQuery(queryObject) { | ||
this.searchAudios({ | ||
query: queryObject.query, | ||
page: 1, | ||
pageSize: queryObject.pageSize, | ||
locale: queryObject.locale, | ||
}); | ||
} | ||
|
||
searchAudios(queryObject) { | ||
this.setState({ searching: true }); | ||
this.props | ||
.searchAudios(queryObject) | ||
.then(result => { | ||
this.setState({ | ||
queryObject: { | ||
query: queryObject.query, | ||
page: queryObject.page, | ||
pageSize: result.pageSize, | ||
locale: queryObject.locale, | ||
}, | ||
audios: result.results, | ||
totalCount: result.totalCount, | ||
lastPage: Math.ceil(result.totalCount / result.pageSize), | ||
searching: false, | ||
}); | ||
}) | ||
.catch(err => { | ||
this.props.onError(err); | ||
this.setState({ searching: false }); | ||
}); | ||
} | ||
|
||
render() { | ||
const { fetchAudio, onError, translations } = this.props; | ||
const { queryObject, audios, lastPage, searching } = this.state; | ||
const { page, locale } = queryObject; | ||
|
||
return ( | ||
<div {...classes()}> | ||
<AudioSearchForm | ||
onSearchQuerySubmit={this.submitAudioSearchQuery} | ||
queryObject={queryObject} | ||
searching={searching} | ||
translations={translations} | ||
/> | ||
<AudioSearchList | ||
audios={audios} | ||
searching={searching} | ||
locale={locale} | ||
translations={translations} | ||
onError={onError} | ||
fetchAudio={fetchAudio} | ||
/> | ||
<Pager | ||
page={page ? parseInt(page, 10) : 1} | ||
pathname="" | ||
lastPage={lastPage} | ||
query={queryObject} | ||
onClick={this.searchAudios} | ||
pageItemComponentClass="button" | ||
/> | ||
</div> | ||
); | ||
} | ||
} | ||
|
||
AudioSearch.propTypes = { | ||
queryObject: PropTypes.shape({ | ||
query: PropTypes.string, | ||
page: PropTypes.number.isRequired, | ||
pageSize: PropTypes.number.isRequired, | ||
locale: PropTypes.string.isRequired, | ||
}), | ||
fetchAudio: PropTypes.func.isRequired, | ||
searchAudios: PropTypes.func.isRequired, | ||
onError: PropTypes.func.isRequired, | ||
translations: PropTypes.shape({ | ||
searchPlaceholder: PropTypes.string.isRequired, | ||
searchButtonTitle: PropTypes.string.isRequired, | ||
useAudio: PropTypes.string.isRequired, | ||
noResults: PropTypes.string.isRequired, | ||
}), | ||
}; | ||
|
||
export default AudioSearch; |
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,91 @@ | ||
/** | ||
* Copyright (c) 2017-present, NDLA. | ||
* | ||
* This source code is licensed under the GPLv3 license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
*/ | ||
|
||
import React, { Component } from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { Button } from 'ndla-ui'; | ||
import BEMHelper from 'react-bem-helper'; | ||
|
||
const classes = new BEMHelper({ | ||
name: 'audio-search', | ||
prefix: 'c-', | ||
}); | ||
|
||
class AudioSearchForm extends Component { | ||
constructor(props) { | ||
super(props); | ||
this.state = { | ||
queryObject: props.queryObject, | ||
}; | ||
this.onKeyPress = this.onKeyPress.bind(this); | ||
this.handleQueryChange = this.handleQueryChange.bind(this); | ||
this.handleSubmit = this.handleSubmit.bind(this); | ||
} | ||
|
||
onKeyPress(evt) { | ||
if (evt.key === 'Enter') { | ||
this.handleSubmit(evt); | ||
} | ||
} | ||
|
||
handleQueryChange(evt) { | ||
this.setState({ | ||
queryObject: { | ||
query: evt.target.value, | ||
page: this.state.queryObject.page, | ||
pageSize: this.state.queryObject.pageSize, | ||
locale: this.state.queryObject.locale, | ||
}, | ||
}); | ||
} | ||
|
||
handleSubmit(evt) { | ||
evt.preventDefault(); | ||
this.props.onSearchQuerySubmit(this.state.queryObject); | ||
} | ||
|
||
render() { | ||
const { searching, translations } = this.props; | ||
|
||
return ( | ||
<div {...classes('form')}> | ||
<input | ||
{...classes('form-query')} | ||
type="text" | ||
onChange={this.handleQueryChange} | ||
onKeyPress={this.onKeyPress} | ||
value={this.state.queryObject.query} | ||
placeholder={translations.searchPlaceholder} | ||
/> | ||
<Button | ||
{...classes('form-button')} | ||
onClick={this.handleSubmit} | ||
loading={searching}> | ||
{translations.searchButtonTitle} | ||
</Button> | ||
</div> | ||
); | ||
} | ||
} | ||
|
||
AudioSearchForm.propTypes = { | ||
queryObject: PropTypes.shape({ | ||
query: PropTypes.string, | ||
page: PropTypes.number.isRequired, | ||
pageSize: PropTypes.number.isRequired, | ||
locale: PropTypes.string.isRequired, | ||
}), | ||
translations: PropTypes.shape({ | ||
searchPlaceholder: PropTypes.string.isRequired, | ||
searchButtonTitle: PropTypes.string.isRequired, | ||
}), | ||
searching: PropTypes.bool.isRequired, | ||
onSearchQuerySubmit: PropTypes.func.isRequired, | ||
}; | ||
|
||
export default AudioSearchForm; |
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,63 @@ | ||
/** | ||
* Copyright (c) 2017-present, NDLA. | ||
* | ||
* This source code is licensed under the GPLv3 license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
*/ | ||
|
||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import BEMHelper from 'react-bem-helper'; | ||
import AudioSearchResult from './AudioSearchResult'; | ||
|
||
const classes = new BEMHelper({ | ||
name: 'audio-search-list', | ||
prefix: 'c-', | ||
}); | ||
|
||
export default function AudioSearchList({ | ||
audios, | ||
searching, | ||
locale, | ||
translations, | ||
onError, | ||
fetchAudio, | ||
}) { | ||
if ((!audios || audios.length === 0) && !searching) { | ||
return ( | ||
<p> | ||
{translations.noResults} | ||
</p> | ||
); | ||
} | ||
if (searching && !(audios.length > 0)) { | ||
return <div {...classes('result-spinner')} />; | ||
} | ||
return ( | ||
<div {...classes('list')}> | ||
{audios.map(audio => | ||
<AudioSearchResult | ||
key={audio.id} | ||
audio={audio} | ||
fetchAudio={fetchAudio} | ||
onError={onError} | ||
locale={locale} | ||
translations={translations} | ||
/>, | ||
)} | ||
</div> | ||
); | ||
} | ||
|
||
AudioSearchList.propTypes = { | ||
audios: PropTypes.array.isRequired, | ||
searching: PropTypes.bool.isRequired, | ||
locale: PropTypes.string.isRequired, | ||
translations: PropTypes.shape({ | ||
noResults: PropTypes.string.isRequired, | ||
useAudio: PropTypes.string.isRequired, | ||
}), | ||
onError: PropTypes.func.isRequired, | ||
fetchAudio: PropTypes.func.isRequired, | ||
}; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
defined må være dependency.