Skip to content
This repository has been archived by the owner on Jun 28, 2021. It is now read-only.

Commit

Permalink
Fixes #681 API calls for reciter (#694)
Browse files Browse the repository at this point in the history
  • Loading branch information
mmahalwy authored Mar 19, 2017
1 parent 2bff754 commit 1fc9bb8
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 21 deletions.
37 changes: 19 additions & 18 deletions src/components/ContentDropdown/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,24 +29,24 @@ const compareAlphabetically = property =>
class ContentDropdown extends Component {
static propTypes = {
onOptionChange: PropTypes.func.isRequired,
content: PropTypes.arrayOf(PropTypes.number).isRequired,
translations: PropTypes.arrayOf(contentType),
translations: PropTypes.arrayOf(PropTypes.number).isRequired,
translationOptions: PropTypes.arrayOf(contentType),
loadTranslations: PropTypes.func.isRequired,
className: PropTypes.string
};

componentDidMount() {
if (!this.props.translations.length) {
if (!this.props.translationOptions.length) {
return this.props.loadTranslations();
}

return false;
}

getTitle() {
const { translations, content } = this.props;
const { translationOptions, translations } = this.props;

return translations.filter(slug => content.includes(slug.id)).map((slug) => {
return translationOptions.filter(slug => translations.includes(slug.id)).map((slug) => {
if (slug.languageName === 'English') return slug.authorName;

return slug.languageName;
Expand All @@ -56,24 +56,24 @@ class ContentDropdown extends Component {
handleRemoveContent = () => {
const { onOptionChange } = this.props;

onOptionChange({ content: [] });
onOptionChange({ translations: [] });
}

handleOptionSelected(id) {
const { onOptionChange, content } = this.props;
const { onOptionChange, translations } = this.props;

if (content.find(option => option === id)) {
onOptionChange({ content: content.filter(option => option !== id) });
if (translations.find(option => option === id)) {
onOptionChange({ translations: translations.filter(option => option !== id) });
} else {
onOptionChange({ content: [...content, id] });
onOptionChange({ translations: [...translations, id] });
}
}

renderItems(items, key) {
const { content } = this.props;
const { translations } = this.props;

return items.map((translation) => {
const checked = content.find(option => option === translation.id);
const checked = translations.find(option => option === translation.id);

return (
<li key={translation.id} className={style.item}>
Expand All @@ -94,23 +94,23 @@ class ContentDropdown extends Component {
}

renderEnglishList() {
const list = this.props.translations
const list = this.props.translationOptions
.filter(translation => translation.languageName === 'English')
.sort(compareAlphabetically('authorName'));

return this.renderItems(list, 'authorName');
}

renderLanguagesList() {
const list = this.props.translations
const list = this.props.translationOptions
.filter(translation => translation.languageName !== 'English')
.sort(compareAlphabetically('languageName'));

return this.renderItems(list, 'languageName');
}

render() {
const { className, content } = this.props;
const { className, translations } = this.props;

return (
<ButtonToolbar>
Expand All @@ -121,7 +121,7 @@ class ContentDropdown extends Component {
title={this.getTitle()}
>
{
content.length &&
translations && translations.length &&
<MenuItem onClick={this.handleRemoveContent}>
<LocaleFormattedMessage id="setting.translations.removeAll" defaultMessage="Remove all" />
</MenuItem>
Expand All @@ -142,6 +142,7 @@ class ContentDropdown extends Component {
}

export default connect(state => ({
translations: state.options.options.translations,
loadingTranslations: state.options.loadingTranslations
translationOptions: state.options.options.translations,
loadingTranslations: state.options.loadingTranslations,
translations: state.options.translations
}), { loadTranslations })(ContentDropdown);
3 changes: 2 additions & 1 deletion src/components/ReciterDropdown/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,5 +66,6 @@ class ReciterDropdown extends Component {

export default connect(state => ({
recitations: state.options.options.recitations,
loadingRecitations: state.options.loadingRecitations
loadingRecitations: state.options.loadingRecitations,
audio: state.options.audio
}), { loadRecitations })(ReciterDropdown);
2 changes: 0 additions & 2 deletions src/components/SettingsModal/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ const SettingsModal = ({
</h5>
<ReciterDropdown
onOptionChange={handleOptionChange}
audio={options.audio}
/>
</div>
<div className="form-group">
Expand All @@ -57,7 +56,6 @@ const SettingsModal = ({
</h5>
<ContentDropdown
onOptionChange={handleOptionChange}
content={options.content}
/>
</div>
<div className="form-group">
Expand Down

0 comments on commit 1fc9bb8

Please sign in to comment.