-
Notifications
You must be signed in to change notification settings - Fork 156
/
DrawerScreen.js
150 lines (141 loc) · 3.61 KB
/
DrawerScreen.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
143
144
145
146
147
148
149
150
import React, { Component, useContext, useState } from 'react';
import { connect } from 'react-redux';
import { View, StyleSheet } from 'react-native';
import PropTypes from 'prop-types';
import {
getProductsForCategoryOrChild,
addFilterData,
getSearchProducts,
} from '../../actions';
import { Button, Text, Input } from '../common';
import { ThemeContext } from '../../theme';
import { translate } from '../../i18n';
const DrawerScreen = props => {
const [maxValue, setMaxValue] = useState('');
const [minValue, setMinValue] = useState('');
const theme = useContext(ThemeContext);
const onApplyPressed = () => {
const { currencyRate } = props;
const priceFilter = {
price: {
condition: 'from,to',
value: `${(minValue / currencyRate).toFixed(2)},${(
maxValue / currencyRate
).toFixed(2)}`,
},
};
props.addFilterData(priceFilter);
if (props.filters.categoryScreen) {
props.getProductsForCategoryOrChild(
props.category,
null,
props.filters.sortOrder,
priceFilter,
);
props.addFilterData({ categoryScreen: false });
} else {
props.getSearchProducts(
props.searchInput,
null,
props.filters.sortOrder,
priceFilter,
);
}
props.navigation.closeDrawer();
};
const {
container,
InputContainer,
textStyle,
minInputStyle,
maxInputStyle,
dashTextStyle,
} = styles;
return (
<View style={container(theme)}>
<View style={InputContainer(theme)}>
<Text type="heading" style={textStyle(theme)}>
Price:
</Text>
<Input
containerStyle={minInputStyle}
placeholder={translate('common.min')}
value={minValue}
keyboardType="numeric"
onChangeText={minValue => setMinValue(minValue)}
/>
<Text style={dashTextStyle(theme)}>-</Text>
<Input
containerStyle={maxInputStyle}
value={maxValue}
placeholder={translate('common.max')}
keyboardType="numeric"
onChangeText={maxValue => setMaxValue(maxValue)}
/>
</View>
<View style={styles.buttonStyleWrap}>
<Button onPress={onApplyPressed} style={styles.buttonStyle}>
{translate('common.apply')}
</Button>
</View>
</View>
);
};
const styles = StyleSheet.create({
container: theme => ({
flex: 1,
flexDirection: 'column',
alignItems: 'stretch',
backgroundColor: theme.colors.background,
}),
InputContainer: theme => ({
flexDirection: 'row',
alignItems: 'center',
backgroundColor: theme.colors.surface,
paddingVertical: theme.spacing.large,
}),
minInputStyle: {
width: 50,
},
maxInputStyle: {
width: 50,
},
textStyle: theme => ({
paddingLeft: 50,
paddingRight: theme.spacing.large,
}),
dashTextStyle: theme => ({
paddingHorizontal: theme.spacing.large,
}),
buttonStyle: {
width: '100%',
},
buttonStyleWrap: {
flex: 1,
justifyContent: 'flex-end',
},
});
DrawerScreen.propTypes = {
currencyRate: PropTypes.number,
};
DrawerScreen.defaultProps = {
currencyRate: 1,
};
const mapStateToProps = ({ category, filters, search, magento }) => {
const currentCategory = category.current.category;
const { searchInput } = search;
const {
currency: { displayCurrencyExchangeRate: currencyRate },
} = magento;
return {
filters,
searchInput,
currencyRate,
category: currentCategory,
};
};
export default connect(mapStateToProps, {
getProductsForCategoryOrChild,
addFilterData,
getSearchProducts,
})(DrawerScreen);