-
Notifications
You must be signed in to change notification settings - Fork 156
/
CategoryTree.js
60 lines (51 loc) · 1.4 KB
/
CategoryTree.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
import React, { useContext, useEffect } from 'react';
import { RefreshControl, View } from 'react-native';
import { connect } from 'react-redux';
import { Spinner } from '../common/index';
import { initMagento, getCategoryTree } from '../../actions/index';
import CategoryTreeList from './CategoryTreeList';
import { ThemeContext } from '../../theme';
const CategoryTree = ({
categoryTree,
refreshing,
getCategoryTree: _getCategoryTree,
}) => {
const theme = useContext(ThemeContext);
useEffect(() => {
_getCategoryTree();
}, [_getCategoryTree]);
const onRefresh = () => {
_getCategoryTree(true);
};
const renderContent = () => {
if (categoryTree) {
return (
<CategoryTreeList
categories={categoryTree.children_data}
refreshControl={
<RefreshControl refreshing={refreshing} onRefresh={onRefresh} />
}
/>
);
}
return <Spinner />;
};
return <View style={styles.container(theme)}>{renderContent()}</View>;
};
CategoryTree.navigationOptions = {
title: 'Categories'.toUpperCase(),
headerBackTitle: ' ',
};
const styles = {
container: theme => ({
flex: 1,
backgroundColor: theme.colors.background,
}),
};
const mapStateToProps = ({ categoryTree }) => ({
categoryTree,
refreshing: categoryTree.refreshing,
});
export default connect(mapStateToProps, { initMagento, getCategoryTree })(
CategoryTree,
);