Skip to content
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 27 commits into from
Aug 7, 2017
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
d67ea79
#474 Audio search with basic response
sirhaug Jul 18, 2017
8734e41
#474 Result list now showing basic preview
sirhaug Jul 18, 2017
449f8a1
Merge branch 'master' into NDLANO/Issue#474-Lydvelger-som-egen-pakke
sirhaug Jul 18, 2017
894f40e
#474 Search bar with simple results and an functional audio player
sirhaug Jul 20, 2017
5c5bfa8
Merge branch 'master' into NDLANO/Issue#474-Lydvelger-som-egen-pakke
sirhaug Jul 20, 2017
d23b3f2
#474 Remove some 'console.log's
sirhaug Jul 20, 2017
9b0de64
#474 New fetch methods, with latest 'test' instead of 'staging'
sirhaug Jul 20, 2017
8622dbc
#474 Audio search with language, and lazy loading of audio sources.
sirhaug Jul 21, 2017
a326a8c
#474 Added new button
sirhaug Jul 21, 2017
0f88b0a
#474 Changed copyright for audio search from 2016-> to 2017->
sirhaug Jul 21, 2017
480bdd9
#474 Switched from text field to drop down menu for langugae selection
sirhaug Jul 24, 2017
0f18b2a
#474 Update query and results before state
sirhaug Jul 24, 2017
9d7ae9e
#474 Hide download button on audio bar in Chrome
sirhaug Jul 24, 2017
6191116
#474 Prettier via Atom
sirhaug Jul 25, 2017
1ab4a52
#474 Prettier with other rules
sirhaug Jul 25, 2017
9d6f145
Merge branch 'master' into NDLANO/Issue#474-Lydvelger-som-egen-pakke
chrpeter Jul 25, 2017
f3cc0eb
Merge branch 'NDLANO/Issue#474-Lydvelger-som-egen-pakke' of github.co…
chrpeter Jul 25, 2017
73e51e3
#474 Lint errors fixed
sirhaug Jul 25, 2017
004630f
#474 Cleanup
sirhaug Jul 25, 2017
b6421e4
#474 Don't store '<source>' in state
sirhaug Jul 25, 2017
30ba799
#474 Check on 'audioSource', not 'loaded'
sirhaug Jul 25, 2017
d567a91
#474 Remove drop down menu for language selection
sirhaug Jul 25, 2017
de11abc
Cosmetic fixes for audio #474
chrpeter Jul 25, 2017
2cb7944
#474 Added spinner
sirhaug Jul 25, 2017
b081c4d
#474 Added missing 'AudioSearchList'
sirhaug Jul 25, 2017
338b2a0
#474 Code review
sirhaug Jul 26, 2017
a7f5b15
#474 Added content to README
sirhaug Jul 26, 2017
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file.
47 changes: 47 additions & 0 deletions packages/ndla-audio-search/package.json
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.4.3",
"ndla-util": "^0.1.3"
},
"peerDependencies": {
"classnames": "^2.2.5",
"ndla-article-scripts": "^0.0.3",
"ndla-licenses": "^0.0.7",
"ndla-ui": "^0.4.3",
"ndla-util": "^0.1.3",
"react": "^15.0.0",
"react-bem-helper": "^1.2.0",
"react-dom": "^15.0.0"
},
"dependencies": {
"defined": "1.0.0",
"react-bem-helper": "^1.2.0"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trengs vel bare som devDep.

}
}
66 changes: 66 additions & 0 deletions packages/ndla-audio-search/src/AudioComponent.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/**
* 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 BEMHelper from 'react-bem-helper';
import { Button } from 'ndla-ui';

const classes = new BEMHelper({
name: 'audio-component',
Copy link
Contributor

Choose a reason for hiding this comment

The 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,
};

this.loadAudio = this.loadAudio.bind(this);
}

loadAudio() {
this.props
.fetchAudio(this.props.audio.id)
.then(result => {
this.setState({
audioSource: (
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Her ville jeg heller ha satt

this.setState({src: result.audioFile.url, type: result.audioFile.mimeType});

og brukt dette i source taggen lenger ned.

<source
src={result.audioFile.url}
type={result.audioFile.mimeType}
/>
),
});
})
.catch(err => {
this.props.onError(err);
});
}

render() {
const { audioSource } = this.state;

return (
<div {...classes()}>
<audio autoPlay controls onPlay={!audioSource && this.loadAudio}>
{' '}{audioSource}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hvorfor {' '}{audioSource} ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Med state endringen ovenfor kan du ta ha

<source src={this.state.src} type={this.state.type} />

</audio>
</div>
);
}
}

AudioComponent.propTypes = {
audio: PropTypes.object.isRequired,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PropTypes.shape her.

fetchAudio: PropTypes.func.isRequired,
onError: PropTypes.func.isRequired,
};

export default AudioComponent;
133 changes: 133 additions & 0 deletions packages/ndla-audio-search/src/AudioSearch.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
/**
* 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 AudioSearchResult from './AudioSearchResult';

const classes = new BEMHelper({
name: 'audio-search',
prefix: 'c-',
});

class AudioSearch extends Component {
constructor(props) {
super(props);
this.state = {
queryObject: this.props.queryObject,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bare props, ikke this.props

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 {
searchPlaceholder,
searchButtonTitle,
fetchAudio,
onError,
} = this.props;

const { queryObject, audios, lastPage, searching } = this.state;

const { page, locale } = queryObject;

return (
<div {...classes()}>
<AudioSearchForm
onSearchQuerySubmit={this.submitAudioSearchQuery}
queryObject={queryObject}
searching={searching}
searchPlaceholder={searchPlaceholder}
searchButtonTitle={searchButtonTitle}
/>
<div {...classes('list')}>
{audios.map(audio =>
<AudioSearchResult
key={audio.id}
audio={audio}
fetchAudio={fetchAudio}
onError={onError}
locale={locale}
/>,
)}
</div>
<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,
searchPlaceholder: PropTypes.string.isRequired,
searchButtonTitle: PropTypes.string.isRequired,
};

export default AudioSearch;
109 changes: 109 additions & 0 deletions packages/ndla-audio-search/src/AudioSearchForm.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
/**
* 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);
this.handleLanguageChange = this.handleLanguageChange.bind(this);
}

onKeyPress(evt) {
if (evt.key === 'Enter') {
this.handleSubmit(evt);
}
}

handleLanguageChange(evt) {
let newQueryObject = {
query: this.state.queryObject.query,
page: this.state.queryObject.page,
pageSize: this.state.queryObject.pageSize,
locale: evt.target.value,
};

this.props.onSearchQuerySubmit(newQueryObject);
this.setState({ queryObject: newQueryObject });
}

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, searchPlaceholder, searchButtonTitle } = this.props;

return (
<div {...classes('form')}>
<select onChange={this.handleLanguageChange}>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tror ikke vi burde ha det her. Dette er noe som bestemmes av locale som blir sendt inn av den frontenden som bruker denne pakken.

<option value="nb"> Norsk - Bokmål </option>
<option value="nn"> Norsk - Nynorsk </option>
<option value="en"> Engelsk </option>
<option value="unknown"> *Ukjent* </option>
</select>
<div>
<input
{...classes('form-query')}
type="text"
onChange={this.handleQueryChange}
onKeyPress={this.onKeyPress}
value={this.state.queryObject.query}
placeholder={searchPlaceholder}
/>
<Button
{...classes('form-button')}
onClick={this.handleSubmit}
loading={searching}>
{searchButtonTitle}
</Button>
</div>
</div>
);
}
}

AudioSearchForm.propTypes = {
queryObject: PropTypes.object,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Proptypes.shape her også.

searching: PropTypes.bool.isRequired,
onSearchQuerySubmit: PropTypes.func.isRequired,
searchPlaceholder: PropTypes.string.isRequired,
searchButtonTitle: PropTypes.string.isRequired,
};

AudioSearchForm.defaultProps = {
query: '',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Er query en prop? Ser den ikke i valideringen i hvertfall

};

export default AudioSearchForm;
Loading