forked from Sefaria/Sefaria-Mobile
-
Notifications
You must be signed in to change notification settings - Fork 0
/
AutocompletePage.js
94 lines (84 loc) · 2.65 KB
/
AutocompletePage.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
'use strict';
import PropTypes from 'prop-types';
import React from 'react';
import {
TouchableOpacity,
Text,
View,
} from 'react-native';
import {
CategoryColorLine,
} from './Misc';
import AutocompleteList from './AutocompleteList';
import SearchBar from './SearchBar';
import styles from './Styles';
import strings from './LocalizedStrings';
class AutocompletePage extends React.Component {
static propTypes = {
interfaceLanguage: PropTypes.oneOf(["english", "hebrew"]).isRequired,
theme: PropTypes.object.isRequired,
themeStr: PropTypes.string.isRequired,
onBack: PropTypes.func.isRequired,
openSearch: PropTypes.func.isRequired,
setIsNewSearch: PropTypes.func.isRequired,
query: PropTypes.string.isRequired,
onChange: PropTypes.func.isRequired,
openRef: PropTypes.func.isRequired,
openTextTocDirectly: PropTypes.func.isRequired,
openTopic: PropTypes.func.isRequired,
setCategories: PropTypes.func.isRequired,
openUri: PropTypes.func.isRequired,
searchType: PropTypes.oneOf(['text', 'sheet']).isRequired,
};
componentDidMount() {
this._originalQuery = this.props.query;
this._autocomplete.onQueryChange(this.props.query);
}
back = () => {
const q = this.props.query || this._originalQuery;
if (!q) {
this.props.openNav();
} else {
this.search(q);
}
};
search = query => {
this.props.openSearch('text', query);
this.props.openSearch('sheet', query);
};
_getAutocompleteRef = ref => {
this._autocomplete = ref;
}
render() {
return (
<View style={[styles.menu, this.props.theme.menu]}>
<CategoryColorLine category={"Other"} />
<SearchBar
autoFocus
onBack={this.props.onBack}
leftMenuButton="back"
search={this.props.openSearch}
query={this.props.query}
searchType={this.props.searchType}
setIsNewSearch={this.props.setIsNewSearch}
onChange={this.props.onChange}
hideSearchButton={true}
/>
<AutocompleteList
openUri={this.props.openUri}
interfaceLanguage={this.props.interfaceLanguage}
ref={this._getAutocompleteRef}
theme={this.props.theme}
themeStr={this.props.themeStr}
query={this.props.query}
openRef={this.props.openRef}
openTextTocDirectly={this.props.openTextTocDirectly}
openTopic={this.props.openTopic}
setCategories={this.props.setCategories}
search={this.search}
/>
</View>
);
}
}
export default AutocompletePage;