@@ -474,19 +490,24 @@ export class Audioplayer extends Component {
}
}
-const mapStateToProps = (state, ownProps) => ({
- files: state.audioplayer.files[ownProps.chapter.chapterNumber],
- segments: state.audioplayer.segments[ownProps.chapter.chapterNumber],
- currentFile: state.audioplayer.currentFile,
- currentVerse: state.audioplayer.currentVerse,
- chapterId: state.audioplayer.chapterId,
- isPlaying: state.audioplayer.isPlaying,
- isLoadedOnClient: state.audioplayer.isLoadedOnClient,
- isLoading: state.audioplayer.isLoading,
- repeat: state.audioplayer.repeat,
- shouldScroll: state.audioplayer.shouldScroll,
- duration: state.audioplayer.duration,
- currentTime: state.audioplayer.currentTime,
-});
+const mapStateToProps = (state, ownProps) => {
+ const currentVerse = state.audioplayer.currentVerse || ownProps.startVerse.verseKey;
+ const files = state.audioplayer.files[ownProps.chapter.id];
+
+ return {
+ files,
+ currentVerse,
+ segments: state.audioplayer.segments[ownProps.chapter.id],
+ currentFile: files[currentVerse],
+ chapterId: ownProps.chapter.id,
+ isPlaying: state.audioplayer.isPlaying,
+ isLoadedOnClient: state.audioplayer.isLoadedOnClient,
+ isLoading: state.audioplayer.isLoading,
+ repeat: state.audioplayer.repeat,
+ shouldScroll: state.audioplayer.shouldScroll,
+ duration: state.audioplayer.duration,
+ currentTime: state.audioplayer.currentTime,
+ };
+};
export default connect(mapStateToProps, AudioActions)(Audioplayer);
diff --git a/src/components/Verse/index.js b/src/components/Verse/index.js
index 90ef215b1..db93f90a8 100644
--- a/src/components/Verse/index.js
+++ b/src/components/Verse/index.js
@@ -5,6 +5,7 @@ import { connect } from 'react-redux';
import Loadable from 'react-loadable';
import { verseType, matchType, surahType } from 'types';
+import { load as loadAudio } from 'redux/actions/audioplayer';
import ComponentLoader from 'components/ComponentLoader';
import LocaleFormattedMessage from 'components/LocaleFormattedMessage';
import Word from 'components/Word';
@@ -52,7 +53,9 @@ class Verse extends Component {
currentWord: PropTypes.number, // gets passed in an integer, null by default
iscurrentVerse: PropTypes.bool,
currentVerse: PropTypes.string,
- userAgent: PropTypes.func
+ userAgent: PropTypes.func,
+ audio: PropTypes.number.isRequired,
+ loadAudio: PropTypes.func.isRequired
};
@@ -61,6 +64,32 @@ class Verse extends Component {
isSearched: false
};
+ // TODO: Should this belong here?
+ componentDidMount() {
+ const { verse, audio } = this.props;
+
+ this.props.loadAudio({
+ chapterId: verse.chapterId,
+ verseId: verse.id,
+ verseKey: verse.verseKey,
+ audio
+ });
+ }
+
+ // TODO: Should this belong here?
+ componentWillReceiveProps(nextProps) {
+ if (this.props.audio !== nextProps.audio) {
+ const { verse, audio } = nextProps;
+
+ this.props.loadAudio({
+ chapterId: verse.chapterId,
+ verseId: verse.id,
+ verseKey: verse.verseKey,
+ audio
+ });
+ }
+ }
+
shouldComponentUpdate(nextProps) {
const conditions = [
this.props.verse !== nextProps.verse,
@@ -311,6 +340,4 @@ class Verse extends Component {
}
}
-export default connect(state => ({
- userAgent: state.options.userAgent
-}))(Verse);
+export default connect(() => ({}), { loadAudio })(Verse);
diff --git a/src/containers/Surah/index.js b/src/containers/Surah/index.js
index 0067c965b..ba79e2b5d 100644
--- a/src/containers/Surah/index.js
+++ b/src/containers/Surah/index.js
@@ -328,6 +328,8 @@ class Surah extends Component {
isPlaying={isPlaying}
isAuthenticated={isAuthenticated}
key={`${verse.chapterId}-${verse.id}-verse`}
+ userAgent={options.userAgent}
+ audio={options.audio}
/>
));
}
@@ -349,7 +351,7 @@ class Surah extends Component {
}
render() {
- const { chapter, options, actions } = this.props; // eslint-disable-line no-shadow
+ const { chapter, verses, options, actions } = this.props; // eslint-disable-line no-shadow
debug('component:Surah', 'Render');
if (!this.hasAyahs()) return
{this.renderNoAyah()}
;
@@ -409,6 +411,7 @@ class Surah extends Component {