Skip to content
This repository was archived by the owner on Jun 28, 2021. It is now read-only.

Commit c93c9a5

Browse files
naveed-ahmadmmahalwy
authored andcommitted
Foot note (#710)
* added foot note popup * lint happy
1 parent b71bb46 commit c93c9a5

File tree

11 files changed

+161
-15
lines changed

11 files changed

+161
-15
lines changed

src/components/Translation/index.js

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,55 @@
11
/* eslint-disable react/prefer-stateless-function */
22
import React, { Component, PropTypes } from 'react';
3+
import { connect } from 'react-redux';
34

45
import { translationType } from 'types';
6+
import { loadFootNote } from 'redux/actions/footNote';
57

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

8-
export default class Translation extends Component {
10+
class Translation extends Component {
911
static propTypes = {
1012
translation: translationType.isRequired,
11-
index: PropTypes.number
13+
index: PropTypes.number,
14+
loadFootNote: PropTypes.func.isRequired,
1215
};
1316

17+
componentDidMount() {
18+
const { index } = this.props;
19+
let trans;
20+
21+
if (__CLIENT__) {
22+
trans = document.getElementById(`trans${index}`).children[1]; // eslint-disable-line no-undef
23+
trans.addEventListener('click', this.fetchFootNote, true);
24+
}
25+
}
26+
27+
componentWillUnmount() {
28+
const { index } = this.props;
29+
let trans;
30+
31+
if (__CLIENT__) {
32+
trans = document.getElementById(`trans${index}`).children[1]; // eslint-disable-line no-undef
33+
trans.removeEventListener('click', this.fetchFootNote, true);
34+
}
35+
}
36+
37+
fetchFootNote = (event) => {
38+
const { loadFootNote } = this.props; // eslint-disable-line no-shadow
39+
40+
if (event.target.nodeName === 'SUP' && event.target.attributes.foot_note) {
41+
event.preventDefault();
42+
loadFootNote(event.target.attributes.foot_note.value);
43+
}
44+
}
45+
1446
render() {
1547
const { translation, index } = this.props;
1648
const lang = translation.languageName;
1749
const isArabic = lang === 'arabic';
1850

1951
return (
20-
<div id={index} className={`${styles.translation} ${isArabic && 'arabic'} translation`}>
52+
<div id={`trans${index}`} className={`${styles.translation} ${isArabic && 'arabic'} translation`}>
2153
<h4 className="montserrat">{translation.resourceName}</h4>
2254
<h2 className={`${isArabic ? 'text-right' : 'text-left'} text-translation times-new`}>
2355
<small
@@ -29,3 +61,7 @@ export default class Translation extends Component {
2961
);
3062
}
3163
}
64+
65+
export default connect(state => ({}), // eslint-disable-line no-unused-vars
66+
{ loadFootNote }
67+
)(Translation);

src/components/Verse/index.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,10 @@ class Verse extends Component {
9595

9696
renderTranslations() {
9797
const { verse, match } = this.props;
98-
9998
const array = match || verse.translations || [];
10099

101-
return array.map((translation, index) => (
102-
<Translation translation={translation} index={index} key={index} />
100+
return array.map(translation => (
101+
<Translation translation={translation} index={translation.id} key={translation.id} />
103102
));
104103
}
105104

src/containers/App/index.js

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ import metricsConfig from 'helpers/metrics';
1515
import Footer from 'components/Footer';
1616
import NoScript from 'components/NoScript';
1717
import { removeMedia } from 'redux/actions/media';
18+
import { removeFootNote } from 'redux/actions/footNote';
19+
20+
import Loader from 'quran-components/lib/Loader';
21+
22+
import { footNoteType } from 'types';
1823

1924
import authConnect from './connect';
2025

@@ -28,10 +33,13 @@ class App extends Component {
2833
content: PropTypes.object
2934
}).isRequired,
3035
removeMedia: PropTypes.func.isRequired,
36+
removeFootNote: PropTypes.func.isRequired,
3137
children: PropTypes.element,
3238
main: PropTypes.element,
3339
nav: PropTypes.element,
3440
sidebar: PropTypes.element,
41+
footNote: footNoteType,
42+
loadingFootNote: PropTypes.bool
3543
};
3644

3745
static contextTypes = {
@@ -49,10 +57,20 @@ class App extends Component {
4957
sidebar,
5058
children,
5159
media,
60+
footNote,
61+
loadingFootNote,
5262
removeMedia, // eslint-disable-line no-shadow
63+
removeFootNote, // eslint-disable-line no-shadow
5364
...props
5465
} = this.props;
5566
debug('component:APPLICATION', 'Render');
67+
let footNoteText;
68+
69+
if (footNote) {
70+
footNoteText = footNote.text;
71+
} else {
72+
footNoteText = <Loader isActive={loadingFootNote} />;
73+
}
5674

5775
return (
5876
<div>
@@ -91,6 +109,7 @@ class App extends Component {
91109
{children || main}
92110
<SmartBanner title="The Noble Quran - القرآن الكريم" button="Install" />
93111
<Footer />
112+
94113
<Modal bsSize="large" show={media && media.content} onHide={removeMedia}>
95114
<ModalHeader closeButton>
96115
<ModalTitle className="montserrat">
@@ -104,6 +123,20 @@ class App extends Component {
104123
/>
105124
</ModalBody>
106125
</Modal>
126+
127+
<Modal bsSize="large" show={!!footNote || loadingFootNote} onHide={removeFootNote}>
128+
<ModalHeader closeButton>
129+
<ModalTitle className="montserrat">
130+
Foot note
131+
</ModalTitle>
132+
</ModalHeader>
133+
<ModalBody>
134+
<div
135+
className={`${footNote && footNote.languageName}`}
136+
dangerouslySetInnerHTML={{ __html: footNoteText }}
137+
/>
138+
</ModalBody>
139+
</Modal>
107140
</div>
108141
);
109142
}
@@ -113,6 +146,10 @@ const metricsApp = metrics(metricsConfig)(App);
113146
const AsyncApp = asyncConnect([{ promise: authConnect }])(metricsApp);
114147

115148
export default connect(
116-
state => ({ media: state.media }),
117-
{ removeMedia }
149+
state => ({
150+
media: state.media,
151+
footNote: state.footNote.footNote,
152+
loadingFootNote: state.footNote.loadingFootNote
153+
}),
154+
{ removeMedia, removeFootNote }
118155
)(AsyncApp);

src/redux/actions/footNote.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import {
2+
LOAD_FOOT_NOTE,
3+
LOAD_FOOT_NOTE_SUCCESS,
4+
REMOVE_FOOT_NOTE,
5+
LOAD_FOOT_NOTE_FAIL
6+
} from 'redux/constants/footNote.js';
7+
8+
export const loadFootNote = footNoteId => ({
9+
types: [LOAD_FOOT_NOTE, LOAD_FOOT_NOTE_SUCCESS, LOAD_FOOT_NOTE_FAIL],
10+
promise: client => client.get(`/api/v3/foot_notes/${footNoteId}`)
11+
});
12+
13+
export const removeFootNote = () => ({
14+
type: REMOVE_FOOT_NOTE
15+
});

src/redux/actions/options.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,6 @@ export function setOption(payload) {
3030
};
3131
}
3232

33-
export const loadRecitations = () => ({
34-
types: [LOAD_RECITERS, LOAD_RECITERS_SUCCESS, LOAD_RECITERS_FAIL],
35-
promise: client => client.get('/api/v3/options/recitations')
36-
});
37-
3833
export function setUserAgent(userAgent) {
3934
return {
4035
type: SET_USER_AGENT,
@@ -46,3 +41,8 @@ export const loadTranslations = () => ({
4641
types: [LOAD_TRANSLATIONS, LOAD_TRANSLATIONS_SUCCESS, LOAD_TRANSLATIONS_FAIL],
4742
promise: client => client.get('/api/v3/options/translations')
4843
});
44+
45+
export const loadRecitations = () => ({
46+
types: [LOAD_RECITERS, LOAD_RECITERS_SUCCESS, LOAD_RECITERS_FAIL],
47+
promise: client => client.get('/api/v3/options/recitations')
48+
});

src/redux/constants/footNote.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export const LOAD_FOOT_NOTE = '@@quran/footNote/LOAD';
2+
export const LOAD_FOOT_NOTE_SUCCESS = '@@quran/footNote/LOAD_SUCCESS';
3+
export const LOAD_FOOT_NOTE_FAIL = '@@quran/footNote/LOAD_FAIL';
4+
export const REMOVE_FOOT_NOTE = '@@quran/footNote/REMOVE';

src/redux/modules/footNote.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import {
2+
LOAD_FOOT_NOTE,
3+
LOAD_FOOT_NOTE_SUCCESS,
4+
REMOVE_FOOT_NOTE
5+
} from 'redux/constants/footNote.js';
6+
7+
const initialState = {
8+
footNote: null,
9+
loadingFootNote: false
10+
};
11+
12+
export default function reducer(state = initialState, action = {}) {
13+
switch (action.type) {
14+
case LOAD_FOOT_NOTE: {
15+
return {
16+
...state,
17+
loadingFootNote: true,
18+
footNote: null,
19+
};
20+
}
21+
case LOAD_FOOT_NOTE_SUCCESS: {
22+
return {
23+
...state,
24+
loadingFootNote: false,
25+
footNote: action.result.footNote
26+
};
27+
}
28+
case REMOVE_FOOT_NOTE: {
29+
return {
30+
...state,
31+
loadingFootNote: false,
32+
footNote: null,
33+
};
34+
}
35+
default:
36+
return state;
37+
}
38+
}

src/redux/modules/options.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {
55
SET_USER_AGENT,
66
LOAD_TRANSLATIONS,
77
LOAD_TRANSLATIONS_SUCCESS
8-
} from 'redux/constants/options.js';
8+
} from 'redux/constants/options.js';
99

1010
const initialState = {
1111
isReadingMode: false,
@@ -17,6 +17,8 @@ const initialState = {
1717
translations: [20],
1818
tooltip: 'translation',
1919
userAgent: null,
20+
footNote: null,
21+
loadingFootNote: false,
2022
options: {
2123
recitations: [],
2224
translations: []

src/redux/modules/reducer.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import fontFaces from './fontFaces';
1313
import auth from './auth';
1414
import bookmarks from './bookmarks';
1515
import media from './media';
16+
import footNote from './footNote';
1617

1718
export default combineReducers({
1819
routing: routerReducer,
@@ -27,5 +28,6 @@ export default combineReducers({
2728
lines,
2829
searchResults,
2930
suggestResults,
30-
options
31+
options,
32+
footNote
3133
});

src/styles/main.scss

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,12 @@ li em{
167167
.urdu, .punjabi{
168168
direction: rtl;
169169
font-family: 'Nafees';
170+
text-align: right;
171+
line-height: 30px;
172+
173+
#arabic{
174+
font-family: initial;
175+
}
170176
}
171177

172178
.modal-backdrop{

0 commit comments

Comments
 (0)