|
@@ -6,6 +6,7 @@ import {Chip, Searchbar, withTheme} from 'react-native-paper';
|
6
|
6
|
import AuthenticatedScreen from "../../components/Amicale/AuthenticatedScreen";
|
7
|
7
|
import i18n from "i18n-js";
|
8
|
8
|
import ClubListItem from "../../components/Lists/ClubListItem";
|
|
9
|
+import {isItemInCategoryFilter, stringMatchQuery} from "../../utils/Search";
|
9
|
10
|
|
10
|
11
|
type Props = {
|
11
|
12
|
navigation: Object,
|
|
@@ -27,7 +28,6 @@ class ClubListScreen extends React.Component<Props, State> {
|
27
|
28
|
colors: Object;
|
28
|
29
|
|
29
|
30
|
getRenderItem: Function;
|
30
|
|
- originalData: Array<Object>;
|
31
|
31
|
categories: Array<Object>;
|
32
|
32
|
|
33
|
33
|
constructor(props) {
|
|
@@ -69,26 +69,17 @@ class ClubListScreen extends React.Component<Props, State> {
|
69
|
69
|
* @param str The new search string
|
70
|
70
|
*/
|
71
|
71
|
onSearchStringChange = (str: string) => {
|
72
|
|
- this.updateFilteredData(this.sanitizeString(str), null);
|
|
72
|
+ this.updateFilteredData(str, null);
|
73
|
73
|
};
|
74
|
74
|
|
75
|
|
- /**
|
76
|
|
- * Sanitizes the given string to improve search performance
|
77
|
|
- *
|
78
|
|
- * @param str The string to sanitize
|
79
|
|
- * @return {string} The sanitized string
|
80
|
|
- */
|
81
|
|
- sanitizeString(str: string): string {
|
82
|
|
- return str.toLowerCase().normalize("NFD").replace(/[\u0300-\u036f]/g, "");
|
83
|
|
- }
|
84
|
|
-
|
85
|
75
|
keyExtractor = (item: Object) => {
|
86
|
|
- return item.name + item.logo;
|
|
76
|
+ return item.id.toString();
|
87
|
77
|
};
|
88
|
78
|
|
89
|
79
|
getScreen = (data: Object) => {
|
90
|
80
|
this.categories = data.categories;
|
91
|
81
|
return (
|
|
82
|
+ //$FlowFixMe
|
92
|
83
|
<FlatList
|
93
|
84
|
data={data.clubs}
|
94
|
85
|
keyExtractor={this.keyExtractor}
|
|
@@ -112,7 +103,7 @@ class ClubListScreen extends React.Component<Props, State> {
|
112
|
103
|
if (index === -1)
|
113
|
104
|
newCategoriesState.push(categoryId);
|
114
|
105
|
else
|
115
|
|
- newCategoriesState.splice(index);
|
|
106
|
+ newCategoriesState.splice(index,1);
|
116
|
107
|
}
|
117
|
108
|
if (filterStr !== null || categoryId !== null)
|
118
|
109
|
this.setState({
|
|
@@ -121,21 +112,14 @@ class ClubListScreen extends React.Component<Props, State> {
|
121
|
112
|
})
|
122
|
113
|
}
|
123
|
114
|
|
124
|
|
- isItemInCategoryFilter(categories: Array<string>) {
|
125
|
|
- for (const category of categories) {
|
126
|
|
- if (this.state.currentlySelectedCategories.indexOf(category) !== -1)
|
127
|
|
- return true;
|
128
|
|
- }
|
129
|
|
- return false;
|
130
|
|
- }
|
131
|
|
-
|
132
|
|
- getChipRender = (category: Object) => {
|
|
115
|
+ getChipRender = (category: Object, key: string) => {
|
133
|
116
|
const onPress = this.onChipSelect.bind(this, category.id);
|
134
|
117
|
return <Chip
|
135
|
|
- selected={this.isItemInCategoryFilter([category.id])}
|
|
118
|
+ selected={isItemInCategoryFilter(this.state.currentlySelectedCategories, [category.id])}
|
136
|
119
|
mode={'outlined'}
|
137
|
120
|
onPress={onPress}
|
138
|
121
|
style={{marginRight: 5, marginBottom: 5}}
|
|
122
|
+ key={key}
|
139
|
123
|
>
|
140
|
124
|
{category.name}
|
141
|
125
|
</Chip>;
|
|
@@ -144,7 +128,7 @@ class ClubListScreen extends React.Component<Props, State> {
|
144
|
128
|
getListHeader() {
|
145
|
129
|
let final = [];
|
146
|
130
|
for (let i = 0; i < this.categories.length; i++) {
|
147
|
|
- final.push(this.getChipRender(this.categories[i]));
|
|
131
|
+ final.push(this.getChipRender(this.categories[i], this.categories[i].id));
|
148
|
132
|
}
|
149
|
133
|
return <View style={{
|
150
|
134
|
justifyContent: 'space-around',
|
|
@@ -163,9 +147,9 @@ class ClubListScreen extends React.Component<Props, State> {
|
163
|
147
|
|
164
|
148
|
shouldRenderItem(item) {
|
165
|
149
|
let shouldRender = this.state.currentlySelectedCategories.length === 0
|
166
|
|
- || this.isItemInCategoryFilter(item.category);
|
|
150
|
+ || isItemInCategoryFilter(this.state.currentlySelectedCategories, item.category);
|
167
|
151
|
if (shouldRender)
|
168
|
|
- shouldRender = this.sanitizeString(item.name).includes(this.state.currentSearchString);
|
|
152
|
+ shouldRender = stringMatchQuery(item.name, this.state.currentSearchString);
|
169
|
153
|
return shouldRender;
|
170
|
154
|
}
|
171
|
155
|
|