Skip to content

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

Fix components structure

Krzysztof Białogłowiczbd16d6c5629f
diff --git a/saleor/static/js/category.js b/saleor/static/js/category.js
new file mode 100644
index 0000000000..8e15944cf5
--- /dev/null
+++ b/saleor/static/js/category.js
@@ -0,0 +1,8 @@
+import React from 'react'
+import ReactDOM from 'react-dom'
+
+import { CategoryPage } from './components/categoryPage'
+
+ReactDOM.render(
+ <CategoryPage />, document.getElementById('category-page')
+);
diff --git a/saleor/static/js/components/categoryPage.js b/saleor/static/js/components/categoryPage.js
new file mode 100644
index 0000000000..97dc30719b
--- /dev/null
+++ b/saleor/static/js/components/categoryPage.js
@@ -0,0 +1,23 @@
+import React, { Component, findDOMNode, PropTypes } from 'react'
+
+import { ProductList } from './productList'
+import { ProductFilters } from './productFilters'
+
+export class CategoryPage extends Component {
+
+ render() {
+ return(
+ <div className="row">
+ <div className="col-md-3">
+ <ProductFilters />
+ </div>
+ <div className="col-md-9">
+ <div className="row">
+ <ProductList />
+ </div>
+ </div>
+ </div>
+ )
+ }
+
+}
\ No newline at end of file
diff --git a/saleor/static/js/components/productFilters.js b/saleor/static/js/components/productFilters.js
new file mode 100644
index 0000000000..2df6b3eb67
--- /dev/null
+++ b/saleor/static/js/components/productFilters.js
@@ -0,0 +1,18 @@
+import React, { Component, findDOMNode, PropTypes } from 'react'
+
+import { ProductList } from './productList'
+
+export class ProductFilters extends Component {
+
+ render() {
+ return(
+ <div>
+ <button className="btn btn-danger">Red</button>
+ <button className="btn btn-success">Green</button>
+ <button className="btn btn-default">Cancel</button>
+ </div>
+ )
+
+ }
+
+}
\ No newline at end of file
diff --git a/saleor/static/js/components/productList.js b/saleor/static/js/components/productList.js
new file mode 100644
index 0000000000..c307508cd2
--- /dev/null
+++ b/saleor/static/js/components/productList.js
@@ -0,0 +1,73 @@
+import React, { Component, findDOMNode, PropTypes } from 'react'
+
+export class ProductList extends Component {
+
+ static propTypes = {
+ className: PropTypes.string,
+ categoryId: PropTypes.number,
+ color: PropTypes.array,
+ size: PropTypes.array,
+ minPrice: PropTypes.number,
+ maxPrice: PropTypes.number
+ };
+
+ state = {
+ data: [],
+ };
+
+ componentWillMount() {
+ fetch("https://private-58ac5-saleor.apiary-mock.com/products/", {
+ method: 'GET',
+ }).then(res => {
+ res.json().then((data) => {
+ this.setState({
+ data: data
+ });
+ });
+ });
+ }
+
+ componentWillReceiveProps(nextProps) {
+ let url = "https://private-58ac5-saleor.apiary-mock.com/products/" + nextProps.color
+ fetch(url, {
+ method: 'GET',
+ }).then(res => {
+ res.json().then((data) => {
+ this.setState({
+ data: data
+ });
+ });
+ });
+ }
+
+ render() {
+
+ const { data } = this.state;
+ const { color } = this.props;
+
+ return (
+ <div>
+ {data.map((product) => {
+ return (
+ <div key={product.id} className="col-xs-12 col-sm-6 col-md-4 col-lg-3" itemScope itemType="https://schema.org/Product">
+ <div className="panel panel-default text-center">
+ <div className="panel-body">
+ <a itemProp="url" href={product.url}>
+ <img itemProp="image" className="img-responsive" src={product.image_url} alt="" />
+ <span className="product-list-item-name" itemProp="name" title={product.name}>{product.name}</span>
+ </a>
+ </div>
+ <div className="panel-footer">
+ <span itemProp="price">
+ {product.price_value}
+ <span className="currency"> {product.price_currency}</span>
+ </span>
+ </div>
+ </div>
+ </div>
+ );
+ })}
+ </div>
+ )
+ }
+}
diff --git a/saleor/static/js/components/products.js b/saleor/static/js/components/products.js
deleted file mode 100644
index 4cb61e7883..0000000000
--- a/saleor/static/js/components/products.js
+++ /dev/null
@@ -1,59 +0,0 @@
-import React, { Component, findDOMNode, PropTypes } from 'react'
-import { connect } from 'react-redux'
-import $ from 'jquery'
-import axios from 'axios';
-
-export class ProductList extends Component {
-
- static propTypes = {
- className: PropTypes.string,
- color: PropTypes.string,
- };
-
- state = {
- data: [],
- };
-
- componentWillMount() {
- fetch("https://private-58ac5-saleor.apiary-mock.com/products/", {
- method: 'GET',
- }).then(res => {
- res.json().then((data) => {
- this.setState({
- data: data
- });
- });
- });
- }
-
- componentWillReceiveProps(nextProps) {
- let url = "https://private-58ac5-saleor.apiary-mock.com/products/" + nextProps.color
- fetch(url, {
- method: 'GET',
- }).then(res => {
- res.json().then((data) => {
- this.setState({
- data: data
- });
- });
- });
- }
-
- render() {
-
- const { data } = this.state;
- const { color } = this.props;
-
- return (
- <div>
- {data.map((product) => {
- return (
- <p key={product.id}>
- <a href={product.url}>{product.name} - {product.price_value} {product.price_currency} - {product.attributes[0].color}</a>
- </p>
- );
- })}
- </div>
- )
- }
-}
\ No newline at end of file
diff --git a/saleor/static/js/products_search.js b/saleor/static/js/products_search.js
deleted file mode 100644
index b62f3a3410..0000000000
--- a/saleor/static/js/products_search.js
+++ /dev/null
@@ -1,41 +0,0 @@
-import $ from 'jquery'
-import React from 'react'
-import ReactDOM from 'react-dom'
-
-import { ProductList } from './components/products'
-
-class ProductSearch {
-
- constructor() {
- this.props = {
- className: 'btn class',
- color: ''
- }
- this.renderProducts();
- }
-
- attachOnclickEvents() {
- $('.fetch_data').on( 'click', (e) => {
- this.props.color = $(e.target).data('color');
- this.renderProducts();
- });
- }
-
- renderProducts() {
- ReactDOM.render(
- <ProductList {...this.props}/>, document.getElementById('productList')
- );
- }
-
-}
-
-$(document).ready(() => {
- let products = new ProductSearch();
- products.attachOnclickEvents();
-});
-
-
-
-
-
-
diff --git a/templates/category/index.html b/templates/category/index.html
index dcaed1763f..159b7fd379 100644
--- a/templates/category/index.html
+++ b/templates/category/index.html
@@ -6,7 +6,7 @@
{% block footer_scripts %}
{{ block.super }}
- {% render_bundle 'products_search' 'js' %}
+ {% render_bundle 'category' 'js' %}
{% endblock footer_scripts %}
{% block title %}{{ category }} — {{ block.super }}{% endblock %}
@@ -25,13 +25,13 @@
{% endblock breadcrumb %}
{% block content %}
+ <div id="category-page"></div>
<div class="row">
<div class="col-md-3">
<ul class="list-group">
<li class="list-group-item active">
{{ category }}
</li>
-
{% for category in children_categories %}
<li class="list-group-item">
<a href="{{ category.get_absolute_url }}">
@@ -40,11 +40,6 @@
</li>
{% endfor %}
</ul>
- <button class="btn btn-danger fetch_data" data-color="red">Red</button>
- <button class="btn btn-success fetch_data" data-color="green">Green</button>
- <button class="btn btn-default fetch_data" data-color="">Cancel</button>
- <div id="productList"></div>
-
</div>
<div class="col-md-9">
diff --git a/webpack.config.js b/webpack.config.js
index 9fcaf55a29..841414fdd9 100644
--- a/webpack.config.js
+++ b/webpack.config.js
@@ -28,6 +28,7 @@ var providePlugin = new webpack.ProvidePlugin({
var config = {
entry: {
+ category: './saleor/static/js/category.js',
dashboard: './saleor/static/js/dashboard.js',
storefront: './saleor/static/js/storefront.js',
vendor: [