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 server.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import debug from './src/helpers/debug';

import Html from './src/helpers/Html';

import { setUserAgent } from './src/redux/modules/audioplayer';
import { setUserAgent } from './src/redux/actions/AudioPlayerActions.js';
import { setOption } from './src/redux/modules/options';

// Use varnish for the static routes, which will cache too
Expand Down
2 changes: 1 addition & 1 deletion src/components/Audioplayer/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { connect } from 'react-redux';
import { camelize } from 'humps';

// Redux
import * as AudioActions from '../../redux/modules/audioplayer';
import * as AudioActions from '../../redux/actions/AudioPlayerActions';

// Components
import Track from './Track';
Expand Down
2 changes: 1 addition & 1 deletion src/containers/Home/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { connect } from 'react-redux';

import debug from '../../helpers/debug';

import { isAllLoaded, loadAll } from '../../redux/modules/surahs';
import { isAllLoaded, loadAll } from '../../redux/actions/SurahsActions.js';

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

Expand Down
4 changes: 2 additions & 2 deletions src/containers/Surah/connect.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { isAllLoaded, loadAll, setCurrent as setCurrentSurah } from '../../redux/modules/surahs';
import { clearCurrent, isLoaded, load as loadAyahs } from '../../redux/modules/ayahs';
import { isAllLoaded, loadAll, setCurrent as setCurrentSurah } from '../../redux/actions/SurahsActions.js';
import { clearCurrent, isLoaded, load as loadAyahs } from '../../redux/actions/AyahsActions.js';

import debug from 'helpers/debug';

Expand Down
4 changes: 2 additions & 2 deletions src/containers/Surah/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ import descriptions from './descriptions';

import { surahsConnect, ayahsConnect } from './connect';

import * as AudioActions from '../../redux/modules/audioplayer';
import * as AyahActions from '../../redux/modules/ayahs';
import * as AudioActions from '../../redux/actions/AudioPlayerActions.js';
import * as AyahActions from '../../redux/actions/AyahsActions.js';
import * as OptionsActions from '../../redux/modules/options';

const style = require('./style.scss');
Expand Down
95 changes: 95 additions & 0 deletions src/redux/actions/AudioPlayerActions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
import {
SET_USER_AGENT,
SET_CURRENT_FILE,
SET_CURRENT_WORD,
PLAY,
PAUSE,
NEXT,
SET_AYAH,
PREVIOUS,
SET_REPEAT,
TOGGLE_SCROLL,
BUILD_ON_CLIENT,
UPDATE
} from '../constants/AudioPlayerActionTypes.js';
Copy link
Contributor

Choose a reason for hiding this comment

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

AudioPlayerActionTypes Why camel cased?


export function setUserAgent(userAgent) {
return {
type: SET_USER_AGENT,
userAgent
};
}

export function setCurrentFile(file) {
return {
type: SET_CURRENT_FILE,
file
};
}

export function setCurrentWord(word) {
return {
type: SET_CURRENT_WORD,
word
};
}

export function play() {
return {
type: PLAY
};
}

export function pause() {
return {
type: PAUSE
};
}

export function next(currentAyah) {
return {
type: NEXT,
currentAyah
};
}

export function setAyah(currentAyah) {
return {
type: SET_AYAH,
currentAyah
};
}

export function previous(currentAyah) {
return {
type: PREVIOUS,
currentAyah
};
}

export function setRepeat(repeat) {
return {
type: SET_REPEAT,
repeat
};
}

export function toggleScroll() {
return {
type: TOGGLE_SCROLL
};
}

export function buildOnClient(surahId) {
return {
type: BUILD_ON_CLIENT,
surahId
};
}

export function update(payload) {
return {
type: UPDATE,
payload
};
}
75 changes: 75 additions & 0 deletions src/redux/actions/AyahsActions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import { ayahsSchema } from '../schemas';

import { arrayOf } from 'normalizr';

import {
LOAD,
LOAD_SUCCESS,
LOAD_FAIL,
CLEAR_CURRENT,
SET_CURRENT_AYAH,
SET_CURRENT_WORD,
CLEAR_CURRENT_WORD

} from '../constants/AyahsActionTypes.js';

// For safe measure
const defaultOptions = {
audio: 8,
quran: 1,
content: [19]
};

export function load(id, from, to, options = defaultOptions) {
const { audio, quran, content } = options;

return {
types: [LOAD, LOAD_SUCCESS, LOAD_FAIL],
schema: arrayOf(ayahsSchema),
promise: (client) => client.get(`/v2/surahs/${id}/ayahs`, {
params: {
from,
to,
audio,
quran,
content
}
}),
surahId: id
};
}

export function clearCurrent(id) {
return {
type: CLEAR_CURRENT,
id
};
}

export function clearCurrentWord() {
return {
type: CLEAR_CURRENT_WORD
};
}

export function setCurrentAyah(id) {
return {
type: SET_CURRENT_AYAH,
id
};
}

export function setCurrentWord(id) {
return {
type: SET_CURRENT_WORD,
id
};
}

export function isLoaded(globalState, surahId, from, to) {
Copy link
Contributor

Choose a reason for hiding this comment

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

should we use store checks in action files too? Since they don't actually dispatch an action

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this one is an odd case, I am not sure where to put it. It only gets used inside surah/connect.js, possibly a helper function?

return (
globalState.ayahs.entities[surahId] &&
globalState.ayahs.entities[surahId][`${surahId}:${from}`] &&
globalState.ayahs.entities[surahId][`${surahId}:${to}`]
Copy link
Contributor

Choose a reason for hiding this comment

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

indentation :)

);
}
49 changes: 49 additions & 0 deletions src/redux/actions/SurahsActions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { surahsSchema } from '../schemas';
import { arrayOf } from 'normalizr';
import {
LOAD,
LOAD_SUCCESS,
LOAD_FAIL,
LOAD_INFO,
LOAD_INFO_SUCCESS,
LOAD_INFO_FAIL,
SET_CURRENT
} from '../constants/SurahsActionTypes.js'
Copy link
Contributor

Choose a reason for hiding this comment

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

indent


export function loadAll() {
return {
types: [LOAD, LOAD_SUCCESS, LOAD_FAIL],
schema: arrayOf(surahsSchema),
promise: (client) => client.get('/v2/surahs')
};
}

export function load(id) {
return {
types: [LOAD, LOAD_SUCCESS, LOAD_FAIL],
schema: arrayOf(surahsSchema),
promise: (client) => client.get(`/v2/surahs/${id}`)
};
}

export function loadInfo(link) {
return {
types: [LOAD_INFO, LOAD_INFO_SUCCESS, LOAD_INFO_FAIL],
promise: (client) => client.get(`http://en.wikipedia.org/w/api.php?format=json&action=query&prop=extracts&titles=${link}&redirects=true`) // eslint-disable-line max-len
};
}

export function setCurrent(id) {
return {
type: SET_CURRENT,
current: id
};
}

export function isSingleLoaded(globalState, id) {
return !!globalState.surahs.entities[id];
}

export function isAllLoaded(globalState) {
return Object.keys(globalState.surahs.entities).length === 114;
}
12 changes: 12 additions & 0 deletions src/redux/constants/AudioPlayerActionTypes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
export const SET_USER_AGENT = '@@quran/audioplayer/SET_USER_AGENT';
export const SET_CURRENT_FILE = '@@quran/audioplayer/SET_CURRENT_FILE';
export const SET_CURRENT_WORD = '@@quran/audioplayer/SET_CURRENT_WORD';
export const PLAY = '@@quran/audioplayer/PLAY';
export const PAUSE = '@@quran/audioplayer/PAUSE';
export const NEXT = '@@quran/audioplayer/NEXT';
export const SET_AYAH = '@@quran/audioplayer/SET';
export const PREVIOUS = '@@quran/audioplayer/PREVIOUS';
export const SET_REPEAT = '@@quran/audioplayer/SET_REPEAT';
export const TOGGLE_SCROLL = '@@quran/audioplayer/TOGGLE_SCROLL';
export const BUILD_ON_CLIENT = '@@quran/audioplayer/BUILD_ON_CLIENT';
export const UPDATE = '@@quran/audioplayer/UPDATE';
7 changes: 7 additions & 0 deletions src/redux/constants/AyahsActionTypes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export const LOAD = '@@quran/ayahs/LOAD';
export const LOAD_SUCCESS = '@@quran/ayahs/LOAD_SUCCESS';
export const LOAD_FAIL = '@@quran/ayahs/LOAD_FAIL';
export const CLEAR_CURRENT = '@@quran/ayahs/CLEAR_CURRENT';
export const SET_CURRENT_AYAH = '@@quran/ayahs/SET_CURRENT_AYAH';
export const SET_CURRENT_WORD = '@@quran/ayahs/SET_CURRENT_WORD';
export const CLEAR_CURRENT_WORD = '@@quran/ayahs/CLEAR_CURRENT_WORD';
7 changes: 7 additions & 0 deletions src/redux/constants/SurahsActionTypes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export const LOAD = '@@quran/surahs/LOAD';
export const LOAD_SUCCESS = '@@quran/surahs/LOAD_SUCCESS';
export const LOAD_FAIL = '@@quran/surahs/LOAD_FAIL';
export const LOAD_INFO = '@@quran/surahs/LOAD_INFO';
export const LOAD_INFO_SUCCESS = '@@quran/surahs/LOAD_INFO_SUCCESS';
export const LOAD_INFO_FAIL = '@@quran/surahs/LOAD_INFO_FAIL';
export const SET_CURRENT = '@@quran/surahs/SET_CURRENT';
Loading