Skip to content
This repository has been archived by the owner on Feb 1, 2022. It is now read-only.

Commit

Permalink
Added classifications filter
Browse files Browse the repository at this point in the history
  • Loading branch information
gersomvg committed Jul 19, 2018
1 parent 36035c1 commit cef4cc5
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 27 deletions.
4 changes: 2 additions & 2 deletions src/api/products.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import { API_ENDPOINT } from 'config';

const products = {};

products.get = ({ limit, offset, nextLink, name, categoryId, shopCode } = {}) => {
products.get = ({ limit, offset, nextLink, name, categoryId, shopCode, classifications } = {}) => {
let url = nextLink;
if (!url) {
const params = qs.stringify({ limit, offset, name, categoryId, shopCode });
const params = qs.stringify({ limit, offset, name, categoryId, shopCode, classifications });
url = `${API_ENDPOINT}/product${params}`;
}
return fetcher(url);
Expand Down
4 changes: 2 additions & 2 deletions src/config/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export * from './styling';

export const API_ENDPOINT = {
//development: 'http://localhost:3001/api/v1',
development: 'https://plenty-staging.herokuapp.com/api/v1',
development: 'http://localhost:3001/api/v1',
// development: 'https://plenty-staging.herokuapp.com/api/v1',
production: 'https://plenty-production.herokuapp.com/api/v1',
}[process.env.NODE_ENV];
2 changes: 1 addition & 1 deletion src/modules/Home/Home.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class Home extends React.Component {
};

handleOnPressCategory = categoryId => {
this.props.navigation.push('Search', { categoryId });
this.props.navigation.push('Search', { categoryId, classifications: 'YES' });
};

handleOnPressCreate = () => {
Expand Down
9 changes: 8 additions & 1 deletion src/modules/Search/Search.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ class Search extends React.PureComponent {
filters: {
shopCode: null,
categoryId: _.get(props, 'navigation.state.params.categoryId') || null,
classifications:
_.get(props, 'navigation.state.params.classifications') || null,
},
};
}
Expand All @@ -50,6 +52,7 @@ class Search extends React.PureComponent {
name: this.state.searchValue,
categoryId: this.state.filters.categoryId,
shopCode: this.state.filters.shopCode,
classifications: this.state.filters.classifications,
});
const data = await this.fetch.promise;
this.setState({ fetchStatus: 'loaded', products: data.items, nextLink: data.nextLink });
Expand Down Expand Up @@ -116,7 +119,11 @@ class Search extends React.PureComponent {
};

render() {
const isAnyFilterActive = !!(this.state.filters.categoryId || this.state.filters.shopCode);
const isAnyFilterActive = !!(
this.state.filters.categoryId ||
this.state.filters.shopCode ||
this.state.filters.classifications
);
return (
<RN.KeyboardAvoidingView behavior="padding" style={styles.screen}>
<ElevatedHeader style={styles.header}>
Expand Down
89 changes: 69 additions & 20 deletions src/modules/Search/components/FilterModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,6 @@ class FilterModal extends React.PureComponent {
onClose: PT.func.isRequired,
};

handleShopChange = shopCode => {
this.props.onChange({
...this.props.filters,
shopCode: this.props.filters.shopCode === shopCode ? null : shopCode,
});
};

handleCategoryChange = categoryId => {
this.props.onChange({
...this.props.filters,
categoryId: this.props.filters.categoryId === categoryId ? null : categoryId,
});
};

render() {
const { filters, onPressFilter, onRemoveFilter } = this.props;
return (
Expand All @@ -43,7 +29,11 @@ class FilterModal extends React.PureComponent {
onRequestClose={this.props.onClose}
animationType="fade"
>
<RN.ScrollView style={styles.container}>
<RN.ScrollView contentContainerStyle={styles.container}>
<Text align="left" font="brand">
VEGANISTISCH
</Text>
{this.renderClassification()}
<Text align="left" font="brand">
VERKOOPPUNT
</Text>
Expand All @@ -54,12 +44,53 @@ class FilterModal extends React.PureComponent {
{this.renderCategories()}
</RN.ScrollView>
<IconButton onPress={this.props.onClose} icon="close" style={styles.close} />
<LinearGradient colors={['rgba(255,255,255,0)', 'white']} style={styles.gradient} />
<LinearGradient
colors={['rgba(255,255,255,0)', 'white']}
style={styles.gradient}
pointerEvents="none"
/>
{this.renderApplyButton()}
</RN.Modal>
);
}

handleClassificationChange = option => {
const { classifications } = this.props.filters;
const commaDelimited = { YES: 'YES', MAYBE: 'YES,MAYBE' }[option];
this.props.onChange({
...this.props.filters,
classification: commaDelimited === classification ? null : commaDelimited,
});
};
renderClassification = () => {
return (
<RN.View style={[styles.filterGroup, styles.classGroup]}>
<RN.TouchableOpacity
activeOpacity={0.5}
style={styles.class}
onPress={() => this.handleClassificationChange('YES')}
>
<RadioBox checked={this.props.filters.classifications === 'YES'} />
<Text style={styles.classText}>100%</Text>
</RN.TouchableOpacity>
<RN.TouchableOpacity
activeOpacity={0.5}
style={styles.class}
onPress={() => this.handleClassificationChange('MAYBE')}
>
<RadioBox checked={this.props.filters.classifications === 'YES,MAYBE'} />
<Text style={styles.classText}>Inclusief misschien</Text>
</RN.TouchableOpacity>
</RN.View>
);
};

handleShopChange = shopCode => {
this.props.onChange({
...this.props.filters,
shopCode: this.props.filters.shopCode === shopCode ? null : shopCode,
});
};
renderShops = () => {
return (
<RN.View style={[styles.filterGroup, styles.shopGroup]}>
Expand All @@ -80,6 +111,12 @@ class FilterModal extends React.PureComponent {
);
};

handleCategoryChange = categoryId => {
this.props.onChange({
...this.props.filters,
categoryId: this.props.filters.categoryId === categoryId ? null : categoryId,
});
};
renderCategories = () => {
return (
<RN.View style={styles.filterGroup}>
Expand Down Expand Up @@ -107,7 +144,7 @@ class FilterModal extends React.PureComponent {

renderApplyButton = () => {
return (
<RN.View style={styles.applyWrapper}>
<RN.View style={styles.applyWrapper} pointerEvents="box-none">
<Button onPress={this.props.onClose} label="Bekijk producten" />
</RN.View>
);
Expand All @@ -117,7 +154,7 @@ class FilterModal extends React.PureComponent {
const styles = RN.StyleSheet.create({
container: {
paddingTop: getSafeTopHeight() + 28,
paddingBottom: getSafeBottomHeight() + 16,
paddingBottom: getSafeBottomHeight() + 48,
paddingHorizontal: 16,
},
close: {
Expand All @@ -141,12 +178,24 @@ const styles = RN.StyleSheet.create({
},
filterGroup: {
marginTop: 25,
marginBottom: 50,
marginBottom: 40,
},
shopGroup: {
flexDirection: 'row',
flexWrap: 'wrap',
marginBottom: 40,
},
classGroup: {
flexDirection: 'row',
alignItems: 'center',
},
class: {
flexDirection: 'row',
alignItems: 'center',
height: 48,
marginRight: 16,
},
classText: {
marginLeft: 8,
},
shop: {
alignItems: 'center',
Expand Down
7 changes: 6 additions & 1 deletion src/modules/Search/components/FilterTags.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class FilterTags extends React.PureComponent {
horizontal
showsHorizontalScrollIndicator={false}
>
{['shopCode', 'categoryId']
{['shopCode', 'categoryId', 'classifications']
.filter(key => filters[key] !== null)
.map(this.renderTag)}
</RN.ScrollView>
Expand All @@ -61,6 +61,11 @@ class FilterTags extends React.PureComponent {
if (key === 'shopCode') {
label = this.props.shops.find(shop => shop.code === this.props.filters[key]).name;
}
if (key === 'classifications') {
label = { YES: '100% Vegan', 'YES,MAYBE': '(Misschien) vegan' }[
this.props.filters.classifications
];
}
return (
<RN.View style={styles.tag} key={key}>
<RN.TouchableOpacity
Expand Down

0 comments on commit cef4cc5

Please sign in to comment.