Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Add React to category page
Krzysztof Białogłowicz32500caa36ee
diff --git a/saleor/static/js/components/products.js b/saleor/static/js/components/products.jsnew file mode 100644index 0000000000..4cb61e7883--- /dev/null+++ b/saleor/static/js/components/products.js@@ -0,0 +1,59 @@+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 filediff --git a/saleor/static/js/products_search.js b/saleor/static/js/products_search.jsnew file mode 100644index 0000000000..b62f3a3410--- /dev/null+++ b/saleor/static/js/products_search.js@@ -0,0 +1,41 @@+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.htmlindex df3c5d370c..dcaed1763f 100644--- a/templates/category/index.html+++ b/templates/category/index.html@@ -2,6 +2,12 @@{% load slice from shop %}{% load static from staticfiles %}{% load bootstrap_pagination from bootstrap3 %}+{% load render_bundle from webpack_loader %}++{% block footer_scripts %}+ {{ block.super }}+ {% render_bundle 'products_search' 'js' %}+{% endblock footer_scripts %}{% block title %}{{ category }} — {{ block.super }}{% endblock %}@@ -34,6 +40,11 @@</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">