This repository was archived by the owner on Jun 28, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 372
Expand file tree
/
Copy pathindex.js
More file actions
307 lines (266 loc) · 8.35 KB
/
index.js
File metadata and controls
307 lines (266 loc) · 8.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
import React, { Component, PropTypes } from 'react';
import Link from 'react-router/lib/Link';
import Element from 'react-scroll/lib/components/Element';
import { connect } from 'react-redux';
import Loadable from 'react-loadable';
import { verseType, matchType, surahType } from 'types';
import ComponentLoader from 'components/ComponentLoader';
import LocaleFormattedMessage from 'components/LocaleFormattedMessage';
import Word from 'components/Word';
import Translation from 'components/Translation';
import debug from 'helpers/debug';
const styles = require('./style.scss');
const Copy = Loadable({
loader: () => import('components/Copy'),
LoadingComponent: ComponentLoader
});
const Share = Loadable({
loader: () => import('components/Share'),
LoadingComponent: ComponentLoader
});
class Verse extends Component {
static propTypes = {
isSearched: PropTypes.bool,
verse: verseType.isRequired,
chapter: surahType.isRequired,
bookmarked: PropTypes.bool, // TODO: Add this for search
bookmarkActions: PropTypes.shape({
isLoaded: PropTypes.func.isRequired,
load: PropTypes.func.isRequired,
addBookmark: PropTypes.func.isRequired,
removeBookmark: PropTypes.func.isRequired,
}),
mediaActions: PropTypes.shape({
setMedia: PropTypes.func.isRequired,
removeMedia: PropTypes.func.isRequired,
}),
audioActions: PropTypes.shape({
pause: PropTypes.func.isRequired,
setAyah: PropTypes.func.isRequired,
play: PropTypes.func.isRequired,
setCurrentWord: PropTypes.func.isRequired,
}), // not required because in search it is not.
match: PropTypes.arrayOf(matchType),
isPlaying: PropTypes.bool,
isAuthenticated: PropTypes.bool,
tooltip: PropTypes.string,
currentWord: PropTypes.number, // gets passed in an integer, null by default
iscurrentVerse: PropTypes.bool,
currentVerse: PropTypes.string,
userAgent: PropTypes.func
};
static defaultProps = {
currentWord: null,
isSearched: false
};
shouldComponentUpdate(nextProps) {
const conditions = [
this.props.verse !== nextProps.verse,
this.props.bookmarked !== nextProps.bookmarked,
this.props.tooltip !== nextProps.tooltip,
this.props.currentWord !== nextProps.currentWord,
this.props.iscurrentVerse !== nextProps.iscurrentVerse
];
if (this.props.match) {
conditions.push(this.props.match.length !== nextProps.match.length);
}
return conditions.some(condition => condition);
}
handlePlay(verse) {
const { isPlaying, audioActions } = this.props;
const { pause, setAyah, play } = audioActions;
if (isPlaying) {
pause();
}
setAyah(verse.verseKey);
play();
}
renderTranslations() {
const { verse, match } = this.props;
const array = match || verse.translations || [];
return array.map((translation, index) => (
<Translation translation={translation} index={index} key={index} />
));
}
renderMedia() {
const { verse, mediaActions, isSearched } = this.props;
if (isSearched || !verse.mediaContents) return false;
return (
<div>
{
verse.mediaContents.map((content, index) => (
<div
className={`${styles.translation} translation`}
key={index}
>
<h2 className="text-translation times-new">
<small>
<a
tabIndex="-1"
className="pointer"
onClick={() => mediaActions.setMedia(content)}
data-metrics-event-name="Media Click"
data-metrics-media-content-url={content.url}
data-metrics-media-content-id={content.id}
data-metrics-media-content-verse-key={verse.verseKey}
>
<LocaleFormattedMessage
id="verse.media.lectureFrom"
defaultMessage="Watch lecture by {from}"
values={{ from: content.authorName }}
/>
</a>
</small>
</h2>
</div>
))
}
</div>
);
}
renderText() {
const { verse, tooltip, currentVerse, isPlaying, audioActions, isSearched, userAgent } = this.props; // eslint-disable-line max-len
// NOTE: Some 'word's are glyphs (jeem). Not words and should not be clicked for audio
let wordAudioPosition = -1;
const renderText = userAgent.isChrome || userAgent.isOpera || userAgent.isBot;
const text = verse.words.map(word => ( // eslint-disable-line
<Word
word={word}
key={`${word.position}-${word.code}-${word.lineNum}`}
currentVerse={currentVerse}
tooltip={tooltip}
isPlaying={isPlaying}
audioActions={audioActions}
audioPosition={word.wordId ? wordAudioPosition += 1 : null}
isSearched={isSearched}
useTextFont={renderText}
/>
));
return (
<h1 className={`${styles.font} text-right text-arabic`}>
<p>
{text}
</p>
</h1>
);
}
renderPlayLink() {
const { isSearched, verse, currentVerse, isPlaying } = this.props;
const playing = verse.verseKey === currentVerse && isPlaying;
if (!isSearched) {
return (
<a
tabIndex="-1"
onClick={() => this.handlePlay(verse)}
className="text-muted"
>
<i className={`ss-icon ${playing ? 'ss-pause' : 'ss-play'} vertical-align-middle`} />{' '}
<LocaleFormattedMessage
id={playing ? 'actions.pause' : 'actions.play'}
defaultMessage={playing ? 'Pause' : 'Play'}
/>
</a>
);
}
return false;
}
renderCopyLink() {
const { isSearched, verse } = this.props;
if (!isSearched) {
return (
<Copy text={verse.textMadani} verseKey={verse.verseKey} />
);
}
return false;
}
renderBookmark() {
const { verse, bookmarked, isAuthenticated, bookmarkActions, isSearched } = this.props;
if (isSearched || !isAuthenticated) return false;
if (bookmarked) {
return (
<a
tabIndex="-1"
onClick={() => bookmarkActions.removeBookmark(verse.verseKey)}
className="text-muted"
>
<strong>
<i className="ss-icon ss-bookmark vertical-align-middle" />{' '}
<LocaleFormattedMessage
id="verse.bookmarked"
defaultMessage="Bookmarked"
/>
</strong>
</a>
);
}
return (
<a
tabIndex="-1"
onClick={() => bookmarkActions.addBookmark(verse.verseKey)}
className="text-muted"
>
<i className="ss-icon ss-bookmark vertical-align-middle" />{' '}
<LocaleFormattedMessage
id="verse.bookmark"
defaultMessage="Bookmark"
/>
</a>
);
}
renderAyahBadge() {
const { isSearched } = this.props;
let metric;
const content = (
<h4>
<span className={`label label-default ${styles.label}`}>
{this.props.verse.verseKey}
</span>
</h4>
);
if (isSearched) {
metric = 'Verse:Searched:Link';
} else {
metric = 'Verse:Link';
}
return (
<Link
to={`/${this.props.verse.chapterId}/${this.props.verse.verseNumber}`}
data-metrics-event-name={metric}
>
{content}
</Link>
);
}
renderControls() {
const { chapter, verse } = this.props;
return (
<div className={`col-md-1 col-sm-1 ${styles.controls}`}>
{this.renderAyahBadge()}
{this.renderPlayLink()}
{this.renderCopyLink()}
{this.renderBookmark()}
<Share chapter={chapter} verseKey={verse.verseKey} />
</div>
);
}
render() {
const { verse, iscurrentVerse } = this.props;
debug('component:Verse', `Render ${this.props.verse.verseKey}`);
return (
<Element
name={`verse:${verse.verseKey}`}
className={`row ${iscurrentVerse && 'highlight'} ${styles.container}`}
>
{this.renderControls()}
<div className="col-md-11 col-sm-11">
{this.renderText()}
{this.renderTranslations()}
{this.renderMedia()}
</div>
</Element>
);
}
}
export default connect(state => ({
userAgent: state.options.userAgent
}))(Verse);