forked from Sefaria/Sefaria-Mobile
-
Notifications
You must be signed in to change notification settings - Fork 0
/
VersionBlock.js
110 lines (103 loc) · 3.82 KB
/
VersionBlock.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
import React, { useContext, useCallback } from 'react';
import PropTypes from 'prop-types';
import {
View,
Text,
TouchableOpacity,
} from 'react-native';
import {
SText,
} from './Misc';
import { GlobalStateContext, getTheme } from './StateManager';
import HTMLView from 'react-native-htmlview'; //to convert html'afied JSON to something react can render (https://github.com/jsdf/react-native-htmlview)
import styles from './Styles.js';
const VersionBlock = ({
version,
openVersionInSidebar,
openVersionInReader,
isCurrent,
openUri,
}) => {
const { themeStr, textLanguage, interfaceLanguage } = useContext(GlobalStateContext);
const theme = getTheme(themeStr);
const onVersionTitleClick = useCallback(() => {
const action = openVersionInSidebar ? openVersionInSidebar : openVersionInReader;
if (action) {
action(version.versionTitle, version.versionTitleInHebrew, version.language);
}
}, [version]);
const onSelectVersionClick = useCallback(() => {
if (openVersionInReader) {
openVersionInReader(version.versionTitle, version.language);
}
}, [version]);
let versionTitle, versionSource, shortVersionSource, license, licenseURL, versionNotes;
if (Sefaria.util.get_menu_language(interfaceLanguage, textLanguage) == "hebrew") {
versionTitle = version['versionTitleInHebrew'] || version['versionTitle'];
versionSource = version['versionSource'];
shortVersionSource = Sefaria.util.parseURLhost(versionSource);
license = version['license'];
licenseURL = Sefaria.util.getLicenseURL(license);
versionNotes = version['versionNotesInHebrew'] || version['versionNotes'];
} else {
versionTitle = version['versionTitle'];
versionSource = version['versionSource'];
shortVersionSource = Sefaria.util.parseURLhost(versionSource);
license = version['license'];
licenseURL = Sefaria.util.getLicenseURL(license);
versionNotes = version['versionNotes'];
}
const textAlign = { textAlign: "left" };
return (
<View>
{
versionTitle ?
(openVersionInSidebar ?
<TouchableOpacity onPress={onVersionTitleClick}>
<Text style={[styles.en, styles.textTocVersionTitle, textAlign, theme.text]}>
{versionTitle}
</Text>
</TouchableOpacity> :
<SText lang={"english"} style={[styles.en, styles.textTocVersionTitle, textAlign, theme.text]}>
{versionTitle}
</SText>)
: null
}
<View style={styles.textTocVersionInfo}>
{ versionSource ?
<TouchableOpacity onPress={() => { openUri(versionSource); }}>
<Text style={[styles.textTocVersionInfoText, theme.tertiaryText]}>{shortVersionSource || versionSource}</Text>
</TouchableOpacity>
: null
}
{ versionSource && (license && license !== "unknown") ?
<Text style={[styles.dot, theme.tertiaryText]}>•</Text>
: null
}
{ license && license !== "unknown" ?
<TouchableOpacity onPress={() => licenseURL ? openUri(licenseURL) : null}>
<Text style={[styles.textTocVersionInfoText, theme.tertiaryText]}>{license}</Text>
</TouchableOpacity>
: null
}
</View>
{ versionNotes ?
<HTMLView
value={"<div>"+version['versionNotes']+"</div>"}
onLinkPress={(url) => openUri(url) }
stylesheet={styles}
textComponentProps={{style: [styles.textTocVersionNotes, textAlign, theme.tertiaryText]}}
/>
: null
}
</View>
);
}
VersionBlock.propTypes = {
version: PropTypes.object.isRequired,
openVersionInSidebar: PropTypes.func,
openVersionInReader: PropTypes.func,
isCurrent: PropTypes.bool,
openUri: PropTypes.func.isRequired,
};
export default VersionBlock;