forked from Sefaria/Sefaria-Mobile
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSearchSheetResult.js
71 lines (66 loc) · 2.37 KB
/
SearchSheetResult.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
'use strict';
import PropTypes from 'prop-types';
import React, { useContext } from 'react';
import {
StyleSheet,
Text,
TouchableOpacity,
View,
Image
} from 'react-native';
import HTMLView from 'react-native-htmlview'; //to convert html'afied JSON to something react can render (https://github.com/jsdf/react-native-htmlview)
import { GlobalStateContext, getTheme } from './StateManager';
import styles from './Styles.js';
const SearchSheetResult = ({
text,
title,
heTitle,
textType,
onPress,
ownerImageUrl,
ownerName,
tags,
views,
}) => {
const { interfaceLanguage, themeStr } = useContext(GlobalStateContext);
const theme = getTheme(themeStr);
const refTitleStyle = interfaceLanguage === "hebrew" ? styles.he : styles.en;
return (
<TouchableOpacity
style={[styles.searchTextResult, theme.searchTextResult]}
onPress={onPress}
delayPressIn={200}
>
<View>
<View>
<Text style={[refTitleStyle, styles.textListCitation, theme.text]}>{title.replace(/\s\s+/g, ' ')}</Text>
</View>
{text ?
(<HTMLView
value= {textType == "hebrew" ? "<hediv>"+text.replace(/(\r\n|\n|\r)/gm, "").substring(0, 124)+"...</hediv>" : "<endiv>"+text.replace(/(\r\n|\n|\r)/gm, "").substring(0, 124)+"...</endiv>"}
stylesheet={styles}
textComponentProps={{style: [textType == "hebrew" ? styles.hebrewText : styles.englishText, theme.searchResultSummaryText]}}
/>) : null
}
<View style={{ flexDirection: (interfaceLanguage == "hebrew" ? "row-reverse" : "row"), flex:1, marginTop: 10}}>
<Image
style={styles.userAvatar}
source={{uri: ownerImageUrl}}
/>
<View style={{flexDirection: "column", flex: 1, justifyContent: "space-between", marginHorizontal: 10}}>
<Text style={[styles.enInt, {alignSelf: "flex-start", color:"#666"}]}>{ownerName}</Text>
<Text style={[{color:"#999"}, styles.enInt]}>{views} Views {tags.length > 0 ? "· " + tags.join(", ") : null}</Text>
</View>
</View>
</View>
</TouchableOpacity>
);
}
SearchSheetResult.propTypes = {
text: PropTypes.string,
title: PropTypes.string,
heTitle: PropTypes.string,
textType: PropTypes.oneOf(["english","hebrew"]),
onPress: PropTypes.func.isRequired
};
export default SearchSheetResult;