forked from Sefaria/Sefaria-Mobile
-
Notifications
You must be signed in to change notification settings - Fork 0
/
AboutBox.js
139 lines (132 loc) · 6.02 KB
/
AboutBox.js
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
import React from 'react';
import PropTypes from 'prop-types';
import {
View,
ScrollView,
Text,
} from 'react-native';
import {
LoadingView,
} from './Misc.js';
import HTMLView from 'react-native-htmlview';
import strings from './LocalizedStrings';
import styles from './Styles';
import VersionBlock from './VersionBlock';
class AboutBox extends React.Component {
static propTypes = {
textToc: PropTypes.object,
theme: PropTypes.object.isRequired,
currVersions: PropTypes.object.isRequired,
contentLang: PropTypes.oneOf(["english", "hebrew"]).isRequired,
interfaceLang: PropTypes.oneOf(["english", "hebrew"]).isRequired,
mainVersionLanguage: PropTypes.oneOf(["english", "hebrew", "bilingual"]),
textTitle: PropTypes.string.isRequired,
openUri: PropTypes.func.isRequired,
};
render() {
const d = this.props.textToc;
const vh = this.props.currVersions.he;
const ve = this.props.currVersions.en;
const hei = this.props.interfaceLang === "hebrew";
let detailSection = null;
if (d) {
let authorsEn, authorsHe;
if (d.authors && d.authors.length) {
const authorArrayEn = d.authors.filter((elem) => !!elem.en);
const authorArrayHe = d.authors.filter((elem) => !!elem.he);
authorsEn = [<Text key="authorText">{"Author: "}</Text>];
authorsHe = [<Text key="authorText">{"מחבר: "}</Text>];
authorsEn = authorsEn.concat(authorArrayEn.map(author => <Text key={author.en}>{author.en}</Text> ));
authorsHe = authorsHe.concat(authorArrayHe.map(author => <Text key={author.en}>{author.he}</Text> ));
}
// use compPlaceString and compDateString if available. then use compPlace o/w use pubPlace o/w nothing
let placeTextEn, placeTextHe;
if (d.compPlaceString) {
placeTextEn = d.compPlaceString.en;
placeTextHe = d.compPlaceString.he;
} else if (d.compPlace){
placeTextEn = d.compPlace;
placeTextHe = d.compPlace;
} else if (d.pubPlace) {
placeTextEn = d.pubPlace;
placeTextHe = d.pubPlace;
}
let dateTextEn, dateTextHe;
if (d.compDateString) {
dateTextEn = d.compDateString.en;
dateTextHe = d.compDateString.he
} else if (d.compDate) {
if (d.errorMargin !== 0) {
//I don't think there are any texts which are mixed BCE/CE
const lowerDate = Math.abs(d.compDate - d.errorMargin);
const upperDate = Math.abs(d.compDate - d.errorMargin);
dateTextEn = `(c.${lowerDate} - c.${upperDate} ${d.compDate < 0 ? "BCE" : "CE"})`;
dateTextHe = `(${lowerDate} - ${upperDate} ${d.compDate < 0 ? 'לפנה"ס בקירוב' : 'לספירה בקירוב'})`;
} else {
dateTextEn = `(${Math.abs(d.compDate)} ${d.compDate < 0 ? "BCE" : "CE"})`;
dateTextHe = `(${Math.abs(d.compDate)} ${d.compDate < 0 ? 'לפנה"ס בקירוב' : 'לספירה בקירוב'})`;
}
} else if (d.pubDate) {
dateTextEn = `(${Math.abs(d.pubDate)} ${d.pubDate < 0 ? "BCE" : "CE"})`;
dateTextHe = `(${Math.abs(d.pubDate)} ${d.pubDate < 0 ? 'לפנה"ס בקירוב' : 'לספירה בקירוב'})`;
}
detailSection = (
<View>
<View style={[styles.aboutHeaderWrapper, this.props.theme.bordered]}>
<Text style={[styles.aboutHeader, this.props.theme.secondaryText, hei ? styles.heInt : null]}>{strings.aboutThisText}</Text>
</View>
<Text style={[styles.aboutTitle, hei ? styles.he : styles.en, this.props.theme.text]}>
{ hei ? d.heTitle : d.title }
</Text>
{ authorsEn && authorsEn.length ?
<Text style={[styles.aboutSubtitle, hei ? styles.heInt : styles.enInt, this.props.theme.secondaryText]}>
{ hei ? authorsHe : authorsEn}
</Text> : null
}
{ !!placeTextEn || !!dateTextEn ?
<Text style={[styles.aboutSubtitle, hei ? styles.heInt : styles.enInt, this.props.theme.secondaryText]}>
{ hei ? `נוצר/נערך: ${!!placeTextHe ? placeTextHe : ""} ${!!dateTextHe ? dateTextHe : ""}` : `Composed: ${!!placeTextEn ? placeTextEn : ""} ${!!dateTextEn ? dateTextEn : ""}`}
</Text> : null
}
{ hei ? (!!d.heDesc ? <Text style={[styles.aboutDescription, styles.heInt, this.props.theme.text]}>{d.heDesc}</Text> : null) :
(!!d.enDesc ? <Text style={[styles.aboutDescription, styles.enInt, this.props.theme.text]}>{d.enDesc}</Text> : null)
}
</View>
);
}
const versionSectionHe =
(!!vh && !vh.disabled ? <View style={styles.currVersionSection}>
<View style={[styles.aboutHeaderWrapper, this.props.theme.bordered]}>
<Text style={[styles.aboutHeader, this.props.theme.secondaryText, hei ? styles.heInt : null]}>{ strings.currentHebrewVersion }</Text>
</View>
<VersionBlock
theme={this.props.theme}
version={vh}
interfaceLang={this.props.interfaceLang}
openUri={this.props.openUri}
/>
</View> : null );
const versionSectionEn =
(!!ve && !ve.disabled ? <View style={styles.currVersionSection}>
<View style={[styles.aboutHeaderWrapper, this.props.theme.bordered]}>
<Text style={[styles.aboutHeader, this.props.theme.secondaryText, hei ? styles.heInt : null]}>{ strings.currentEnglishVersion }</Text>
</View>
<VersionBlock
theme={this.props.theme}
version={ve}
interfaceLang={this.props.interfaceLang}
openUri={this.props.openUri}
/>
</View> : null );
return (
<ScrollView contentContainerStyle={[styles.aboutBoxScrollView, styles.readerSideMargin]}>
{ detailSection }
{ this.props.mainVersionLanguage === "english" ?
(<View>{versionSectionEn}{versionSectionHe}</View>) :
(<View>{versionSectionHe}{versionSectionEn}</View>)
}
</ScrollView>
);
}
}
export default AboutBox;