Skip to content
This repository was archived by the owner on Jun 28, 2021. It is now read-only.
Prev Previous commit
Next Next commit
fix surah
  • Loading branch information
mmahalwy committed Feb 12, 2017
commit 30f7260d8d45f5ecd2cfd4afe55d6d706599b33a
12 changes: 6 additions & 6 deletions src/containers/App/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { asyncConnect } from 'redux-connect';
import Helmet from 'react-helmet';
import Modal from 'react-bootstrap/lib/Modal';
import SmartBanner from 'components/SmartBanner';
// import GlobalNav from 'components/GlobalNav';
import GlobalNav from 'components/GlobalNav';
import GlobalSidebar from 'components/GlobalSidebar';

import debug from 'helpers/debug';
Expand All @@ -31,7 +31,7 @@ class App extends Component {
removeMedia: PropTypes.func.isRequired,
children: PropTypes.element,
main: PropTypes.element,
// nav: PropTypes.element,
nav: PropTypes.element,
sidebar: PropTypes.element,
};

Expand All @@ -46,12 +46,12 @@ class App extends Component {
render() {
const {
main,
// nav,
nav,
sidebar,
children,
media,
removeMedia, // eslint-disable-line no-shadow
// ...props
...props
} = this.props;
debug('component:APPLICATION', 'Render');

Expand All @@ -74,12 +74,12 @@ class App extends Component {
</div>
</NoScript>
{
/* React.cloneElement(
React.cloneElement(
nav || <GlobalNav isStatic {...props} />,
{
handleSidebarToggle: () => this.setState({ sidebarOpen: !this.state.sidebarOpen })
}
) */
)
}
{
React.cloneElement(
Expand Down
18 changes: 9 additions & 9 deletions src/containers/Surah/connect.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,18 @@ export const surahsConnect = ({ store: { getState, dispatch } }) => {

export const surahInfoConnect = ({ store: { dispatch }, params }) => {
if (__CLIENT__) {
dispatch(loadInfo(params.surahId));
dispatch(loadInfo(params.chapterId));
return true;
}

return dispatch(loadInfo(params.surahId));
return dispatch(loadInfo(params.chapterId));
};

export const ayahsConnect = ({ store: { dispatch, getState }, params }) => {
debug('component:Surah:ayahsConnect', 'Init');

const range = params.range;
const surahId = parseInt(params.surahId, 10);
const chapterId = parseInt(params.chapterId, 10);

let from;
let to;
Expand All @@ -70,21 +70,21 @@ export const ayahsConnect = ({ store: { dispatch, getState }, params }) => {
from = parseInt(from, 10);
to = parseInt(to, 10);

if (surahId !== getState().surahs.current) {
dispatch(setCurrentSurah(surahId));
if (chapterId !== getState().chapters.current) {
dispatch(setCurrentSurah(chapterId));
}

if (!isLoaded(getState(), surahId, from, to)) {
if (!isLoaded(getState(), chapterId, from, to)) {
debug('component:Surah:ayahsConnect', 'Not loaded');

dispatch(clearCurrent(surahId)); // In the case where you go to same surah but later ayahs.
dispatch(clearCurrent(chapterId)); // In the case where you go to same surah but later ayahs.

if (__CLIENT__) {
dispatch(loadAyahs(surahId, from, to, getState().options));
dispatch(loadAyahs(chapterId, from, to, getState().options));
return true;
}

return dispatch(loadAyahs(surahId, from, to, getState().options));
return dispatch(loadAyahs(chapterId, from, to, getState().options));
}

return true;
Expand Down
4 changes: 2 additions & 2 deletions src/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,10 @@ export default (store) => {
<Route path="/profile" getComponent={(nextState, cb) => System.import('./containers/Profile').then(module => cb(null, module.default)).catch(err => console.trace(err))} />
</Route>

<Redirect from="/:surahId:(:range)" to="/:surahId(/:range)" />
<Redirect from="/:chapterId:(:range)" to="/:chapterId(/:range)" />

<Route
path="/:surahId(/:range)"
path="/:chapterId(/:range)"
getComponents={(nextState, cb) =>
Promise.all([
System.import('./containers/Surah'),
Expand Down
18 changes: 5 additions & 13 deletions src/types/surahType.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,12 @@ import { PropTypes } from 'react';

export default PropTypes.shape({
id: PropTypes.number.isRequired,
ayat: PropTypes.number.isRequired,
versesCount: PropTypes.number.isRequired,
bismillahPre: PropTypes.bool.isRequired,
revelationOrder: PropTypes.number.isRequired,
revelationPlace: PropTypes.string.isRequired,
page: PropTypes.array.isRequired,
name: PropTypes.shape({
complex: PropTypes.string.isRequired,
simple: PropTypes.string.isRequired,
english: PropTypes.string.isRequired,
arabic: PropTypes.string.isRequired,
}).isRequired,
revelation: PropTypes.shape({
order: PropTypes.number,
place: PropTypes.string
}).isRequired,
id: PropTypes.number.isRequired,
pages: PropTypes.arrayOf(PropTypes.number).isRequired,
nameComplex: PropTypes.string.isRequired,
nameSimple: PropTypes.string.isRequired,
nameArabic: PropTypes.string.isRequired,
});
9 changes: 5 additions & 4 deletions src/utils/checkValidSurah.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
export default function isValidSurah(nextState, replaceState) {
const surahId = parseInt(nextState.params.surahId, 10);
const chapterId = parseInt(nextState.params.chapterId, 10);

if (isNaN(surahId) || surahId > 114 || surahId < 1) {
if (isNaN(chapterId) || chapterId > 114 || chapterId < 1) {
replaceState('/error/invalid-surah');
}

if (nextState.params.range) {
if (nextState.params.range.includes('-')) {
const [from, to] = nextState.params.range.split('-').map(num => parseInt(num, 10));

if (from > to) {
replaceState(`/${surahId}/${to}-${from}`);
replaceState(`/${chapterId}/${to}-${from}`);
} else if (from === to) {
replaceState(`/${surahId}/${from}`);
replaceState(`/${chapterId}/${from}`);
}
// TODO: Add check to make sure the range is within the ayah limit
}
Expand Down