From 068e8968bde22ca90c74310eec6f141182a318c6 Mon Sep 17 00:00:00 2001 From: mahmoudfelfel Date: Sat, 7 Sep 2019 14:54:31 +0400 Subject: [PATCH 1/5] minor linting and styling fixes --- .eslintrc | 12 +- api/routes/audio_files.js | 24 ++-- api/routes/qaris.js | 72 +++++------ api/routes/surahs.js | 47 ++++---- api/tasks/addAudioData.js | 17 ++- api/utils/url.js | 17 ++- package.json | 8 +- src/actions/qaris.js | 2 +- src/actions/sections.js | 2 +- src/actions/surahs.js | 2 +- src/components/Audioplayer/MobilePlayer.js | 8 +- src/components/Audioplayer/index.js | 4 +- src/components/SurahList/index.js | 132 +++++++++++---------- src/containers/App/index.js | 12 +- src/containers/Main/download.js | 14 ++- src/containers/Qari/Sura.js | 23 ++-- src/helpers/ApiClient.js | 42 +++---- src/helpers/Html.js | 17 +-- src/server.js | 3 +- src/utils/scroll.js | 1 - 20 files changed, 254 insertions(+), 205 deletions(-) diff --git a/.eslintrc b/.eslintrc index c274c27..da29fad 100644 --- a/.eslintrc +++ b/.eslintrc @@ -2,7 +2,8 @@ "env": { "browser": true, "node": true, - "mocha": true + "mocha": true, + "es6": true }, "rules": { "react/no-multi-comp": 0, @@ -15,7 +16,10 @@ "comma-dangle": 0, // not sure why airbnb turned this on. gross! "indent": [2, 2, {"SwitchCase": 1}], "no-console": 0, - "no-alert": 0 + "no-alert": 0, + "no-empty-label": 0, + "space-after-keywords": 0, + "space-return-throw-case": 0 }, "plugins": [ "react", "import" @@ -34,5 +38,9 @@ "__DEVTOOLS__": true, "socket": true, "webpackIsomorphicTools": true + }, + "parserOptions" : { + "ecmaVersion": 6, + "sourceType": "module", } } diff --git a/api/routes/audio_files.js b/api/routes/audio_files.js index 0bd4ba2..d09f2b8 100644 --- a/api/routes/audio_files.js +++ b/api/routes/audio_files.js @@ -12,25 +12,25 @@ router.get('/', (req, res) => { }); router.get('/:id', (req, res) => { - if (req.params.id) { - return models.audioFile - .findById(req.params.id) - .then(files => res.send(files)) - .catch(error => res.status(500).send({ error })); + if (!req.params.id) { + res.status(500).send({ error: 'missing or invalid id' }); } - res.status(500).send({ error: 'missing or invalid id' }); + models.audioFile + .findById(req.params.id) + .then(files => res.send(files)) + .catch(error => res.status(500).send({ error })); }); router.get('/download/:id', (req, res) => { - if (req.params.id) { - return models.audioFile - .findOne({ where: { id: req.params.id, extension: 'mp3' } }) - .then(files => res.send(files)) - .catch(error => res.status(500).send({ error })); + if (!req.params.id) { + res.status(500).send({ error: 'missing or invalid id' }); } - res.status(500).send({ error: 'missing or invalid id' }); + models.audioFile + .findOne({ where: { id: req.params.id, extension: 'mp3' } }) + .then(files => res.send(files)) + .catch(error => res.status(500).send({ error })); }); export default router; diff --git a/api/routes/qaris.js b/api/routes/qaris.js index 614dd61..b5f6676 100644 --- a/api/routes/qaris.js +++ b/api/routes/qaris.js @@ -20,56 +20,58 @@ router.get('/audio_files', (req, res) => { }); router.get('/:id', (req, res) => { - if (req.params.id) { - return models.qari - .findById(req.params.id) - .then(qari => res.send(qari)) - .catch(error => res.status(500).send({ error })); + if (!req.params.id) { + res.status(500).send({ error: 'missing or invalid id' }); } - res.status(500).send({ error: 'missing or invalid id' }); + models.qari + .findById(req.params.id) + .then(qari => res.send(qari)) + .catch(error => res.status(500).send({ error })); }); router.get('/:id/audio_files', (req, res) => { - if (req.params.id) { - return models.qari - .findById(req.params.id) - .then(qari => { - return qari - .getAudioFiles({ order: 'surah_id' }) - .then(files => res.send(files)); - }) - .catch(error => res.status(500).send({ error })); + if (!req.params.id) { + res.status(500).send({ error: 'missing or invalid id' }); } - res.status(500).send({ error: 'missing or invalid id' }); + models.qari + .findById(req.params.id) + .then(qari => { + return qari + .getAudioFiles({ order: 'surah_id' }) + .then(files => res.send(files)); + }) + .catch(error => res.status(500).send({ error })); }); router.get('/:id/audio_files/:type', (req, res) => { - if (req.params.id) { - return models.qari - .findById(req.params.id) - .then(qari => { - return qari - .getAudioFiles({ - order: 'surah_id', - where: { extension: req.params.type } - }) - .then(files => res.send(files)); - }) - .catch(error => res.status(500).send({ error })); + if (!req.params.id) { + res.status(500).send({ error: 'missing or invalid id' }); } - res.status(500).send({ error: 'missing or invalid id' }); + + models.qari + .findById(req.params.id) + .then(qari => { + return qari + .getAudioFiles({ + order: 'surah_id', + where: { extension: req.params.type } + }) + .then(files => res.send(files)); + }) + .catch(error => res.status(500).send({ error })); }); router.get('/related/:id', (req, res) => { - if (req.params.id) { - return models.related - .findAll({ where: { qari: req.params.id } }) - .then(related => res.send(related)) - .catch(error => res.status(500).send({ error })); + if (!req.params.id) { + res.status(500).send({ error: 'missing or invalid id' }); } - res.status(500).send({ error: 'missing or invalid id' }); + + models.related + .findAll({ where: { qari: req.params.id } }) + .then(related => res.send(related)) + .catch(error => res.status(500).send({ error })); }); export default router; diff --git a/api/routes/surahs.js b/api/routes/surahs.js index d997844..2c91581 100644 --- a/api/routes/surahs.js +++ b/api/routes/surahs.js @@ -13,37 +13,40 @@ router.get('/', (req, res) => { }); router.get('/:id', (req, res) => { - if (req.params.id) { - return models.surah - .findById(req.params.id) - .then(surah => res.send(surah)) - .catch(error => res.status(500).send({ error })); + if (!req.params.id) { + res.status(500).send({ error: 'missing or invalid id' }); } - res.status(500).send({ error: 'missing or invalid id' }); + + models.surah + .findById(req.params.id) + .then(surah => res.send(surah)) + .catch(error => res.status(500).send({ error })); }); router.get('/:id/audio_files', (req, res) => { - if (req.params.id) { - return models.surah - .findById(req.params.id) - .then(surah => { - return surah.getAudioFiles().then(files => res.send(files)); - }) - .catch(error => res.status(500).send({ error })); + if (!req.params.id) { + res.status(500).send({ error: 'missing or invalid id' }); } - res.status(500).send({ error: 'missing or invalid id' }); + + models.surah + .findById(req.params.id) + .then(surah => { + return surah.getAudioFiles().then(files => res.send(files)); + }) + .catch(error => res.status(500).send({ error })); }); router.get('/:id/qaris', (req, res) => { - if (req.params.id) { - return models.surah - .findById(req.params.id) - .then(surah => { - surah.getQaris().then(qaris => res.send(qaris)); - }) - .catch(error => res.status(500).send({ error })); + if (!req.params.id) { + res.status(500).send({ error: 'missing or invalid id' }); } - res.status(500).send({ error: 'missing or invalid id' }); + + return models.surah + .findById(req.params.id) + .then(surah => { + surah.getQaris().then(qaris => res.send(qaris)); + }) + .catch(error => res.status(500).send({ error })); }); export default router; diff --git a/api/tasks/addAudioData.js b/api/tasks/addAudioData.js index f0d3c38..e4563eb 100644 --- a/api/tasks/addAudioData.js +++ b/api/tasks/addAudioData.js @@ -5,7 +5,9 @@ const createData = (files, index) => { const file = files[index]; if (file.qari && (!file.format || !file.metadata)) { - const url = `https://download.quranicaudio.com/quran/${file.qari.relative_path}${file.file_name}`; + const url = `https://download.quranicaudio.com/quran/${ + file.qari.relative_path + }${file.file_name}`; try { return probe(url, (err, data) => { file.metadata = data.metadata; @@ -18,8 +20,15 @@ const createData = (files, index) => { console.warn(error); } } + + return null; }; -models.audioFile.all({ where: {extension: 'mp3', metadata: null, format: null}, include: [models.qari] }).then(files => { - return createData(files, 0); -}); +models.audioFile + .all({ + where: { extension: 'mp3', metadata: null, format: null }, + include: [models.qari] + }) + .then(files => { + return createData(files, 0); + }); diff --git a/api/utils/url.js b/api/utils/url.js index cd913bf..939a9b1 100644 --- a/api/utils/url.js +++ b/api/utils/url.js @@ -1,5 +1,5 @@ export function mapUrl(availableActions = {}, url = []) { - const notFound = {action: null, params: []}; + const notFound = { action: null, params: [] }; // test for empty input if (url.length === 0 || Object.keys(availableActions).length === 0) { @@ -8,18 +8,23 @@ export function mapUrl(availableActions = {}, url = []) { /*eslint-disable */ const reducer = (prev, current) => { if (prev.action && prev.action[current]) { - return {action: prev.action[current], params: []}; // go deeper + return { action: prev.action[current], params: [] }; // go deeper } else { if (typeof prev.action === 'function') { - return {action: prev.action, params: prev.params.concat(current)}; // params are found + return { action: prev.action, params: prev.params.concat(current) }; // params are found } else { return notFound; } } }; - /*eslint-enable */ + /* eslint-enable */ - const actionAndParams = url.reduce(reducer, {action: availableActions, params: []}); + const actionAndParams = url.reduce(reducer, { + action: availableActions, + params: [] + }); - return (typeof actionAndParams.action === 'function') ? actionAndParams : notFound; + return typeof actionAndParams.action === 'function' + ? actionAndParams + : notFound; } diff --git a/package.json b/package.json index 7cbf0f3..d3d5430 100644 --- a/package.json +++ b/package.json @@ -45,7 +45,7 @@ "env": { "NODE_PATH": "./src", "NODE_ENV": "production", - "PORT": 8080, + "PORT": 8000, "APIPORT": 8080 } }, @@ -169,11 +169,13 @@ "chai": "^3.3.0", "concurrently": "^0.1.1", "prettier": "^1.15.2", - "eslint": "1.10.3", + "escope": "^3.6.0", + "eslint": "4.18.2", "eslint-config-airbnb": "0.1.0", "eslint-loader": "^1.0.0", "eslint-plugin-import": "^0.8.0", "eslint-plugin-react": "^3.5.0", + "estraverse-fb": "^1.3.2", "font-awesome": "^4.4.0", "font-awesome-webpack": "0.0.4", "husky": "^0.13.3", @@ -212,4 +214,4 @@ "engines": { "node": "^10.13.0" } -} \ No newline at end of file +} diff --git a/src/actions/qaris.js b/src/actions/qaris.js index 1efe68a..89d2897 100644 --- a/src/actions/qaris.js +++ b/src/actions/qaris.js @@ -8,7 +8,7 @@ export function loadAll() { return { types: [LOAD, LOAD_SUCCESS, LOAD_FAIL], schema: arrayOf(qarisSchema), - promise: client => client.get(`/qaris`) + promise: client => client.get('/qaris') }; } diff --git a/src/actions/sections.js b/src/actions/sections.js index 83cb518..1d74601 100644 --- a/src/actions/sections.js +++ b/src/actions/sections.js @@ -9,6 +9,6 @@ export function loadAll() { return { types: [LOAD, LOAD_SUCCESS, LOAD_FAIL], schema: arrayOf(sectionsSchema), - promise: client => client.get(`/sections`) + promise: client => client.get('/sections') }; } diff --git a/src/actions/surahs.js b/src/actions/surahs.js index e4e3e85..30a55c5 100644 --- a/src/actions/surahs.js +++ b/src/actions/surahs.js @@ -9,7 +9,7 @@ export function loadAll() { return { types: [LOAD, LOAD_SUCCESS, LOAD_FAIL], schema: arrayOf(surahsSchema), - promise: client => client.get(`/surahs`) + promise: client => client.get('/surahs') }; } diff --git a/src/components/Audioplayer/MobilePlayer.js b/src/components/Audioplayer/MobilePlayer.js index b68abf6..72e9d31 100644 --- a/src/components/Audioplayer/MobilePlayer.js +++ b/src/components/Audioplayer/MobilePlayer.js @@ -92,7 +92,9 @@ class MobilePlayer extends Component { if (file.readyState < 4) { return ( ); } @@ -147,7 +149,7 @@ class MobilePlayer extends Component { return (
-
@@ -159,7 +161,7 @@ class MobilePlayer extends Component { return (
-
diff --git a/src/components/Audioplayer/index.js b/src/components/Audioplayer/index.js index 1a80abd..9a22866 100644 --- a/src/components/Audioplayer/index.js +++ b/src/components/Audioplayer/index.js @@ -146,7 +146,7 @@ class Audioplayer extends Component { styles.active}`} > -