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

Commit

Permalink
#383 Ayah Play Audio + Redux Refactoring (WIP) (#390)
Browse files Browse the repository at this point in the history
* #383 refactoring how redux actions and fixing ayah play (WIP)

* 383 lint-roller :bowtie:

* #383 refactor out decorators.

* #383 hide play from search results.

* #371 lint-roller :bowtie:

* #371 :scissors

* #371 ✂️
  • Loading branch information
thabti authored and mmahalwy committed Jul 10, 2016
1 parent fb35d4f commit c2c1e64
Show file tree
Hide file tree
Showing 6 changed files with 149 additions and 126 deletions.
21 changes: 12 additions & 9 deletions src/components/Ayah/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,13 @@ export default class Ayah extends Component {
isSearch: PropTypes.bool,
tooltip: PropTypes.string,
currentWord: PropTypes.any, // gets passed in an integer, null by default
onWordClick: PropTypes.func.isRequired
onWordClick: PropTypes.func,
actions: PropTypes.object
};

static defaultProps = {
currentWord: null,
isSearched: false,
isSearched: false
};

shouldComponentUpdate(nextProps) {
Expand All @@ -44,10 +45,12 @@ export default class Ayah extends Component {
return conditions.some(condition => condition);
}

handlePlay() {
this.setState({
open: false
});
handlePlay(ayah) {
const {stop, setAyah, start} = this.props.actions;

stop();
setAyah(ayah);
start();
}

renderTranslations() {
Expand Down Expand Up @@ -140,12 +143,12 @@ export default class Ayah extends Component {
}

renderPlayLink() {
const { isSearch, ayah } = this.props;
const { isSearched, ayah } = this.props;

if (!isSearch) {
if (!isSearched) {
return (
<a
onClick={() => this.handlePlay(ayah.ayahNum)}
onClick={() => this.handlePlay(ayah.ayahKey)}
className="text-muted"
>
<i className="ss-icon ss-play" /> Play
Expand Down
12 changes: 5 additions & 7 deletions src/containers/App/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,7 @@ import FontStyles from 'components/FontStyles';

const styles = require('./style.scss');

@metrics(metricsConfig)
@connect(
state => ({
surahs: state.surahs.entities
})
)
export default class App extends Component {
class App extends Component {
static propTypes = {
surahs: PropTypes.object,
children: PropTypes.any
Expand Down Expand Up @@ -107,3 +101,7 @@ export default class App extends Component {
);
}
}

const metricsApp = metrics(metricsConfig)(App);

export default connect(state => ({surahs: state.surahs.entities }))(metricsApp);
25 changes: 12 additions & 13 deletions src/containers/Home/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,6 @@ import { isAllLoaded, loadAll } from '../../redux/modules/surahs';

const styles = require('./style.scss');

@asyncConnect([{
promise({ store: { getState, dispatch } }) {
if (!isAllLoaded(getState())) {
return dispatch(loadAll());
}

return true;
}
}])
@connect(
state => ({surahs: state.surahs.entities})
)
class Home extends Component {
static propTypes = {
lastVisit: PropTypes.any,
Expand Down Expand Up @@ -189,4 +177,15 @@ class Home extends Component {
}
}

export default Home;
const AsyncHome = asyncConnect([{
promise({ store: { getState, dispatch } }) {
if (!isAllLoaded(getState())) {
return dispatch(loadAll());
}

return true;
}
}])(Home);

export default connect(state => ({surahs: state.surahs.entities}))(AsyncHome);

48 changes: 26 additions & 22 deletions src/containers/Search/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React, { Component, PropTypes } from 'react';
import { PropTypes as MetricsPropTypes } from 'react-metrics';

import { asyncConnect } from 'redux-connect';
import { connect } from 'react-redux';
import { push } from 'react-router-redux';
Expand All @@ -19,28 +20,7 @@ import { search } from '../../redux/modules/searchResults';

const style = require('./style.scss');

@asyncConnect([{
promise({ store: { dispatch }, location: { query } }) {
return dispatch(search(query));
}
}])
@connect(
state => ({
isErrored: state.searchResults.errored,
isLoading: state.searchResults.loading,
total: state.searchResults.total,
page: state.searchResults.page,
size: state.searchResults.size,
from: state.searchResults.from,
took: state.searchResults.took,
query: state.searchResults.query,
results: state.searchResults.results,
ayahs: state.searchResults.entities,
options: state.options
}),
{ push }
)
export default class Search extends Component {
class Search extends Component {
static propTypes = {
isErrored: PropTypes.bool,
isLoading: PropTypes.bool,
Expand Down Expand Up @@ -177,3 +157,27 @@ export default class Search extends Component {
);
}
}

const AsyncSearch = asyncConnect([{
promise({ store: { dispatch }, location: { query } }) {
return dispatch(search(query));
}
}])(Search);

function mapStateToProps(state) {
return {
isErrored: state.searchResults.errored,
isLoading: state.searchResults.loading,
total: state.searchResults.total,
page: state.searchResults.page,
size: state.searchResults.size,
from: state.searchResults.from,
took: state.searchResults.took,
query: state.searchResults.query,
results: state.searchResults.results,
ayahs: state.searchResults.entities,
options: state.options
};
}

export default connect(mapStateToProps, {push})(AsyncSearch);
Loading

0 comments on commit c2c1e64

Please sign in to comment.