-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #58 from sabeurthabti/feature/56
support for legacy /download path.
- Loading branch information
Showing
11 changed files
with
144 additions
and
9 deletions.
There are no files selected for viewing
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
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
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,12 @@ | ||
export const LOAD = '@@quran/download/LOAD'; | ||
export const LOAD_SUCCESS = '@@quran/download/LOAD_SUCCESS'; | ||
export const LOAD_FAIL = '@@quran/download/LOAD_FAIL'; | ||
|
||
export function load(id) { | ||
console.log('download ', id); | ||
return { | ||
types: [LOAD, LOAD_SUCCESS, LOAD_FAIL], | ||
promise: (client) => client.get(`/audio_files/download/${id}`), | ||
id | ||
}; | ||
} |
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
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,56 @@ | ||
import React, { PropTypes, Component } from 'react'; | ||
import Grid from 'react-bootstrap/lib/Grid'; | ||
import Row from 'react-bootstrap/lib/Row'; | ||
import Col from 'react-bootstrap/lib/Col'; | ||
import Header from '../../components/Header'; | ||
import { connect } from 'react-redux'; | ||
import { asyncConnect } from 'redux-connect'; | ||
import { load } from 'actions/download'; | ||
import zeroPad from 'utils/zeroPad'; | ||
|
||
const styles = require('./style.scss'); | ||
|
||
class Download extends Component { | ||
|
||
static propTypes = { | ||
qaris: PropTypes.object.isRequired, | ||
surahs: PropTypes.object.isRequired, | ||
data: PropTypes.object.isRequired | ||
} | ||
|
||
render() { | ||
const { surahs, data, qaris} = this.props; | ||
const { surahId, qariId } = data; | ||
return ( | ||
<div> | ||
<Header /> | ||
<Grid> | ||
<Row className={styles.aboutContainer}> | ||
<Col md={8} mdOffset={2}> | ||
{data.loaded ? <Row> | ||
<h1>Surat {surahs[surahId].name.simple} by {qaris[qariId].name}</h1> | ||
<a className={styles.downloadLink} href={`http://download.quranicaudio.com/quran/${qaris[qariId].relativePath}${zeroPad(surahId, 3)}.mp3`}>Download</a> | ||
</Row> : <h1>Not Found</h1>} | ||
</Col> | ||
</Row> | ||
</Grid> | ||
</div> | ||
); | ||
} | ||
} | ||
|
||
const connectedDownload = connect( | ||
state => ({ | ||
qaris: state.qaris.entities, | ||
surahs: state.surahs.entities, | ||
sections: state.sections.entities, | ||
data: state.download | ||
}) | ||
)(Download); | ||
|
||
|
||
export default asyncConnect([{ | ||
promise({ params, store: { dispatch } }) { | ||
return dispatch(load(params.id)); | ||
} | ||
}])(connectedDownload); |
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
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
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,41 @@ | ||
import { | ||
LOAD, | ||
LOAD_SUCCESS, | ||
LOAD_FAIL | ||
} from 'actions/download'; | ||
|
||
const initialState = { | ||
errored: false, | ||
loaded: false, | ||
entities: {} | ||
}; | ||
|
||
export default function reducer(state = initialState, action = {}) { | ||
switch (action.type) { | ||
case LOAD: | ||
return { | ||
...state, | ||
loaded: false, | ||
loading: true | ||
}; | ||
case LOAD_FAIL: | ||
return { | ||
...state, | ||
loaded: false, | ||
errored: true, | ||
}; | ||
case LOAD_SUCCESS: | ||
|
||
return { | ||
...state, | ||
loaded: true, | ||
errored: false, | ||
entities: { | ||
...state.entities, | ||
}, | ||
...action.result | ||
}; | ||
default: | ||
return state; | ||
} | ||
} |
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
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
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