-
-
Notifications
You must be signed in to change notification settings - Fork 20
/
ReaderNavigationSheetList.js
142 lines (120 loc) · 3.91 KB
/
ReaderNavigationSheetList.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
'use strict';
import PropTypes from 'prop-types';
import React from 'react';
import {
Text,
View,
FlatList,
RefreshControl,
} from 'react-native';
import {
CategoryColorLine,
} from './Misc.js';
import styles from './Styles.js';
import strings from "./LocalizedStrings";
import {DirectedButton} from "./Misc";
import SheetResult from "./SheetResult";
import MySheetResult from "./MySheetResult";
class ReaderNavigationSheetList extends React.Component {
static propTypes = {
theme: PropTypes.object.isRequired,
themeStr: PropTypes.string.isRequired,
menuOpen: PropTypes.oneOf(["mySheets"]),
};
constructor(props) {
super(props);
this.state = {
sheets: [],
refreshing: true,
};
}
componentDidMount() { this.loadData(); }
loadData = async () => {
const { menuOpen } = this.props;
try {
let sheets;
if (menuOpen === 'mySheets') {
sheets = await Sefaria.api.mySheets();
}
this.setState({ sheets, refreshing: false });
} catch (error) {
this.setState({ refreshing: false });
console.log(error);
}
}
onRefresh = () => { this.setState({ refreshing: true }, this.loadData); }
_keyExtractor = (sheet, pos) => {
return sheet.id + "|" + pos;
};
renderItem = ({ item }) => {
return (
<View style={[this.props.theme.menu]}>
{
this.props.menuOpen === 'mySheets' ? (
<MySheetResult
title={item.title}
heTitle={item.title}
views={item.views}
topics={item.topics}
created={item.created}
isPrivate={item.status === 'unlisted'}
onPress={() => this.props.openRef(item.id,item)}
/>
) : (
<SheetResult
title={item.title}
heTitle={item.title}
ownerImageUrl={item.ownerImageUrl}
ownerName={item.ownerName}
views={item.views}
onPress={() => this.props.openRef(item.id,item)}
/>
)
}
</View>
);
}
render() {
const showHebrew = this.props.interfaceLanguage == "hebrew";
const title = strings.mySheets;
return(
<View style={[styles.menu, this.props.theme.menu]}>
<CategoryColorLine category="Sheets" />
<View style={[styles.header, this.props.theme.header]}>
<DirectedButton
onPress={this.props.onBack}
themeStr={this.props.themeStr}
imageStyle={[styles.menuButton, styles.directedButton]}
direction="back"
language="english"
/>
{showHebrew ?
<Text style={[styles.he, styles.categoryTitle, this.props.theme.categoryTitle, {textTransform: "uppercase"}]}>{title}</Text> :
<Text style={[styles.en, styles.categoryTitle, this.props.theme.categoryTitle, {textTransform: "uppercase"}]}>{title}</Text>
}
<DirectedButton
onPress={this.props.onBack}
themeStr={this.props.themeStr}
imageStyle={[styles.menuButton, styles.directedButton, {opacity: 0}]}
direction="back"
language="english"
/>
</View>
<FlatList
style={{}}
data={this.state.sheets}
keyExtractor={(item, index) => ''+item.id}
renderItem={this.renderItem}
refreshControl={
<RefreshControl
refreshing={this.state.refreshing}
onRefresh={this.onRefresh}
tintColor="#CCCCCC"
style={{ backgroundColor: 'transparent' }} />
}
/>
</View>
)
}
}
export default ReaderNavigationSheetList;