Skip to content

Saleor Core: the high performance, composable, headless commerce API.

Add mobile devives check functions

Krzysztof Białogłowicz0985b05e99ce
diff --git a/saleor/static/js/components/categoryPage/PriceFilter.js b/saleor/static/js/components/categoryPage/PriceFilter.js
index 253ab37c67..ea647bd10a 100644
--- a/saleor/static/js/components/categoryPage/PriceFilter.js
+++ b/saleor/static/js/components/categoryPage/PriceFilter.js
@@ -1,19 +1,14 @@
import React, { Component, PropTypes } from 'react';
import FilterHeader from './FilterHeader';
+import {isMobile} from '../utils';
export default class PriceFilter extends Component {
constructor(props) {
super(props);
- if (window.innerWidth <= 700) {
this.state = {
- visibility: false
+ visibility: !isMobile()
};
- } else {
- this.state = {
- visibility: true
- };
- }
}
static propTypes = {
diff --git a/saleor/static/js/components/categoryPage/ProductFilters.js b/saleor/static/js/components/categoryPage/ProductFilters.js
index 5595bc9c79..3fc0cb6070 100644
--- a/saleor/static/js/components/categoryPage/ProductFilters.js
+++ b/saleor/static/js/components/categoryPage/ProductFilters.js
@@ -3,6 +3,7 @@ import Relay from 'react-relay';
import AttributeInput from './AttributeInput';
import FilterHeader from './FilterHeader';
+import {isMobile} from '../utils';
class ProductFilters extends Component {
@@ -36,15 +37,9 @@ class ProductFilters extends Component {
componentWillMount() {
this.props.attributes.map((attribute) => {
const attrValue = `${attribute.name}`;
- if (window.innerWidth <= 700) {
this.setState({
- visibility: Object.assign(this.state.visibility, {[attrValue]: false})
+ visibility: Object.assign(this.state.visibility, {[attrValue]: !isMobile()})
});
- } else {
- this.setState({
- visibility: Object.assign(this.state.visibility, {[attrValue]: true})
- });
- }
});
}
diff --git a/saleor/static/js/components/utils.js b/saleor/static/js/components/utils.js
new file mode 100644
index 0000000000..15a6274f17
--- /dev/null
+++ b/saleor/static/js/components/utils.js
@@ -0,0 +1,20 @@
+export const xsBreakpoint = 576;
+export const smBreakpoint = 768;
+export const mdBreakpoint = 992;
+export const lgBreakpoint = 1200;
+
+export const isMobile = () => {
+ if(window.innerWidth < smBreakpoint) {
+ return true;
+ } else {
+ return false;
+ }
+}
+
+export const isTablet = () => {
+ if(window.innerWidth >= smBreakpoint && window.innerWidth <= mdBreakpoint) {
+ return true;
+ } else {
+ return false;
+ }
+}
\ No newline at end of file