From afd3172dab94ba74c285b2dd6792cb25614171db Mon Sep 17 00:00:00 2001 From: Sabeur Thabti Date: Tue, 26 Jul 2016 08:44:56 +0100 Subject: [PATCH 01/10] refactoring the redux structure to something more standard. --- server.js | 2 +- src/components/Audioplayer/index.js | 2 +- src/containers/Surah/index.js | 2 +- src/redux/actions/AudioPlayerActions.js | 95 ++++++++ src/redux/constants/AudioPlayerActionTypes.js | 12 + src/redux/modules/audioplayer.js | 220 +++++++----------- 6 files changed, 195 insertions(+), 138 deletions(-) create mode 100644 src/redux/actions/AudioPlayerActions.js create mode 100644 src/redux/constants/AudioPlayerActionTypes.js diff --git a/server.js b/server.js index 55413f0f8..ca909bb9f 100644 --- a/server.js +++ b/server.js @@ -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 diff --git a/src/components/Audioplayer/index.js b/src/components/Audioplayer/index.js index 05382fd7e..58972b588 100644 --- a/src/components/Audioplayer/index.js +++ b/src/components/Audioplayer/index.js @@ -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'; diff --git a/src/containers/Surah/index.js b/src/containers/Surah/index.js index 1a39dd665..24bfbc134 100644 --- a/src/containers/Surah/index.js +++ b/src/containers/Surah/index.js @@ -42,7 +42,7 @@ import descriptions from './descriptions'; import { surahsConnect, ayahsConnect } from './connect'; -import * as AudioActions from '../../redux/modules/audioplayer'; +import * as AudioActions from '../../redux/actions/AudioPlayerActions.js'; import * as AyahActions from '../../redux/modules/ayahs'; import * as OptionsActions from '../../redux/modules/options'; diff --git a/src/redux/actions/AudioPlayerActions.js b/src/redux/actions/AudioPlayerActions.js new file mode 100644 index 000000000..584af1f23 --- /dev/null +++ b/src/redux/actions/AudioPlayerActions.js @@ -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'; + +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 + }; +} diff --git a/src/redux/constants/AudioPlayerActionTypes.js b/src/redux/constants/AudioPlayerActionTypes.js new file mode 100644 index 000000000..e0d43d7a8 --- /dev/null +++ b/src/redux/constants/AudioPlayerActionTypes.js @@ -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'; diff --git a/src/redux/modules/audioplayer.js b/src/redux/modules/audioplayer.js index 39b5d1003..3688a3683 100644 --- a/src/redux/modules/audioplayer.js +++ b/src/redux/modules/audioplayer.js @@ -8,20 +8,24 @@ import { LOAD as AYAHS_LOAD, CLEAR_CURRENT as AYAHS_CLEAR_CURRENT, SET_CURRENT_AYAH -} from './ayahs'; + } from './ayahs'; -const SET_USER_AGENT = '@@quran/audioplayer/SET_USER_AGENT'; -const SET_CURRENT_FILE = '@@quran/audioplayer/SET_CURRENT_FILE'; -const SET_CURRENT_WORD = '@@quran/audioplayer/SET_CURRENT_WORD'; -const PLAY = '@@quran/audioplayer/PLAY'; -const PAUSE = '@@quran/audioplayer/PAUSE'; -export const NEXT = '@@quran/audioplayer/NEXT'; -export const SET_AYAH = '@@quran/audioplayer/SET'; -const PREVIOUS = '@@quran/audioplayer/PREVIOUS'; -const SET_REPEAT = '@@quran/audioplayer/SET_REPEAT'; -const TOGGLE_SCROLL = '@@quran/audioplayer/TOGGLE_SCROLL'; -const BUILD_ON_CLIENT = '@@quran/audioplayer/BUILD_ON_CLIENT'; -const UPDATE = '@@quran/audioplayer/UPDATE'; +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'; + +export { NEXT, SET_AYAH }; const initialState = { files: {}, @@ -43,39 +47,49 @@ const initialState = { }; export default function reducer(state = initialState, action = {}) { + switch (action.type) { case BUILD_ON_CLIENT: { debug('reducer:audioplayer', 'BUILD_ON_CLIENT init'); const audioFromHash = buildAudioFromHash(state.files[action.surahId], state.userAgent); debug('reducer:audioplayer', 'BUILD_ON_CLIENT return'); + + const stateFiles = state.files; + const filesById = stateFiles[action.surahId]; + const filesFromHash = audioFromHash.files; + return { ...state, isLoadedOnClient: true, files: { - ...state.files, + ...stateFiles, [action.surahId]: { - ...state.files[action.surahId], - ...audioFromHash.files + ...filesById, + ...filesFromHash } }, currentFile: Object.values(audioFromHash.files)[0], currentAyah: Object.keys(audioFromHash.files)[0] }; } - case AYAHS_CLEAR_CURRENT: + case AYAHS_CLEAR_CURRENT: { + const stateFilesCurrent = state.files; + return { ...state, files: { - ...state.files, + ...stateFilesCurrent, [action.id]: {} } }; - case AYAHS_LOAD: + } + case AYAHS_LOAD: { return { ...state, isLoading: false }; + } case AYAHS_LOAD_SUCCESS: { debug('reducer:audioplayer', 'AYAHS_LOAD_SUCCESS init'); let currentFile; @@ -115,6 +129,9 @@ export default function reducer(state = initialState, action = {}) { } } + const stateFiles = state.files; + const stateSegments = state.segments; + debug('reducer:audioplayer', 'AYAHS_LOAD_SUCCESS return'); return { ...state, @@ -124,50 +141,56 @@ export default function reducer(state = initialState, action = {}) { surahId: action.surahId, isLoadedOnClient: __CLIENT__, files: { - ...state.files, + ...stateFiles, [action.surahId]: files }, segments: { - ...state.segments, + ...stateSegments, [action.surahId]: extractSegments(action.result.entities.ayahs) } }; } - case UPDATE: + case UPDATE: { + const {payload} = action; return { ...state, - ...action.payload + ...payload }; - case SET_USER_AGENT: + } + case SET_USER_AGENT: { + const {userAgent} = action; return { ...state, - userAgent: action.userAgent + userAgent }; - case PLAY: + } + case PLAY: { state.currentFile.play(); - return { ...state, isPlaying: true }; - case PAUSE: + } + case PAUSE: { state.currentFile.pause(); return { ...state, isPlaying: false }; - + } case NEXT: { const [surahId, ayahNum] = action.currentAyah.split(':'); const nextId = `${surahId}:${parseInt(ayahNum, 10) + 1}`; + const stateSegments = state.segments; + const stateSegmentsId = stateSegments[surahId]; return { ...state, segments: { - ...state.segments, + ...stateSegments, [surahId]: { - ...state.segments[surahId], + ...stateSegmentsId, [nextId]: buildSegments(state.segments[surahId][nextId]) } }, @@ -176,52 +199,57 @@ export default function reducer(state = initialState, action = {}) { currentTime: 0 }; } + case PREVIOUS: { + const [surahId, ayahNum] = action.currentAyah.split(':'); + const nextId = `${surahId}:${parseInt(ayahNum, 10) - 1}`; + return { + ...state, + currentAyah: nextId, + currentFile: state.files[surahId][nextId], + currentTime: 0 + }; + } case SET_AYAH: { const [surahId, ayahNum] = action.currentAyah.split(':'); const currentAyah = `${surahId}:${parseInt(ayahNum, 10)}`; + const stateSegments = state.segments; + const stateSegmentsId = state.segments[surahId]; + const currentFile = state.files[surahId][currentAyah]; return { ...state, segments: { - ...state.segments, + ...stateSegments, [surahId]: { - ...state.segments[surahId], + ...stateSegmentsId, [currentAyah]: buildSegments(state.segments[surahId][currentAyah]) } }, currentAyah, - currentFile: state.files[surahId][currentAyah], + currentFile, currentTime: 0 }; } - - case PREVIOUS: { - const [surahId, ayahNum] = action.currentAyah.split(':'); - const nextId = `${surahId}:${parseInt(ayahNum, 10) - 1}`; - + case SET_REPEAT: { + const {repeat} = action; return { ...state, - currentAyah: nextId, - currentFile: state.files[surahId][nextId], - currentTime: 0 + repeat }; } - case SET_REPEAT: - return { - ...state, - repeat: action.repeat - }; - case TOGGLE_SCROLL: + case TOGGLE_SCROLL: { return { ...state, shouldScroll: !state.shouldScroll }; - case SET_CURRENT_FILE: + } + case SET_CURRENT_FILE: { return { ...state, currentFile: action.file }; + } case SET_CURRENT_WORD: { if (!action.word) return state; @@ -246,6 +274,8 @@ export default function reducer(state = initialState, action = {}) { const segment = buildSegments(state.segments[surahId][nextId]); currentTime = segment.words[word].startTime; currentFile.currentTime = currentTime; + const stateSegments = state.segments; + const stateSegmentsId = state.segments[surahId]; return { ...state, @@ -255,102 +285,22 @@ export default function reducer(state = initialState, action = {}) { currentTime, currentFile, segments: { - ...state.segments, + ...stateSegments, [surahId]: { - ...state.segments[surahId], + ...stateSegmentsId, [nextId]: segment } } }; - } - case SET_CURRENT_AYAH: + case SET_CURRENT_AYAH: { return { ...state, currentAyah: action.id }; - default: + } + default: { return state; + } } } - -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 - }; -} From 171f79cb7e9e24843e3138134d7657f25488df25 Mon Sep 17 00:00:00 2001 From: Sabeur Thabti Date: Tue, 26 Jul 2016 22:19:21 +0100 Subject: [PATCH 02/10] ayahs actions/reducers --- src/containers/Surah/connect.js | 2 +- src/containers/Surah/index.js | 2 +- src/redux/actions/AyahsActions.js | 75 ++++++++++++++++++++++ src/redux/constants/AyahsActionTypes.js | 7 ++ src/redux/modules/ayahs.js | 85 ++++--------------------- 5 files changed, 98 insertions(+), 73 deletions(-) create mode 100644 src/redux/actions/AyahsActions.js create mode 100644 src/redux/constants/AyahsActionTypes.js diff --git a/src/containers/Surah/connect.js b/src/containers/Surah/connect.js index 965888db0..cb23850cd 100644 --- a/src/containers/Surah/connect.js +++ b/src/containers/Surah/connect.js @@ -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 { clearCurrent, isLoaded, load as loadAyahs } from '../../redux/actions/AyahsActions.js'; import debug from 'helpers/debug'; diff --git a/src/containers/Surah/index.js b/src/containers/Surah/index.js index 24bfbc134..64f0d2c2e 100644 --- a/src/containers/Surah/index.js +++ b/src/containers/Surah/index.js @@ -43,7 +43,7 @@ import descriptions from './descriptions'; import { surahsConnect, ayahsConnect } from './connect'; import * as AudioActions from '../../redux/actions/AudioPlayerActions.js'; -import * as AyahActions from '../../redux/modules/ayahs'; +import * as AyahActions from '../../redux/actions/AyahsActions.js'; import * as OptionsActions from '../../redux/modules/options'; const style = require('./style.scss'); diff --git a/src/redux/actions/AyahsActions.js b/src/redux/actions/AyahsActions.js new file mode 100644 index 000000000..b87a8e221 --- /dev/null +++ b/src/redux/actions/AyahsActions.js @@ -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) { + return ( + globalState.ayahs.entities[surahId] && + globalState.ayahs.entities[surahId][`${surahId}:${from}`] && + globalState.ayahs.entities[surahId][`${surahId}:${to}`] + ); +} diff --git a/src/redux/constants/AyahsActionTypes.js b/src/redux/constants/AyahsActionTypes.js new file mode 100644 index 000000000..4b215a3a8 --- /dev/null +++ b/src/redux/constants/AyahsActionTypes.js @@ -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'; diff --git a/src/redux/modules/ayahs.js b/src/redux/modules/ayahs.js index 80fd8715c..68430a61f 100644 --- a/src/redux/modules/ayahs.js +++ b/src/redux/modules/ayahs.js @@ -1,14 +1,15 @@ -import { ayahsSchema } from '../schemas'; +import { + LOAD, + LOAD_SUCCESS, + LOAD_FAIL, + CLEAR_CURRENT, + SET_CURRENT_AYAH, + SET_CURRENT_WORD, + CLEAR_CURRENT_WORD + } from '../constants/AyahsActionTypes.js'; -import { arrayOf } from 'normalizr'; -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'; +export {LOAD, LOAD_SUCCESS, LOAD_FAIL, CLEAR_CURRENT, SET_CURRENT_AYAH, SET_CURRENT_WORD, CLEAR_CURRENT_WORD} const initialState = { current: null, @@ -46,12 +47,13 @@ export default function reducer(state = initialState, action = {}) { currentWord: null }; case CLEAR_CURRENT: + const stateEntities = state.entities; return { ...state, current: null, currentWord: null, entities: { - ...state.entities, + ...stateEntities, [action.id]: {} } }; @@ -63,6 +65,7 @@ export default function reducer(state = initialState, action = {}) { }; case LOAD_SUCCESS: const current = state.current ? state.current : action.result.result[0]; + const stateEntities = state.entities; return { ...state, @@ -71,7 +74,7 @@ export default function reducer(state = initialState, action = {}) { loading: false, errored: false, entities: { - ...state.entities, + ...stateEntities, [action.surahId]: Object.assign( {}, state.entities[action.surahId], @@ -88,63 +91,3 @@ export default function reducer(state = initialState, action = {}) { } } -// 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) { - return ( - globalState.ayahs.entities[surahId] && - globalState.ayahs.entities[surahId][`${surahId}:${from}`] && - globalState.ayahs.entities[surahId][`${surahId}:${to}`] - ); -} From f2db70e7a569f3e64160b409d9be875940892a89 Mon Sep 17 00:00:00 2001 From: Sabeur Thabti Date: Tue, 26 Jul 2016 22:34:33 +0100 Subject: [PATCH 03/10] SURAHS actions/reducers --- src/containers/Home/index.js | 2 +- src/containers/Surah/connect.js | 2 +- src/redux/actions/SurahsActions.js | 49 ++++++++++++++++++ src/redux/constants/SurahsActionTypes.js | 7 +++ src/redux/modules/ayahs.js | 3 +- src/redux/modules/surahs.js | 65 +++++------------------- 6 files changed, 73 insertions(+), 55 deletions(-) create mode 100644 src/redux/actions/SurahsActions.js create mode 100644 src/redux/constants/SurahsActionTypes.js diff --git a/src/containers/Home/index.js b/src/containers/Home/index.js index 42cecc777..936ab3be1 100644 --- a/src/containers/Home/index.js +++ b/src/containers/Home/index.js @@ -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'); diff --git a/src/containers/Surah/connect.js b/src/containers/Surah/connect.js index cb23850cd..b16af3100 100644 --- a/src/containers/Surah/connect.js +++ b/src/containers/Surah/connect.js @@ -1,4 +1,4 @@ -import { isAllLoaded, loadAll, setCurrent as setCurrentSurah } from '../../redux/modules/surahs'; +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'; diff --git a/src/redux/actions/SurahsActions.js b/src/redux/actions/SurahsActions.js new file mode 100644 index 000000000..759e06aea --- /dev/null +++ b/src/redux/actions/SurahsActions.js @@ -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' + +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; +} diff --git a/src/redux/constants/SurahsActionTypes.js b/src/redux/constants/SurahsActionTypes.js new file mode 100644 index 000000000..b74c0eb4e --- /dev/null +++ b/src/redux/constants/SurahsActionTypes.js @@ -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'; diff --git a/src/redux/modules/ayahs.js b/src/redux/modules/ayahs.js index 68430a61f..c6cd9e74b 100644 --- a/src/redux/modules/ayahs.js +++ b/src/redux/modules/ayahs.js @@ -47,13 +47,12 @@ export default function reducer(state = initialState, action = {}) { currentWord: null }; case CLEAR_CURRENT: - const stateEntities = state.entities; return { ...state, current: null, currentWord: null, entities: { - ...stateEntities, + ...state.entities, [action.id]: {} } }; diff --git a/src/redux/modules/surahs.js b/src/redux/modules/surahs.js index 38fc516c4..9c30cdcfb 100644 --- a/src/redux/modules/surahs.js +++ b/src/redux/modules/surahs.js @@ -1,13 +1,12 @@ -import { surahsSchema } from '../schemas'; -import { arrayOf } from 'normalizr'; - -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'; +import { + LOAD, + LOAD_SUCCESS, + LOAD_FAIL, + LOAD_INFO, + LOAD_INFO_SUCCESS, + LOAD_INFO_FAIL, + SET_CURRENT + } from '../constants/SurahsActionTypes.js' const initialState = { errored: false, @@ -24,14 +23,16 @@ export default function reducer(state = initialState, action = {}) { current: action.current }; case LOAD_SUCCESS: + const entities = state.entities; + const {surahs} = action.result.entities; return { ...state, loaded: true, errored: false, entities: { - ...state.entities, - ...action.result.entities.surahs - }, + ...entities, + ...surahs + } }; case LOAD_FAIL: console.log(action); @@ -40,41 +41,3 @@ export default function reducer(state = initialState, action = {}) { return state; } } - -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; -} From a4833f1301c5c310760448c38ec02e8e0c60b95e Mon Sep 17 00:00:00 2001 From: Sabeur Thabti Date: Tue, 26 Jul 2016 22:46:18 +0100 Subject: [PATCH 04/10] search action --- .eslintrc | 5 ++--- src/containers/Search/index.js | 2 +- src/redux/actions/SearchActions.js | 21 +++++++++++++++++++++ src/redux/constants/SearchActionTypes.js | 3 +++ src/redux/modules/searchResults.js | 24 +++++------------------- 5 files changed, 32 insertions(+), 23 deletions(-) create mode 100644 src/redux/actions/SearchActions.js create mode 100644 src/redux/constants/SearchActionTypes.js diff --git a/.eslintrc b/.eslintrc index a8d2f2fb3..e721b2b5d 100644 --- a/.eslintrc +++ b/.eslintrc @@ -1,6 +1,5 @@ { "parser": "babel-eslint", - "extends": "airbnb", "env": { "browser": true, "node": true, @@ -14,13 +13,13 @@ "import/named": 0, "import/namespace": 0, "import/no-unresolved": 0, - "import/no-named-as-default": 2, + "import/no-named-as-default": 0, // Temporarirly disabled due to a possible bug in babel-eslint (todomvc example) "block-scoped-var": 0, // Temporarily disabled for test/* until babel/babel-eslint#33 is resolved "padded-blocks": 0, "comma-dangle": 0, // not sure why airbnb turned this on. gross! - "indent": [2, 2, {"SwitchCase": 1}], + "indent": [0, 0, {"SwitchCase": 0}], "no-console": 0, "no-alert": 0, "object-curly-spacing": 0, diff --git a/src/containers/Search/index.js b/src/containers/Search/index.js index 1af7eb7b6..caf9c3c1c 100644 --- a/src/containers/Search/index.js +++ b/src/containers/Search/index.js @@ -16,7 +16,7 @@ import Header from './Header'; import Ayah from '../../components/Ayah'; import CoreLoader from '../../components/Loader'; -import { search } from '../../redux/modules/searchResults'; +import { search } from '../../redux/actions/SearchActions.js'; const style = require('./style.scss'); diff --git a/src/redux/actions/SearchActions.js b/src/redux/actions/SearchActions.js new file mode 100644 index 000000000..f898d22bd --- /dev/null +++ b/src/redux/actions/SearchActions.js @@ -0,0 +1,21 @@ +import { ayahsSchema } from '../schemas'; +import { arrayOf } from 'normalizr'; + +import { + SEARCH, + SEARCH_SUCCESS, + SEARCH_FAIL + } from '../constants/SearchActionTypes.js'; + +export function search(params) { + return { + types: [SEARCH, SEARCH_SUCCESS, SEARCH_FAIL], + schema: {results: arrayOf({ayah: ayahsSchema})}, + promise: (client) => client.get('/v2/search', { params }), + params + }; +} + +export function isQueried() { + return false; +} diff --git a/src/redux/constants/SearchActionTypes.js b/src/redux/constants/SearchActionTypes.js new file mode 100644 index 000000000..2eeaa1654 --- /dev/null +++ b/src/redux/constants/SearchActionTypes.js @@ -0,0 +1,3 @@ +export const SEARCH = '@@quran/search/LOAD'; +export const SEARCH_SUCCESS = '@@quran/search/LOAD_SUCCESS'; +export const SEARCH_FAIL = '@@quran/search/LOAD_FAIL'; diff --git a/src/redux/modules/searchResults.js b/src/redux/modules/searchResults.js index c97969b73..5b2654961 100644 --- a/src/redux/modules/searchResults.js +++ b/src/redux/modules/searchResults.js @@ -1,9 +1,8 @@ -import { ayahsSchema } from '../schemas'; -import { arrayOf } from 'normalizr'; - -export const SEARCH = '@@quran/search/LOAD'; -export const SEARCH_SUCCESS = '@@quran/search/LOAD_SUCCESS'; -export const SEARCH_FAIL = '@@quran/search/LOAD_FAIL'; +import { + SEARCH, + SEARCH_SUCCESS, + SEARCH_FAIL + } from '../constants/SearchActionTypes.js'; const initialState = { errored: false, @@ -46,16 +45,3 @@ export default function reducer(state = initialState, action = {}) { return state; } } - -export function search(params) { - return { - types: [SEARCH, SEARCH_SUCCESS, SEARCH_FAIL], - schema: {results: arrayOf({ayah: ayahsSchema})}, - promise: (client) => client.get('/v2/search', { params }), - params - }; -} - -export function isQueried() { - return false; -} From 42f6eaa8b298c5d42ec161546bfe20add449ff73 Mon Sep 17 00:00:00 2001 From: Sabeur Thabti Date: Tue, 26 Jul 2016 23:22:04 +0100 Subject: [PATCH 05/10] options and fontface actions --- .eslintrc | 5 ++-- server.js | 2 +- src/components/FontStyles/index.js | 2 +- src/containers/Surah/index.js | 2 +- src/redux/actions/FontFaceActions.js | 8 +++++++ src/redux/actions/OptionsActions.js | 23 ++++++++++++++++++ src/redux/constants/FontFaceActionTypes.js | 1 + src/redux/constants/OptionsActionTypes.js | 2 ++ src/redux/modules/fontFaces.js | 14 ++++------- src/redux/modules/lines.js | 11 +++++---- src/redux/modules/options.js | 28 +++------------------- 11 files changed, 53 insertions(+), 45 deletions(-) create mode 100644 src/redux/actions/FontFaceActions.js create mode 100644 src/redux/actions/OptionsActions.js create mode 100644 src/redux/constants/FontFaceActionTypes.js create mode 100644 src/redux/constants/OptionsActionTypes.js diff --git a/.eslintrc b/.eslintrc index e721b2b5d..a8d2f2fb3 100644 --- a/.eslintrc +++ b/.eslintrc @@ -1,5 +1,6 @@ { "parser": "babel-eslint", + "extends": "airbnb", "env": { "browser": true, "node": true, @@ -13,13 +14,13 @@ "import/named": 0, "import/namespace": 0, "import/no-unresolved": 0, - "import/no-named-as-default": 0, + "import/no-named-as-default": 2, // Temporarirly disabled due to a possible bug in babel-eslint (todomvc example) "block-scoped-var": 0, // Temporarily disabled for test/* until babel/babel-eslint#33 is resolved "padded-blocks": 0, "comma-dangle": 0, // not sure why airbnb turned this on. gross! - "indent": [0, 0, {"SwitchCase": 0}], + "indent": [2, 2, {"SwitchCase": 1}], "no-console": 0, "no-alert": 0, "object-curly-spacing": 0, diff --git a/server.js b/server.js index ca909bb9f..cf2b5b2ea 100644 --- a/server.js +++ b/server.js @@ -26,7 +26,7 @@ import debug from './src/helpers/debug'; import Html from './src/helpers/Html'; import { setUserAgent } from './src/redux/actions/AudioPlayerActions.js'; -import { setOption } from './src/redux/modules/options'; +import { setOption } from './src/redux/actions/OptionsActions.js'; // Use varnish for the static routes, which will cache too server.use(raven.middleware.express.requestHandler(config.sentryServer)); diff --git a/src/components/FontStyles/index.js b/src/components/FontStyles/index.js index a887bb375..1e491d096 100644 --- a/src/components/FontStyles/index.js +++ b/src/components/FontStyles/index.js @@ -1,7 +1,7 @@ import React, { Component, PropTypes } from 'react'; import { connect } from 'react-redux'; import { fontFaceStyle, fontFaceStyleLoaded } from '../../helpers/buildFontFaces'; -import { load } from 'redux/modules/fontFaces'; +import { load } from 'redux/actions/FontFaceActions.js'; import debug from 'helpers/debug'; import selector from './selector'; diff --git a/src/containers/Surah/index.js b/src/containers/Surah/index.js index 64f0d2c2e..2956c3ab1 100644 --- a/src/containers/Surah/index.js +++ b/src/containers/Surah/index.js @@ -44,7 +44,7 @@ import { surahsConnect, ayahsConnect } from './connect'; import * as AudioActions from '../../redux/actions/AudioPlayerActions.js'; import * as AyahActions from '../../redux/actions/AyahsActions.js'; -import * as OptionsActions from '../../redux/modules/options'; +import * as OptionsActions from '../../redux/actions/OptionsActions.js'; const style = require('./style.scss'); diff --git a/src/redux/actions/FontFaceActions.js b/src/redux/actions/FontFaceActions.js new file mode 100644 index 000000000..7ea113642 --- /dev/null +++ b/src/redux/actions/FontFaceActions.js @@ -0,0 +1,8 @@ +import { LOAD } from '../constants/FontFaceActionTypes.js'; + +export function load(className) { + return { + type: LOAD, + className + }; +} diff --git a/src/redux/actions/OptionsActions.js b/src/redux/actions/OptionsActions.js new file mode 100644 index 000000000..94d68db8f --- /dev/null +++ b/src/redux/actions/OptionsActions.js @@ -0,0 +1,23 @@ +import cookie from 'react-cookie'; +import { TOGGLE_READING_MODE, SET_OPTION } from '../constants/OptionsActionTypes.js' + +export function isReadingMode(globalState) { + return globalState.options.isReadingMode; +} + +export function setOption(payload) { + const options = cookie.load('options') || {}; // protect against first timers. + Object.keys(payload).forEach(option => { options[option] = payload[option]; }); + cookie.save('options', JSON.stringify(options)); + + return { + type: SET_OPTION, + payload + }; +} + +export function toggleReadingMode() { + return { + type: TOGGLE_READING_MODE + }; +} diff --git a/src/redux/constants/FontFaceActionTypes.js b/src/redux/constants/FontFaceActionTypes.js new file mode 100644 index 000000000..1dc3a243b --- /dev/null +++ b/src/redux/constants/FontFaceActionTypes.js @@ -0,0 +1 @@ +export const LOAD = '@@quran/fontFaces/LOAD'; diff --git a/src/redux/constants/OptionsActionTypes.js b/src/redux/constants/OptionsActionTypes.js new file mode 100644 index 000000000..ffa608eeb --- /dev/null +++ b/src/redux/constants/OptionsActionTypes.js @@ -0,0 +1,2 @@ +export const TOGGLE_READING_MODE = '@@quran/options/TOGGLE_READING_MODE'; +export const SET_OPTION = '@@quran/options/SET_OPTION'; diff --git a/src/redux/modules/fontFaces.js b/src/redux/modules/fontFaces.js index 6c53fe62a..81522223e 100644 --- a/src/redux/modules/fontFaces.js +++ b/src/redux/modules/fontFaces.js @@ -1,7 +1,6 @@ -import { LOAD_SUCCESS } from './ayahs'; -import { SEARCH_SUCCESS } from './searchResults'; - -export const LOAD = '@@quran/fontFaces/LOAD'; +import { LOAD_SUCCESS } from '../constants/AyahsActionTypes.js'; +import { SEARCH_SUCCESS } from '../constants/SearchActionTypes.js'; +import { LOAD } from '../constants/FontFaceActionTypes.js'; export default function reducer(state = {}, action = {}) { switch (action.type) { @@ -33,9 +32,4 @@ export default function reducer(state = {}, action = {}) { } } -export function load(className) { - return { - type: LOAD, - className - }; -} + diff --git a/src/redux/modules/lines.js b/src/redux/modules/lines.js index f4820b0a7..26d895c4f 100644 --- a/src/redux/modules/lines.js +++ b/src/redux/modules/lines.js @@ -2,13 +2,13 @@ import { LOAD as AYAHS_LOAD, LOAD_SUCCESS as AYAHS_LOAD_SUCCESS, - LOAD_FAIL as AYAHS_LOAD_FAIL -} from './ayahs'; + LOAD_FAIL as AYAHS_LOAD_FAIL, + } from '../constants/AyahsActionTypes.js'; -import { SET_CURRENT as SURAHS_SET_CURRENT } from './surahs'; +import { SET_CURRENT as SURAHS_SET_CURRENT } from '../constants/SurahsActionTypes.js' const initialState = { - lines: {}, + lines: {} }; export default function reducer(state = initialState, action = {}) { @@ -26,7 +26,8 @@ export default function reducer(state = initialState, action = {}) { }; case AYAHS_LOAD_SUCCESS: const ayahs = action.result.entities.ayahs; - const lines = {...state.lines}; + const stateLines = state.lines; + const lines = {...stateLines}; action.result.result.forEach(ayahId => { const ayah = ayahs[ayahId]; diff --git a/src/redux/modules/options.js b/src/redux/modules/options.js index c4673bdce..3d180d4cf 100644 --- a/src/redux/modules/options.js +++ b/src/redux/modules/options.js @@ -1,7 +1,5 @@ -import cookie from 'react-cookie'; -const TOGGLE_READING_MODE = '@@quran/options/TOGGLE_READING_MODE'; -const SET_OPTION = '@@quran/options/SET_OPTION'; +import { TOGGLE_READING_MODE, SET_OPTION } from '../constants/OptionsActionTypes.js'; const initialState = { isReadingMode: false, @@ -24,32 +22,12 @@ export default function reducer(state = initialState, action = {}) { isReadingMode: !state.isReadingMode }; case SET_OPTION: + const payload = action.payload; return { ...state, - ...action.payload + ...payload }; default: return state; } } - -export function isReadingMode(globalState) { - return globalState.options.isReadingMode; -} - -export function setOption(payload) { - const options = cookie.load('options') || {}; // protect against first timers. - Object.keys(payload).forEach(option => { options[option] = payload[option]; }); - cookie.save('options', JSON.stringify(options)); - - return { - type: SET_OPTION, - payload - }; -} - -export function toggleReadingMode() { - return { - type: TOGGLE_READING_MODE - }; -} From ae7439b866c12fa50df654eb17d7036792dc8277 Mon Sep 17 00:00:00 2001 From: Sabeur Thabti Date: Thu, 28 Jul 2016 21:59:18 +0100 Subject: [PATCH 06/10] lowercase the file names --- server.js | 4 +- src/components/Audioplayer/index.js | 2 +- src/components/FontStyles/index.js | 2 +- src/containers/Home/index.js | 2 +- src/containers/Search/index.js | 2 +- src/containers/Surah/connect.js | 13 ++- src/containers/Surah/index.js | 6 +- src/redux/actions/audioPlayerActions.js | 95 +++++++++++++++++++ src/redux/actions/ayahsActions.js | 75 +++++++++++++++ src/redux/actions/fontFaceActions.js | 8 ++ src/redux/actions/optionsActions.js | 23 +++++ src/redux/actions/searchActions.js | 21 ++++ src/redux/actions/surahsActions.js | 49 ++++++++++ src/redux/constants/audioPlayerActionTypes.js | 12 +++ src/redux/constants/ayahsActionTypes.js | 7 ++ src/redux/constants/fontFaceActionTypes.js | 1 + src/redux/constants/optionsActionTypes.js | 2 + src/redux/constants/searchActionTypes.js | 3 + src/redux/constants/surahsActionTypes.js | 7 ++ src/redux/modules/audioplayer.js | 2 +- src/redux/modules/ayahs.js | 10 +- src/redux/modules/fontFaces.js | 8 +- src/redux/modules/lines.js | 4 +- src/redux/modules/options.js | 2 +- src/redux/modules/searchResults.js | 2 +- src/redux/modules/surahs.js | 6 +- 26 files changed, 339 insertions(+), 29 deletions(-) create mode 100644 src/redux/actions/audioPlayerActions.js create mode 100644 src/redux/actions/ayahsActions.js create mode 100644 src/redux/actions/fontFaceActions.js create mode 100644 src/redux/actions/optionsActions.js create mode 100644 src/redux/actions/searchActions.js create mode 100644 src/redux/actions/surahsActions.js create mode 100644 src/redux/constants/audioPlayerActionTypes.js create mode 100644 src/redux/constants/ayahsActionTypes.js create mode 100644 src/redux/constants/fontFaceActionTypes.js create mode 100644 src/redux/constants/optionsActionTypes.js create mode 100644 src/redux/constants/searchActionTypes.js create mode 100644 src/redux/constants/surahsActionTypes.js diff --git a/server.js b/server.js index cf2b5b2ea..32a41f750 100644 --- a/server.js +++ b/server.js @@ -25,8 +25,8 @@ import debug from './src/helpers/debug'; import Html from './src/helpers/Html'; -import { setUserAgent } from './src/redux/actions/AudioPlayerActions.js'; -import { setOption } from './src/redux/actions/OptionsActions.js'; +import { setUserAgent } from './src/redux/actions/audioPlayerActions.js'; +import { setOption } from './src/redux/actions/optionsActions.js'; // Use varnish for the static routes, which will cache too server.use(raven.middleware.express.requestHandler(config.sentryServer)); diff --git a/src/components/Audioplayer/index.js b/src/components/Audioplayer/index.js index 58972b588..cf2de0d04 100644 --- a/src/components/Audioplayer/index.js +++ b/src/components/Audioplayer/index.js @@ -3,7 +3,7 @@ import { connect } from 'react-redux'; import { camelize } from 'humps'; // Redux -import * as AudioActions from '../../redux/actions/AudioPlayerActions'; +import * as AudioActions from '../../redux/actions/audioPlayerActions'; // Components import Track from './Track'; diff --git a/src/components/FontStyles/index.js b/src/components/FontStyles/index.js index 1e491d096..d3300d600 100644 --- a/src/components/FontStyles/index.js +++ b/src/components/FontStyles/index.js @@ -1,7 +1,7 @@ import React, { Component, PropTypes } from 'react'; import { connect } from 'react-redux'; import { fontFaceStyle, fontFaceStyleLoaded } from '../../helpers/buildFontFaces'; -import { load } from 'redux/actions/FontFaceActions.js'; +import { load } from 'redux/actions/fontFaceActions.js'; import debug from 'helpers/debug'; import selector from './selector'; diff --git a/src/containers/Home/index.js b/src/containers/Home/index.js index 936ab3be1..3b6460fbd 100644 --- a/src/containers/Home/index.js +++ b/src/containers/Home/index.js @@ -7,7 +7,7 @@ import { connect } from 'react-redux'; import debug from '../../helpers/debug'; -import { isAllLoaded, loadAll } from '../../redux/actions/SurahsActions.js'; +import { isAllLoaded, loadAll } from '../../redux/actions/surahsActions.js'; const styles = require('./style.scss'); diff --git a/src/containers/Search/index.js b/src/containers/Search/index.js index caf9c3c1c..fd48093f5 100644 --- a/src/containers/Search/index.js +++ b/src/containers/Search/index.js @@ -16,7 +16,7 @@ import Header from './Header'; import Ayah from '../../components/Ayah'; import CoreLoader from '../../components/Loader'; -import { search } from '../../redux/actions/SearchActions.js'; +import { search } from '../../redux/actions/searchActions.js'; const style = require('./style.scss'); diff --git a/src/containers/Surah/connect.js b/src/containers/Surah/connect.js index b16af3100..be0c0c673 100644 --- a/src/containers/Surah/connect.js +++ b/src/containers/Surah/connect.js @@ -1,5 +1,14 @@ -import { isAllLoaded, loadAll, setCurrent as setCurrentSurah } from '../../redux/actions/SurahsActions.js'; -import { clearCurrent, isLoaded, load as loadAyahs } from '../../redux/actions/AyahsActions.js'; +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'; diff --git a/src/containers/Surah/index.js b/src/containers/Surah/index.js index 2956c3ab1..484732fb4 100644 --- a/src/containers/Surah/index.js +++ b/src/containers/Surah/index.js @@ -42,9 +42,9 @@ import descriptions from './descriptions'; import { surahsConnect, ayahsConnect } from './connect'; -import * as AudioActions from '../../redux/actions/AudioPlayerActions.js'; -import * as AyahActions from '../../redux/actions/AyahsActions.js'; -import * as OptionsActions from '../../redux/actions/OptionsActions.js'; +import * as AudioActions from '../../redux/actions/audioPlayerActions.js'; +import * as AyahActions from '../../redux/actions/ayahsActions.js'; +import * as OptionsActions from '../../redux/actions/optionsActions.js'; const style = require('./style.scss'); diff --git a/src/redux/actions/audioPlayerActions.js b/src/redux/actions/audioPlayerActions.js new file mode 100644 index 000000000..411ab3d0d --- /dev/null +++ b/src/redux/actions/audioPlayerActions.js @@ -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'; + +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 + }; +} diff --git a/src/redux/actions/ayahsActions.js b/src/redux/actions/ayahsActions.js new file mode 100644 index 000000000..d6d0fff51 --- /dev/null +++ b/src/redux/actions/ayahsActions.js @@ -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) { + return ( + globalState.ayahs.entities[surahId] && + globalState.ayahs.entities[surahId][`${surahId}:${from}`] && + globalState.ayahs.entities[surahId][`${surahId}:${to}`] + ); +} diff --git a/src/redux/actions/fontFaceActions.js b/src/redux/actions/fontFaceActions.js new file mode 100644 index 000000000..12d32660f --- /dev/null +++ b/src/redux/actions/fontFaceActions.js @@ -0,0 +1,8 @@ +import { LOAD } from '../constants/fontFaceActionTypes.js'; + +export function load(className) { + return { + type: LOAD, + className + }; +} diff --git a/src/redux/actions/optionsActions.js b/src/redux/actions/optionsActions.js new file mode 100644 index 000000000..6dee94507 --- /dev/null +++ b/src/redux/actions/optionsActions.js @@ -0,0 +1,23 @@ +import cookie from 'react-cookie'; +import { TOGGLE_READING_MODE, SET_OPTION } from '../constants/optionsActionTypes.js'; + +export function isReadingMode(globalState) { + return globalState.options.isReadingMode; +} + +export function setOption(payload) { + const options = cookie.load('options') || {}; // protect against first timers. + Object.keys(payload).forEach(option => { options[option] = payload[option]; }); + cookie.save('options', JSON.stringify(options)); + + return { + type: SET_OPTION, + payload + }; +} + +export function toggleReadingMode() { + return { + type: TOGGLE_READING_MODE + }; +} diff --git a/src/redux/actions/searchActions.js b/src/redux/actions/searchActions.js new file mode 100644 index 000000000..355c93b0e --- /dev/null +++ b/src/redux/actions/searchActions.js @@ -0,0 +1,21 @@ +import { ayahsSchema } from '../schemas'; +import { arrayOf } from 'normalizr'; + +import { + SEARCH, + SEARCH_SUCCESS, + SEARCH_FAIL + } from '../constants/searchActionTypes.js'; + +export function search(params) { + return { + types: [SEARCH, SEARCH_SUCCESS, SEARCH_FAIL], + schema: {results: arrayOf({ayah: ayahsSchema})}, + promise: (client) => client.get('/v2/search', { params }), + params + }; +} + +export function isQueried() { + return false; +} diff --git a/src/redux/actions/surahsActions.js b/src/redux/actions/surahsActions.js new file mode 100644 index 000000000..008f08926 --- /dev/null +++ b/src/redux/actions/surahsActions.js @@ -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'; + +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; +} diff --git a/src/redux/constants/audioPlayerActionTypes.js b/src/redux/constants/audioPlayerActionTypes.js new file mode 100644 index 000000000..e0d43d7a8 --- /dev/null +++ b/src/redux/constants/audioPlayerActionTypes.js @@ -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'; diff --git a/src/redux/constants/ayahsActionTypes.js b/src/redux/constants/ayahsActionTypes.js new file mode 100644 index 000000000..4b215a3a8 --- /dev/null +++ b/src/redux/constants/ayahsActionTypes.js @@ -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'; diff --git a/src/redux/constants/fontFaceActionTypes.js b/src/redux/constants/fontFaceActionTypes.js new file mode 100644 index 000000000..1dc3a243b --- /dev/null +++ b/src/redux/constants/fontFaceActionTypes.js @@ -0,0 +1 @@ +export const LOAD = '@@quran/fontFaces/LOAD'; diff --git a/src/redux/constants/optionsActionTypes.js b/src/redux/constants/optionsActionTypes.js new file mode 100644 index 000000000..ffa608eeb --- /dev/null +++ b/src/redux/constants/optionsActionTypes.js @@ -0,0 +1,2 @@ +export const TOGGLE_READING_MODE = '@@quran/options/TOGGLE_READING_MODE'; +export const SET_OPTION = '@@quran/options/SET_OPTION'; diff --git a/src/redux/constants/searchActionTypes.js b/src/redux/constants/searchActionTypes.js new file mode 100644 index 000000000..2eeaa1654 --- /dev/null +++ b/src/redux/constants/searchActionTypes.js @@ -0,0 +1,3 @@ +export const SEARCH = '@@quran/search/LOAD'; +export const SEARCH_SUCCESS = '@@quran/search/LOAD_SUCCESS'; +export const SEARCH_FAIL = '@@quran/search/LOAD_FAIL'; diff --git a/src/redux/constants/surahsActionTypes.js b/src/redux/constants/surahsActionTypes.js new file mode 100644 index 000000000..b74c0eb4e --- /dev/null +++ b/src/redux/constants/surahsActionTypes.js @@ -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'; diff --git a/src/redux/modules/audioplayer.js b/src/redux/modules/audioplayer.js index 3688a3683..f52b6a6b1 100644 --- a/src/redux/modules/audioplayer.js +++ b/src/redux/modules/audioplayer.js @@ -23,7 +23,7 @@ import { TOGGLE_SCROLL, BUILD_ON_CLIENT, UPDATE - } from '../constants/AudioPlayerActionTypes.js'; + } from '../constants/audioPlayerActionTypes.js'; export { NEXT, SET_AYAH }; diff --git a/src/redux/modules/ayahs.js b/src/redux/modules/ayahs.js index c6cd9e74b..80a54299b 100644 --- a/src/redux/modules/ayahs.js +++ b/src/redux/modules/ayahs.js @@ -6,10 +6,14 @@ import { SET_CURRENT_AYAH, SET_CURRENT_WORD, CLEAR_CURRENT_WORD - } from '../constants/AyahsActionTypes.js'; + } from '../constants/ayahsActionTypes.js'; - -export {LOAD, LOAD_SUCCESS, LOAD_FAIL, CLEAR_CURRENT, SET_CURRENT_AYAH, SET_CURRENT_WORD, CLEAR_CURRENT_WORD} +export { + LOAD, + LOAD_SUCCESS, + CLEAR_CURRENT, + SET_CURRENT_AYAH, +}; const initialState = { current: null, diff --git a/src/redux/modules/fontFaces.js b/src/redux/modules/fontFaces.js index 81522223e..b3144ad40 100644 --- a/src/redux/modules/fontFaces.js +++ b/src/redux/modules/fontFaces.js @@ -1,6 +1,6 @@ -import { LOAD_SUCCESS } from '../constants/AyahsActionTypes.js'; -import { SEARCH_SUCCESS } from '../constants/SearchActionTypes.js'; -import { LOAD } from '../constants/FontFaceActionTypes.js'; +import { LOAD_SUCCESS } from '../constants/ayahsActionTypes.js'; +import { SEARCH_SUCCESS } from '../constants/searchActionTypes.js'; +import { LOAD } from '../constants/fontFaceActionTypes.js'; export default function reducer(state = {}, action = {}) { switch (action.type) { @@ -31,5 +31,3 @@ export default function reducer(state = {}, action = {}) { return state; } } - - diff --git a/src/redux/modules/lines.js b/src/redux/modules/lines.js index 26d895c4f..2642ddadd 100644 --- a/src/redux/modules/lines.js +++ b/src/redux/modules/lines.js @@ -3,9 +3,9 @@ import { LOAD as AYAHS_LOAD, LOAD_SUCCESS as AYAHS_LOAD_SUCCESS, LOAD_FAIL as AYAHS_LOAD_FAIL, - } from '../constants/AyahsActionTypes.js'; + } from '../constants/ayahsActionTypes.js'; -import { SET_CURRENT as SURAHS_SET_CURRENT } from '../constants/SurahsActionTypes.js' +import { SET_CURRENT as SURAHS_SET_CURRENT } from '../constants/surahsActionTypes.js'; const initialState = { lines: {} diff --git a/src/redux/modules/options.js b/src/redux/modules/options.js index 3d180d4cf..959baaf64 100644 --- a/src/redux/modules/options.js +++ b/src/redux/modules/options.js @@ -1,5 +1,5 @@ -import { TOGGLE_READING_MODE, SET_OPTION } from '../constants/OptionsActionTypes.js'; +import { TOGGLE_READING_MODE, SET_OPTION } from '../constants/optionsActionTypes.js'; const initialState = { isReadingMode: false, diff --git a/src/redux/modules/searchResults.js b/src/redux/modules/searchResults.js index 5b2654961..de242573c 100644 --- a/src/redux/modules/searchResults.js +++ b/src/redux/modules/searchResults.js @@ -2,7 +2,7 @@ import { SEARCH, SEARCH_SUCCESS, SEARCH_FAIL - } from '../constants/SearchActionTypes.js'; + } from '../constants/searchActionTypes.js'; const initialState = { errored: false, diff --git a/src/redux/modules/surahs.js b/src/redux/modules/surahs.js index 9c30cdcfb..fd3af5ad2 100644 --- a/src/redux/modules/surahs.js +++ b/src/redux/modules/surahs.js @@ -1,12 +1,8 @@ import { - LOAD, LOAD_SUCCESS, LOAD_FAIL, - LOAD_INFO, - LOAD_INFO_SUCCESS, - LOAD_INFO_FAIL, SET_CURRENT - } from '../constants/SurahsActionTypes.js' + } from '../constants/surahsActionTypes.js'; const initialState = { errored: false, From 6b53f2361f70e900e7db429e0b711a6c30e2a94d Mon Sep 17 00:00:00 2001 From: Sabeur Thabti Date: Mon, 1 Aug 2016 18:28:12 +0100 Subject: [PATCH 07/10] rename actions/actionTypes --- server.js | 4 +- src/components/Audioplayer/index.js | 2 +- src/components/FontStyles/index.js | 2 +- src/containers/Home/index.js | 2 +- src/containers/Search/index.js | 2 +- src/containers/Surah/connect.js | 4 +- src/containers/Surah/index.js | 6 +- src/redux/actions/AudioPlayerActions.js | 95 ------------------- src/redux/actions/AyahsActions.js | 75 --------------- src/redux/actions/FontFaceActions.js | 8 -- src/redux/actions/OptionsActions.js | 23 ----- src/redux/actions/audioPlayerActions.js | 95 ------------------- .../actions/{ayahsActions.js => ayahs.js} | 9 +- .../{fontFaceActions.js => fontFace.js} | 2 +- .../actions/{optionsActions.js => options.js} | 2 +- .../actions/{SearchActions.js => search.js} | 2 +- src/redux/actions/searchActions.js | 21 ---- .../actions/{SurahsActions.js => surahs.js} | 3 +- src/redux/actions/surahsActions.js | 49 ---------- src/redux/constants/audioPlayerActionTypes.js | 12 --- ...dioPlayerActionTypes.js => audioplayer.js} | 0 .../{AyahsActionTypes.js => ayahs.js} | 0 src/redux/constants/ayahsActionTypes.js | 7 -- .../{FontFaceActionTypes.js => fontFace.js} | 0 src/redux/constants/fontFaceActionTypes.js | 1 - .../{OptionsActionTypes.js => options.js} | 0 src/redux/constants/optionsActionTypes.js | 2 - .../{SearchActionTypes.js => search.js} | 0 src/redux/constants/searchActionTypes.js | 3 - .../{SurahsActionTypes.js => surahs.js} | 0 src/redux/constants/surahsActionTypes.js | 7 -- src/redux/modules/audioplayer.js | 2 +- src/redux/modules/ayahs.js | 2 +- src/redux/modules/fontFaces.js | 6 +- src/redux/modules/lines.js | 4 +- src/redux/modules/options.js | 2 +- src/redux/modules/searchResults.js | 2 +- src/redux/modules/surahs.js | 2 +- 38 files changed, 29 insertions(+), 429 deletions(-) delete mode 100644 src/redux/actions/AudioPlayerActions.js delete mode 100644 src/redux/actions/AyahsActions.js delete mode 100644 src/redux/actions/FontFaceActions.js delete mode 100644 src/redux/actions/OptionsActions.js delete mode 100644 src/redux/actions/audioPlayerActions.js rename src/redux/actions/{ayahsActions.js => ayahs.js} (84%) rename src/redux/actions/{fontFaceActions.js => fontFace.js} (58%) rename src/redux/actions/{optionsActions.js => options.js} (96%) rename src/redux/actions/{SearchActions.js => search.js} (89%) delete mode 100644 src/redux/actions/searchActions.js rename src/redux/actions/{SurahsActions.js => surahs.js} (94%) delete mode 100644 src/redux/actions/surahsActions.js delete mode 100644 src/redux/constants/audioPlayerActionTypes.js rename src/redux/constants/{AudioPlayerActionTypes.js => audioplayer.js} (100%) rename src/redux/constants/{AyahsActionTypes.js => ayahs.js} (100%) delete mode 100644 src/redux/constants/ayahsActionTypes.js rename src/redux/constants/{FontFaceActionTypes.js => fontFace.js} (100%) delete mode 100644 src/redux/constants/fontFaceActionTypes.js rename src/redux/constants/{OptionsActionTypes.js => options.js} (100%) delete mode 100644 src/redux/constants/optionsActionTypes.js rename src/redux/constants/{SearchActionTypes.js => search.js} (100%) delete mode 100644 src/redux/constants/searchActionTypes.js rename src/redux/constants/{SurahsActionTypes.js => surahs.js} (100%) delete mode 100644 src/redux/constants/surahsActionTypes.js diff --git a/server.js b/server.js index 32a41f750..9c1a781a8 100644 --- a/server.js +++ b/server.js @@ -25,8 +25,8 @@ import debug from './src/helpers/debug'; import Html from './src/helpers/Html'; -import { setUserAgent } from './src/redux/actions/audioPlayerActions.js'; -import { setOption } from './src/redux/actions/optionsActions.js'; +import { setUserAgent } from './src/redux/actions/audioplayer.js'; +import { setOption } from './src/redux/actions/options.js'; // Use varnish for the static routes, which will cache too server.use(raven.middleware.express.requestHandler(config.sentryServer)); diff --git a/src/components/Audioplayer/index.js b/src/components/Audioplayer/index.js index cf2de0d04..6492999bf 100644 --- a/src/components/Audioplayer/index.js +++ b/src/components/Audioplayer/index.js @@ -3,7 +3,7 @@ import { connect } from 'react-redux'; import { camelize } from 'humps'; // Redux -import * as AudioActions from '../../redux/actions/audioPlayerActions'; +import * as AudioActions from '../../redux/actions/audioplayer'; // Components import Track from './Track'; diff --git a/src/components/FontStyles/index.js b/src/components/FontStyles/index.js index d3300d600..b147dbe2e 100644 --- a/src/components/FontStyles/index.js +++ b/src/components/FontStyles/index.js @@ -1,7 +1,7 @@ import React, { Component, PropTypes } from 'react'; import { connect } from 'react-redux'; import { fontFaceStyle, fontFaceStyleLoaded } from '../../helpers/buildFontFaces'; -import { load } from 'redux/actions/fontFaceActions.js'; +import { load } from 'redux/actions/fontFace.js'; import debug from 'helpers/debug'; import selector from './selector'; diff --git a/src/containers/Home/index.js b/src/containers/Home/index.js index 3b6460fbd..50fb5f230 100644 --- a/src/containers/Home/index.js +++ b/src/containers/Home/index.js @@ -7,7 +7,7 @@ import { connect } from 'react-redux'; import debug from '../../helpers/debug'; -import { isAllLoaded, loadAll } from '../../redux/actions/surahsActions.js'; +import { isAllLoaded, loadAll } from '../../redux/actions/surahs.js'; const styles = require('./style.scss'); diff --git a/src/containers/Search/index.js b/src/containers/Search/index.js index fd48093f5..1d36c8b42 100644 --- a/src/containers/Search/index.js +++ b/src/containers/Search/index.js @@ -16,7 +16,7 @@ import Header from './Header'; import Ayah from '../../components/Ayah'; import CoreLoader from '../../components/Loader'; -import { search } from '../../redux/actions/searchActions.js'; +import { search } from '../../redux/actions/search.js'; const style = require('./style.scss'); diff --git a/src/containers/Surah/connect.js b/src/containers/Surah/connect.js index be0c0c673..a589f3d15 100644 --- a/src/containers/Surah/connect.js +++ b/src/containers/Surah/connect.js @@ -2,13 +2,13 @@ import { isAllLoaded, loadAll, setCurrent as setCurrentSurah - } from '../../redux/actions/surahsActions.js'; + } from '../../redux/actions/surahs.js'; import { clearCurrent, isLoaded, load as loadAyahs - } from '../../redux/actions/ayahsActions.js'; + } from '../../redux/actions/ayahs.js'; import debug from 'helpers/debug'; diff --git a/src/containers/Surah/index.js b/src/containers/Surah/index.js index 484732fb4..f7b73685b 100644 --- a/src/containers/Surah/index.js +++ b/src/containers/Surah/index.js @@ -42,9 +42,9 @@ import descriptions from './descriptions'; import { surahsConnect, ayahsConnect } from './connect'; -import * as AudioActions from '../../redux/actions/audioPlayerActions.js'; -import * as AyahActions from '../../redux/actions/ayahsActions.js'; -import * as OptionsActions from '../../redux/actions/optionsActions.js'; +import * as AudioActions from '../../redux/actions/audioplayer.js'; +import * as AyahActions from '../../redux/actions/ayahs.js'; +import * as OptionsActions from '../../redux/actions/options.js'; const style = require('./style.scss'); diff --git a/src/redux/actions/AudioPlayerActions.js b/src/redux/actions/AudioPlayerActions.js deleted file mode 100644 index 584af1f23..000000000 --- a/src/redux/actions/AudioPlayerActions.js +++ /dev/null @@ -1,95 +0,0 @@ -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'; - -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 - }; -} diff --git a/src/redux/actions/AyahsActions.js b/src/redux/actions/AyahsActions.js deleted file mode 100644 index b87a8e221..000000000 --- a/src/redux/actions/AyahsActions.js +++ /dev/null @@ -1,75 +0,0 @@ -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) { - return ( - globalState.ayahs.entities[surahId] && - globalState.ayahs.entities[surahId][`${surahId}:${from}`] && - globalState.ayahs.entities[surahId][`${surahId}:${to}`] - ); -} diff --git a/src/redux/actions/FontFaceActions.js b/src/redux/actions/FontFaceActions.js deleted file mode 100644 index 7ea113642..000000000 --- a/src/redux/actions/FontFaceActions.js +++ /dev/null @@ -1,8 +0,0 @@ -import { LOAD } from '../constants/FontFaceActionTypes.js'; - -export function load(className) { - return { - type: LOAD, - className - }; -} diff --git a/src/redux/actions/OptionsActions.js b/src/redux/actions/OptionsActions.js deleted file mode 100644 index 94d68db8f..000000000 --- a/src/redux/actions/OptionsActions.js +++ /dev/null @@ -1,23 +0,0 @@ -import cookie from 'react-cookie'; -import { TOGGLE_READING_MODE, SET_OPTION } from '../constants/OptionsActionTypes.js' - -export function isReadingMode(globalState) { - return globalState.options.isReadingMode; -} - -export function setOption(payload) { - const options = cookie.load('options') || {}; // protect against first timers. - Object.keys(payload).forEach(option => { options[option] = payload[option]; }); - cookie.save('options', JSON.stringify(options)); - - return { - type: SET_OPTION, - payload - }; -} - -export function toggleReadingMode() { - return { - type: TOGGLE_READING_MODE - }; -} diff --git a/src/redux/actions/audioPlayerActions.js b/src/redux/actions/audioPlayerActions.js deleted file mode 100644 index 411ab3d0d..000000000 --- a/src/redux/actions/audioPlayerActions.js +++ /dev/null @@ -1,95 +0,0 @@ -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'; - -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 - }; -} diff --git a/src/redux/actions/ayahsActions.js b/src/redux/actions/ayahs.js similarity index 84% rename from src/redux/actions/ayahsActions.js rename to src/redux/actions/ayahs.js index d6d0fff51..cca44ad57 100644 --- a/src/redux/actions/ayahsActions.js +++ b/src/redux/actions/ayahs.js @@ -10,8 +10,7 @@ import { SET_CURRENT_AYAH, SET_CURRENT_WORD, CLEAR_CURRENT_WORD - - } from '../constants/ayahsActionTypes.js'; + } from '../constants/ayahs.js'; // For safe measure const defaultOptions = { @@ -68,8 +67,8 @@ export function setCurrentWord(id) { export function isLoaded(globalState, surahId, from, to) { return ( - globalState.ayahs.entities[surahId] && - globalState.ayahs.entities[surahId][`${surahId}:${from}`] && - globalState.ayahs.entities[surahId][`${surahId}:${to}`] + globalState.ayahs.entities[surahId] && + globalState.ayahs.entities[surahId][`${surahId}:${from}`] && + globalState.ayahs.entities[surahId][`${surahId}:${to}`] ); } diff --git a/src/redux/actions/fontFaceActions.js b/src/redux/actions/fontFace.js similarity index 58% rename from src/redux/actions/fontFaceActions.js rename to src/redux/actions/fontFace.js index 12d32660f..0fb13f699 100644 --- a/src/redux/actions/fontFaceActions.js +++ b/src/redux/actions/fontFace.js @@ -1,4 +1,4 @@ -import { LOAD } from '../constants/fontFaceActionTypes.js'; +import { LOAD } from '../constants/fontFace.js'; export function load(className) { return { diff --git a/src/redux/actions/optionsActions.js b/src/redux/actions/options.js similarity index 96% rename from src/redux/actions/optionsActions.js rename to src/redux/actions/options.js index 6dee94507..a2006d479 100644 --- a/src/redux/actions/optionsActions.js +++ b/src/redux/actions/options.js @@ -1,5 +1,5 @@ import cookie from 'react-cookie'; -import { TOGGLE_READING_MODE, SET_OPTION } from '../constants/optionsActionTypes.js'; +import { TOGGLE_READING_MODE, SET_OPTION } from '../constants/options.js'; export function isReadingMode(globalState) { return globalState.options.isReadingMode; diff --git a/src/redux/actions/SearchActions.js b/src/redux/actions/search.js similarity index 89% rename from src/redux/actions/SearchActions.js rename to src/redux/actions/search.js index f898d22bd..eecac3587 100644 --- a/src/redux/actions/SearchActions.js +++ b/src/redux/actions/search.js @@ -5,7 +5,7 @@ import { SEARCH, SEARCH_SUCCESS, SEARCH_FAIL - } from '../constants/SearchActionTypes.js'; + } from '../constants/search.js'; export function search(params) { return { diff --git a/src/redux/actions/searchActions.js b/src/redux/actions/searchActions.js deleted file mode 100644 index 355c93b0e..000000000 --- a/src/redux/actions/searchActions.js +++ /dev/null @@ -1,21 +0,0 @@ -import { ayahsSchema } from '../schemas'; -import { arrayOf } from 'normalizr'; - -import { - SEARCH, - SEARCH_SUCCESS, - SEARCH_FAIL - } from '../constants/searchActionTypes.js'; - -export function search(params) { - return { - types: [SEARCH, SEARCH_SUCCESS, SEARCH_FAIL], - schema: {results: arrayOf({ayah: ayahsSchema})}, - promise: (client) => client.get('/v2/search', { params }), - params - }; -} - -export function isQueried() { - return false; -} diff --git a/src/redux/actions/SurahsActions.js b/src/redux/actions/surahs.js similarity index 94% rename from src/redux/actions/SurahsActions.js rename to src/redux/actions/surahs.js index 759e06aea..7ee52ae12 100644 --- a/src/redux/actions/SurahsActions.js +++ b/src/redux/actions/surahs.js @@ -7,8 +7,7 @@ import { LOAD_INFO, LOAD_INFO_SUCCESS, LOAD_INFO_FAIL, - SET_CURRENT - } from '../constants/SurahsActionTypes.js' + SET_CURRENT } from '../constants/surahs.js'; export function loadAll() { return { diff --git a/src/redux/actions/surahsActions.js b/src/redux/actions/surahsActions.js deleted file mode 100644 index 008f08926..000000000 --- a/src/redux/actions/surahsActions.js +++ /dev/null @@ -1,49 +0,0 @@ -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'; - -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; -} diff --git a/src/redux/constants/audioPlayerActionTypes.js b/src/redux/constants/audioPlayerActionTypes.js deleted file mode 100644 index e0d43d7a8..000000000 --- a/src/redux/constants/audioPlayerActionTypes.js +++ /dev/null @@ -1,12 +0,0 @@ -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'; diff --git a/src/redux/constants/AudioPlayerActionTypes.js b/src/redux/constants/audioplayer.js similarity index 100% rename from src/redux/constants/AudioPlayerActionTypes.js rename to src/redux/constants/audioplayer.js diff --git a/src/redux/constants/AyahsActionTypes.js b/src/redux/constants/ayahs.js similarity index 100% rename from src/redux/constants/AyahsActionTypes.js rename to src/redux/constants/ayahs.js diff --git a/src/redux/constants/ayahsActionTypes.js b/src/redux/constants/ayahsActionTypes.js deleted file mode 100644 index 4b215a3a8..000000000 --- a/src/redux/constants/ayahsActionTypes.js +++ /dev/null @@ -1,7 +0,0 @@ -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'; diff --git a/src/redux/constants/FontFaceActionTypes.js b/src/redux/constants/fontFace.js similarity index 100% rename from src/redux/constants/FontFaceActionTypes.js rename to src/redux/constants/fontFace.js diff --git a/src/redux/constants/fontFaceActionTypes.js b/src/redux/constants/fontFaceActionTypes.js deleted file mode 100644 index 1dc3a243b..000000000 --- a/src/redux/constants/fontFaceActionTypes.js +++ /dev/null @@ -1 +0,0 @@ -export const LOAD = '@@quran/fontFaces/LOAD'; diff --git a/src/redux/constants/OptionsActionTypes.js b/src/redux/constants/options.js similarity index 100% rename from src/redux/constants/OptionsActionTypes.js rename to src/redux/constants/options.js diff --git a/src/redux/constants/optionsActionTypes.js b/src/redux/constants/optionsActionTypes.js deleted file mode 100644 index ffa608eeb..000000000 --- a/src/redux/constants/optionsActionTypes.js +++ /dev/null @@ -1,2 +0,0 @@ -export const TOGGLE_READING_MODE = '@@quran/options/TOGGLE_READING_MODE'; -export const SET_OPTION = '@@quran/options/SET_OPTION'; diff --git a/src/redux/constants/SearchActionTypes.js b/src/redux/constants/search.js similarity index 100% rename from src/redux/constants/SearchActionTypes.js rename to src/redux/constants/search.js diff --git a/src/redux/constants/searchActionTypes.js b/src/redux/constants/searchActionTypes.js deleted file mode 100644 index 2eeaa1654..000000000 --- a/src/redux/constants/searchActionTypes.js +++ /dev/null @@ -1,3 +0,0 @@ -export const SEARCH = '@@quran/search/LOAD'; -export const SEARCH_SUCCESS = '@@quran/search/LOAD_SUCCESS'; -export const SEARCH_FAIL = '@@quran/search/LOAD_FAIL'; diff --git a/src/redux/constants/SurahsActionTypes.js b/src/redux/constants/surahs.js similarity index 100% rename from src/redux/constants/SurahsActionTypes.js rename to src/redux/constants/surahs.js diff --git a/src/redux/constants/surahsActionTypes.js b/src/redux/constants/surahsActionTypes.js deleted file mode 100644 index b74c0eb4e..000000000 --- a/src/redux/constants/surahsActionTypes.js +++ /dev/null @@ -1,7 +0,0 @@ -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'; diff --git a/src/redux/modules/audioplayer.js b/src/redux/modules/audioplayer.js index f52b6a6b1..caf844e05 100644 --- a/src/redux/modules/audioplayer.js +++ b/src/redux/modules/audioplayer.js @@ -23,7 +23,7 @@ import { TOGGLE_SCROLL, BUILD_ON_CLIENT, UPDATE - } from '../constants/audioPlayerActionTypes.js'; + } from '../constants/audioplayer.js'; export { NEXT, SET_AYAH }; diff --git a/src/redux/modules/ayahs.js b/src/redux/modules/ayahs.js index 80a54299b..a8d84c15d 100644 --- a/src/redux/modules/ayahs.js +++ b/src/redux/modules/ayahs.js @@ -6,7 +6,7 @@ import { SET_CURRENT_AYAH, SET_CURRENT_WORD, CLEAR_CURRENT_WORD - } from '../constants/ayahsActionTypes.js'; + } from '../constants/ayahs.js'; export { LOAD, diff --git a/src/redux/modules/fontFaces.js b/src/redux/modules/fontFaces.js index b3144ad40..6c573f848 100644 --- a/src/redux/modules/fontFaces.js +++ b/src/redux/modules/fontFaces.js @@ -1,6 +1,6 @@ -import { LOAD_SUCCESS } from '../constants/ayahsActionTypes.js'; -import { SEARCH_SUCCESS } from '../constants/searchActionTypes.js'; -import { LOAD } from '../constants/fontFaceActionTypes.js'; +import { LOAD_SUCCESS } from '../constants/ayahs.js'; +import { SEARCH_SUCCESS } from '../constants/search.js'; +import { LOAD } from '../constants/fontFace.js'; export default function reducer(state = {}, action = {}) { switch (action.type) { diff --git a/src/redux/modules/lines.js b/src/redux/modules/lines.js index 2642ddadd..644915648 100644 --- a/src/redux/modules/lines.js +++ b/src/redux/modules/lines.js @@ -3,9 +3,9 @@ import { LOAD as AYAHS_LOAD, LOAD_SUCCESS as AYAHS_LOAD_SUCCESS, LOAD_FAIL as AYAHS_LOAD_FAIL, - } from '../constants/ayahsActionTypes.js'; + } from '../constants/ayahs.js'; -import { SET_CURRENT as SURAHS_SET_CURRENT } from '../constants/surahsActionTypes.js'; +import { SET_CURRENT as SURAHS_SET_CURRENT } from '../constants/surahs.js'; const initialState = { lines: {} diff --git a/src/redux/modules/options.js b/src/redux/modules/options.js index 959baaf64..2851fa49e 100644 --- a/src/redux/modules/options.js +++ b/src/redux/modules/options.js @@ -1,5 +1,5 @@ -import { TOGGLE_READING_MODE, SET_OPTION } from '../constants/optionsActionTypes.js'; +import { TOGGLE_READING_MODE, SET_OPTION } from '../constants/options.js'; const initialState = { isReadingMode: false, diff --git a/src/redux/modules/searchResults.js b/src/redux/modules/searchResults.js index de242573c..67a15b041 100644 --- a/src/redux/modules/searchResults.js +++ b/src/redux/modules/searchResults.js @@ -2,7 +2,7 @@ import { SEARCH, SEARCH_SUCCESS, SEARCH_FAIL - } from '../constants/searchActionTypes.js'; + } from '../constants/search.js'; const initialState = { errored: false, diff --git a/src/redux/modules/surahs.js b/src/redux/modules/surahs.js index fd3af5ad2..dd7ddffec 100644 --- a/src/redux/modules/surahs.js +++ b/src/redux/modules/surahs.js @@ -2,7 +2,7 @@ import { LOAD_SUCCESS, LOAD_FAIL, SET_CURRENT - } from '../constants/surahsActionTypes.js'; + } from '../constants/surahs.js'; const initialState = { errored: false, From 01df278a5303f403a9b52dbc5f80a0c5410ef5c9 Mon Sep 17 00:00:00 2001 From: Sabeur Thabti Date: Tue, 2 Aug 2016 00:16:41 +0100 Subject: [PATCH 08/10] isLoaded is now a helper function, added audioplayer --- src/containers/Surah/connect.js | 3 +- src/helpers/index.js | 8 +++ src/redux/actions/audioplayer.js | 94 ++++++++++++++++++++++++++++++++ src/redux/modules/ayahs.js | 4 +- 4 files changed, 105 insertions(+), 4 deletions(-) create mode 100644 src/helpers/index.js create mode 100644 src/redux/actions/audioplayer.js diff --git a/src/containers/Surah/connect.js b/src/containers/Surah/connect.js index a589f3d15..4edd9819b 100644 --- a/src/containers/Surah/connect.js +++ b/src/containers/Surah/connect.js @@ -6,11 +6,10 @@ import { import { clearCurrent, - isLoaded, load as loadAyahs } from '../../redux/actions/ayahs.js'; -import debug from 'helpers/debug'; +import {isLoaded, debug} from 'helpers'; const ayahRangeSize = 30; diff --git a/src/helpers/index.js b/src/helpers/index.js new file mode 100644 index 000000000..d5c2d2955 --- /dev/null +++ b/src/helpers/index.js @@ -0,0 +1,8 @@ +export function isLoaded(globalState, surahId, from, to) { + return ( + globalState.ayahs.entities[surahId] && + globalState.ayahs.entities[surahId][`${surahId}:${from}`] && + globalState.ayahs.entities[surahId][`${surahId}:${to}`] + ); +} +export { default as debug } from './debug'; diff --git a/src/redux/actions/audioplayer.js b/src/redux/actions/audioplayer.js new file mode 100644 index 000000000..9b8205f9d --- /dev/null +++ b/src/redux/actions/audioplayer.js @@ -0,0 +1,94 @@ +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/audioplayer.js'; + +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 + }; +} diff --git a/src/redux/modules/ayahs.js b/src/redux/modules/ayahs.js index a8d84c15d..1e9f543c0 100644 --- a/src/redux/modules/ayahs.js +++ b/src/redux/modules/ayahs.js @@ -51,12 +51,13 @@ export default function reducer(state = initialState, action = {}) { currentWord: null }; case CLEAR_CURRENT: + const entities = state.entities; return { ...state, current: null, currentWord: null, entities: { - ...state.entities, + ...entities, [action.id]: {} } }; @@ -93,4 +94,3 @@ export default function reducer(state = initialState, action = {}) { return state; } } - From 9f857351b2268def85670957f50e45318fc4526d Mon Sep 17 00:00:00 2001 From: Sabeur Thabti Date: Tue, 2 Aug 2016 00:59:21 +0100 Subject: [PATCH 09/10] fix --- src/containers/Surah/connect.js | 2 +- src/redux/actions/ayahs.js | 8 -------- 2 files changed, 1 insertion(+), 9 deletions(-) diff --git a/src/containers/Surah/connect.js b/src/containers/Surah/connect.js index 4edd9819b..197910c57 100644 --- a/src/containers/Surah/connect.js +++ b/src/containers/Surah/connect.js @@ -9,7 +9,7 @@ import { load as loadAyahs } from '../../redux/actions/ayahs.js'; -import {isLoaded, debug} from 'helpers'; +import {debug, isLoaded} from 'helpers'; const ayahRangeSize = 30; diff --git a/src/redux/actions/ayahs.js b/src/redux/actions/ayahs.js index cca44ad57..6140559a1 100644 --- a/src/redux/actions/ayahs.js +++ b/src/redux/actions/ayahs.js @@ -64,11 +64,3 @@ export function setCurrentWord(id) { id }; } - -export function isLoaded(globalState, surahId, from, to) { - return ( - globalState.ayahs.entities[surahId] && - globalState.ayahs.entities[surahId][`${surahId}:${from}`] && - globalState.ayahs.entities[surahId][`${surahId}:${to}`] - ); -} From 33d51b6fbc12da9cc69188c40a58deffcadd8ffe Mon Sep 17 00:00:00 2001 From: Sabeur Thabti Date: Thu, 4 Aug 2016 14:17:53 +0100 Subject: [PATCH 10/10] action unit tests --- src/redux/actions/spec.js | 43 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 src/redux/actions/spec.js diff --git a/src/redux/actions/spec.js b/src/redux/actions/spec.js new file mode 100644 index 000000000..9d84cc5c3 --- /dev/null +++ b/src/redux/actions/spec.js @@ -0,0 +1,43 @@ +import * as audioplayerActions from './audioplayer.js'; +import * as ayahsActions from './ayahs.js'; +import * as surahsActions from './surahs.js'; +import * as audioplayerConstant from '../constants/audioplayer.js'; +import * as ayahsConstants from '../constants/ayahs.js'; +import * as surahsConstants from '../constants/surahs.js'; + + +describe("action tests", () => { + + it("audioplayer actions", () => { + expect(audioplayerActions.setUserAgent('abc').type).to.equal(audioplayerConstant.SET_USER_AGENT); + expect(audioplayerActions.setCurrentFile('fil').type).to.equal(audioplayerConstant.SET_CURRENT_FILE); + expect(audioplayerActions.setCurrentWord('word').type).to.equal(audioplayerConstant.SET_CURRENT_WORD); + expect(audioplayerActions.play().type).to.equal(audioplayerConstant.PLAY); + expect(audioplayerActions.pause().type).to.equal(audioplayerConstant.PAUSE); + expect(audioplayerActions.next('abc').type).to.equal(audioplayerConstant.NEXT); + expect(audioplayerActions.previous('abc').type).to.equal(audioplayerConstant.PREVIOUS); + expect(audioplayerActions.setRepeat('abc').type).to.equal(audioplayerConstant.SET_REPEAT); + expect(audioplayerActions.toggleScroll().type).to.equal(audioplayerConstant.TOGGLE_SCROLL); + expect(audioplayerActions.buildOnClient('abc').type).to.equal(audioplayerConstant.BUILD_ON_CLIENT); + expect(audioplayerActions.update('abc').type).to.equal(audioplayerConstant.UPDATE); + }); + + it("ayahs actions", () => { + expect(ayahsActions.load(1, 2, 4).types.length).to.equal(3); + expect(ayahsActions.clearCurrent().type).to.equal(ayahsConstants.CLEAR_CURRENT); + expect(ayahsActions.clearCurrentWord(1).type).to.equal(ayahsConstants.CLEAR_CURRENT_WORD); + expect(ayahsActions.setCurrentAyah(1).type).to.equal(ayahsConstants.SET_CURRENT_AYAH); + expect(ayahsActions.setCurrentWord(1).type).to.equal(ayahsConstants.SET_CURRENT_WORD); + }); + + it("surahs actions", () => { + expect(surahsActions.loadAll().types.length).to.equal(3); + expect(surahsActions.load(1).types.length).to.equal(3); + expect(surahsActions.loadInfo('url').types.length).to.equal(3); + expect(surahsActions.setCurrent(1).type).to.equal(surahsConstants.SET_CURRENT); + }); + + + + +});