-
Notifications
You must be signed in to change notification settings - Fork 0
/
SourcesPage.js
88 lines (84 loc) · 3.13 KB
/
SourcesPage.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
import React, { Component } from 'react';
import { View, Text, Button, FlatList } from 'react-native';
import { inject, observer, Observer } from 'mobx-react';
import SourcesPageModel from './ViewModels/SourcesPageModel';
import CheckListItem from './CheckListItem';
import CheckList from './CheckList';
import SearchPageModel from './ViewModels/SearchPageModel';
import LanguagePageModel from './ViewModels/LanguagePageModel';
import CountryPageModel from './ViewModels/CountryPageModel';
import { moderateScale, scale, verticalScale } from 'react-native-size-matters';
import { Divider } from 'react-native-elements';
class SourcesPage extends Component {
static navigationOptions= {
title: 'Sources'
}
static getDerivedStateFromProps(props, state) {
console.log('props changed');
return { refresh: !state.refresh };
}
constructor() {
super();
this.state = {
refresh: false
};
}
componentDidMount() {
this.load();
this.props.navigation.addListener('willFocus', () => this.load);
}
load() {
SourcesPageModel.getInstance().getSources();
}
capitalizeFirstLetter(string) {
if (string) {
return string.charAt(0).toUpperCase() + string.slice(1);
}
return null;
}
renderText() {
let category = this.capitalizeFirstLetter(SearchPageModel.getInstance().selectedCategory);
if (category) {
category = 'Category: ' + category;
}
let languages = LanguagePageModel.getInstance().selectedLanguages();
if (languages) {
languages = languages.map(language => language.name);
languages = languages.toString();
languages = languages.replace(/,/g, ', ');
if (LanguagePageModel.getInstance().selectedLanguages().length > 1) {
languages = 'Languages: ' + languages;
} else {
languages = 'Language: ' + languages;
}
}
let countries = CountryPageModel.getInstance().selectedCountries();
if (countries) {
countries = countries.map(country => country.name);
// need to do same as with langauges if implementing multiselect countries
countries = 'Country: ' + countries;
}
const shouldRender = (category || languages || countries);
return shouldRender ?
<View style={{ flex: 1, paddingHorizontal: scale(20), paddingVertical: verticalScale(10), justifyContent: 'space-between' }}>
<Text style={{ alignSelf: 'center' }}>{category} {languages} {countries}</Text>
<Divider />
</View>
:
null
;
}
render() {
console.log('render sourcePage');
return (
<View style={{ flex: 1 }}>
<CheckList
listHeaderComponent={this.renderText()}
data={this.props.sourcesPageModel.sources}
bindingContext={SourcesPageModel.getInstance()}
/>
</View>
);
}
}
export default inject('sourcesPageModel')(observer(SourcesPage));