Skip to content
This repository was archived by the owner on Jun 28, 2021. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .env
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
NODE_ENV=development
PORT=8000
API_URL=http://quran.com:3000
API_URL=http://api.quran.com:3000
SEGMENTS_KEY=
SENTRY_KEY_CLIENT=
SENTRY_KEY_SERVER=
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ tests/functional/output/*
test/functional/screenshots/*
.ssh
webpack-stats.debug.json
.env
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, don't need this. We do need .env to be committed

23 changes: 23 additions & 0 deletions src/containers/Error/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import React, { Component } from 'react';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This component is awesome! What I'd recommend, because I assume we'd want to reuse it for other errors, is having :errorTitle be a key to return text given THAT error. For example, /errors/out-of-range would then return 's an invalid Surah/Ayah. Please go to the <a href="/">home page </a>and select a surah' and say /errors/some-other-error would return that text.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is exactly what this component does. Maybe errorTitle isn't exactly the name to use should I use errorText?

import IndexHeader from '../../components/IndexHeader';
import Link from 'react-router/lib/Link';
import Helmet from 'react-helmet';

export default ({params}) => {
console.log(params, 'params?');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✂️

return (
<div>
<Helmet title={`Error ${params.errorTitle}`} />
<IndexHeader noSearch={true} />
<div className="container-fluid about-text">
<div className="row">
<div className="col-md-8 col-md-offset-2">
<h4 className="source-sans">
{params.errorTitle} is an invalid Surah/Ayah. Please go to the <a href="/">home page </a>and select a surah
</h4>
</div>
</div>
</div>
</div>
);
}
8 changes: 8 additions & 0 deletions src/containers/Home/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,14 @@ class Home extends React.Component {
Ayat Al-Kursi
</Link>
</li>
<li>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✂️ ✂️ ✂️ ✂️ ✂️ ✂️ ✂️ This link is invalid :)

<Link
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✂️

to="/884843948389"
data-metrics-event-name="QuickLinks:Click"
data-metrics-surah-id="2/255">
Ayat Al-Kursi
</Link>
</li>
</ul>
</span>
);
Expand Down
8 changes: 7 additions & 1 deletion src/containers/Surah/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,13 @@ export default class Surah extends Component {
state = {
lazyLoading: false
};

componentWillMount() {
const {params, surah, push } = this.props;
let start = parseInt(params.range.split('-')[0], 10);
if(start > surah.ayat || isNaN(start)){
return push(`/error/${params.range}`);
}
}
componentDidMount() {
if (__CLIENT__) {
window.removeEventListener('scroll', this.handleNavbar, true);
Expand Down
8 changes: 6 additions & 2 deletions src/routes.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import React from 'react';
import IndexRoute from 'react-router/lib/IndexRoute';
import Route from 'react-router/lib/Route';

import checkValidSurah from './utils/checkValidSurah';
import App from './containers/App';



export default () => {
return (
<Route path="/" component={App}>
Expand All @@ -16,10 +18,12 @@ export default () => {

<Route path="/contact" getComponent={(nextState, cb) => System.import('./containers/Contact').then(module => cb(null, module))} />
<Route path="/contactus" getComponent={(nextState, cb) => System.import('./containers/Contact').then(module => cb(null, module))} />
<Route path="/error/:errorTitle" getComponent={(nextState, cb) => System.import('./containers/Error').then(module => cb(null, module))} />

<Route path="/search" getComponent={(nextState, cb) => System.import('./containers/Search').then(module => cb(null, module))} />

<Route path="/:surahId(/:range)" getComponent={(nextState, cb) => System.import('./containers/Surah').then(module => cb(null, module)).catch(err => console.trace(err))} />
<Route path="/:surahId(/:range)" getComponent={(nextState, cb) => System.import('./containers/Surah').then(module => cb(null, module)).catch(err => console.trace(err))}
onEnter={checkValidSurah} />
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice!

</Route>
);
}
7 changes: 7 additions & 0 deletions src/utils/checkValidSurah.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export default function isValidSurah(nextState, replaceState) {
let surahId = parseInt(nextState.params.surahId, 10)
if(isNaN(surahId) || surahId > 114 || surahId < 1){

replaceState(`/error/${nextState.params.surahId}`);
}
}