-
-
Notifications
You must be signed in to change notification settings - Fork 21
/
AboutBox.js
180 lines (168 loc) · 7.38 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
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
import React from 'react';
import PropTypes from 'prop-types';
import {
View,
ScrollView,
Text,
} from 'react-native';
import { GlobalStateContext, getTheme } from './StateManager';
import strings from './LocalizedStrings';
import styles from './Styles';
import VersionBlock from './VersionBlock';
var moment = require("moment");
const AboutBox = ({ textToc, currVersionObjects, openFilter, sheet, openUri, segmentRef, versions }) => {
const { themeStr, interfaceLanguage, textLanguage } = React.useContext(GlobalStateContext);
const theme = getTheme(themeStr);
const d = textToc;
const vh = currVersionObjects.he;
const ve = currVersionObjects.en;
const hei = interfaceLanguage === "hebrew";
if (sheet) {
return (
<ScrollView contentContainerStyle={[styles.aboutBoxScrollView, styles.readerSideMargin]}>
<View>
<View style={[styles.aboutHeaderWrapper, theme.bordered]}>
<Text style={[styles.aboutHeader, theme.secondaryText, hei ? styles.heInt : null]}>{strings.aboutThisText}</Text>
</View>
<Text style={[styles.aboutTitle, hei ? styles.he : styles.en, theme.text]}>
{ Sefaria.util.stripHtml(sheet.title) }
</Text>
<Text style={[styles.aboutSubtitle, hei ? styles.heInt : styles.enInt, theme.secondaryText]}>
{sheet.ownerName}
</Text>
<Text style={[styles.aboutSubtitle, hei ? styles.heInt : styles.enInt, theme.secondaryText]}>
Created {moment(sheet.dateCreated, "YYYY-MM-DDTHH:mm:ss.SSS").fromNow()}
</Text>
<Text style={[styles.aboutDescription, styles.enInt, theme.text]}>{sheet.summary}</Text>
</View>
</ScrollView>
);
}
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, theme.bordered]}>
<Text style={[styles.aboutHeader, theme.secondaryText, hei ? styles.heInt : null]}>{strings.aboutThisText}</Text>
</View>
<Text style={[styles.aboutTitle, hei ? styles.he : styles.en, theme.text]}>
{ hei ? d.heTitle : d.title }
</Text>
{ authorsEn && authorsEn.length ?
<Text style={[styles.aboutSubtitle, hei ? styles.heInt : styles.enInt, theme.secondaryText]}>
{ hei ? authorsHe : authorsEn}
</Text> : null
}
{ !!placeTextEn || !!dateTextEn ?
<Text style={[styles.aboutSubtitle, hei ? styles.heInt : styles.enInt, theme.secondaryText]}>
{ hei ? `נוצר/נערך: ${!!placeTextHe ? placeTextHe : ""} ${!!dateTextHe ? dateTextHe : ""}` : `Composed: ${!!placeTextEn ? placeTextEn : ""} ${!!dateTextEn ? dateTextEn : ""}`}
</Text> : null
}
{ hei ? (!!d.heDesc ? <Text style={[styles.aboutDescription, styles.heInt, theme.text]}>{d.heDesc}</Text> : null) :
(!!d.enDesc ? <Text style={[styles.aboutDescription, styles.enInt, theme.text]}>{d.enDesc}</Text> : null)
}
</View>
);
}
const showSourceVersionDetails = textLanguage !== 'english';
const showTranslationVersionDetails = textLanguage !== 'hebrew';
const versionSectionHe =
(!!vh && showSourceVersionDetails ? <View style={styles.currVersionSection}>
<View style={[styles.aboutHeaderWrapper, theme.bordered]}>
<Text style={[styles.aboutHeader, theme.secondaryText, hei ? styles.heInt : null]}>{ strings.currentHebrewVersion }</Text>
</View>
<VersionBlock
version={vh}
openUri={openUri}
segmentRef={segmentRef}
/>
</View> : null );
const versionSectionEn =
(!!ve && showTranslationVersionDetails ? <View style={styles.currVersionSection}>
<View style={[styles.aboutHeaderWrapper, theme.bordered]}>
<Text style={[styles.aboutHeader, theme.secondaryText, hei ? styles.heInt : null]}>{ strings.currentEnglishVersion }</Text>
</View>
<VersionBlock
version={ve}
openUri={openUri}
segmentRef={segmentRef}
/>
</View> : null );
const otherPrimaryVersions = versions.filter((v) => v.isPrimary && v.versionTitle !== vh.versionTitle);
const versionBlocks = (
otherPrimaryVersions.length > 0 && <View style={styles.currVersionSection}>
<View style={[styles.aboutHeaderWrapper, theme.bordered]}>
<Text style={[styles.aboutHeader, theme.secondaryText, hei ? styles.heInt : null]}>{ strings.otherPrimaryVersions }</Text>
</View>
{otherPrimaryVersions.map((v) =>
(<VersionBlock
openUri={openUri}
openFilter={openFilter}
segmentRef={segmentRef}
version={v}
key={v.versionTitle}
/>)
)}
</View>
);
return (
<ScrollView contentContainerStyle={[styles.aboutBoxScrollView, styles.readerSideMargin]}>
{ detailSection }
{ textLanguage === "english" ?
(<View>{versionSectionEn}{versionSectionHe}</View>) :
(<View>{versionSectionHe}{versionSectionEn}</View>)
}
{ versionBlocks }
</ScrollView>
);
};
AboutBox.propTypes = {
textToc: PropTypes.object,
sheet: PropTypes.object,
currVersionObjects: PropTypes.object.isRequired,
openFilter: PropTypes.func.isRequired,
openUri: PropTypes.func.isRequired,
segmentRef: PropTypes.string.isRequired,
versions: PropTypes.array.isRequired,
};
export default AboutBox;