forked from Sefaria/Sefaria-Mobile
-
Notifications
You must be signed in to change notification settings - Fork 0
/
AboutBox.js
160 lines (148 loc) · 6.42 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
import React from 'react';
import PropTypes from 'prop-types';
import {
View,
ScrollView,
Text,
} from 'react-native';
import {
LoadingView,
} from './Misc.js';
import { GlobalStateContext, getTheme } from './StateManager';
import HTMLView from 'react-native-htmlview';
import strings from './LocalizedStrings';
import styles from './Styles';
import VersionBlock from './VersionBlock';
var moment = require("moment");
const AboutBox = ({ textToc, currVersions, textTitle, sheet, openUri }) => {
const { themeStr, interfaceLanguage, textLanguage } = React.useContext(GlobalStateContext);
const theme = getTheme(themeStr);
const d = textToc;
const vh = currVersions.he;
const ve = currVersions.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 versionSectionHe =
(!!vh && !vh.disabled ? <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}
/>
</View> : null );
const versionSectionEn =
(!!ve && !ve.disabled ? <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}
/>
</View> : null );
return (
<ScrollView contentContainerStyle={[styles.aboutBoxScrollView, styles.readerSideMargin]}>
{ detailSection }
{ textLanguage === "english" ?
(<View>{versionSectionEn}{versionSectionHe}</View>) :
(<View>{versionSectionHe}{versionSectionEn}</View>)
}
</ScrollView>
);
};
AboutBox.propTypes = {
textToc: PropTypes.object,
sheet: PropTypes.object,
currVersions: PropTypes.object.isRequired,
textTitle: PropTypes.string.isRequired,
openUri: PropTypes.func.isRequired,
};
export default AboutBox;