From cef4cc57045cd6fa86283246d118c0d1ac85a4bf Mon Sep 17 00:00:00 2001 From: Gersom van Ginkel Date: Thu, 19 Jul 2018 12:41:54 +0200 Subject: [PATCH] Added classifications filter --- src/api/products.js | 4 +- src/config/index.js | 4 +- src/modules/Home/Home.js | 2 +- src/modules/Search/Search.js | 9 +- src/modules/Search/components/FilterModal.js | 89 +++++++++++++++----- src/modules/Search/components/FilterTags.js | 7 +- 6 files changed, 88 insertions(+), 27 deletions(-) diff --git a/src/api/products.js b/src/api/products.js index f6d294e..5067955 100644 --- a/src/api/products.js +++ b/src/api/products.js @@ -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); diff --git a/src/config/index.js b/src/config/index.js index 5706abc..043e2a4 100644 --- a/src/config/index.js +++ b/src/config/index.js @@ -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]; diff --git a/src/modules/Home/Home.js b/src/modules/Home/Home.js index 489dd54..3b2a035 100644 --- a/src/modules/Home/Home.js +++ b/src/modules/Home/Home.js @@ -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 = () => { diff --git a/src/modules/Search/Search.js b/src/modules/Search/Search.js index 0a2a3b0..d860184 100644 --- a/src/modules/Search/Search.js +++ b/src/modules/Search/Search.js @@ -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, }, }; } @@ -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 }); @@ -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 ( diff --git a/src/modules/Search/components/FilterModal.js b/src/modules/Search/components/FilterModal.js index 3f9e2d8..62e229a 100644 --- a/src/modules/Search/components/FilterModal.js +++ b/src/modules/Search/components/FilterModal.js @@ -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 ( @@ -43,7 +29,11 @@ class FilterModal extends React.PureComponent { onRequestClose={this.props.onClose} animationType="fade" > - + + + VEGANISTISCH + + {this.renderClassification()} VERKOOPPUNT @@ -54,12 +44,53 @@ class FilterModal extends React.PureComponent { {this.renderCategories()} - + {this.renderApplyButton()} ); } + 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 ( + + this.handleClassificationChange('YES')} + > + + 100% + + this.handleClassificationChange('MAYBE')} + > + + Inclusief misschien + + + ); + }; + + handleShopChange = shopCode => { + this.props.onChange({ + ...this.props.filters, + shopCode: this.props.filters.shopCode === shopCode ? null : shopCode, + }); + }; renderShops = () => { return ( @@ -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 ( @@ -107,7 +144,7 @@ class FilterModal extends React.PureComponent { renderApplyButton = () => { return ( - +