From 2945ca8b70755db6ee86c3997d74d8f46cf1c89a Mon Sep 17 00:00:00 2001 From: egradanin Date: Wed, 16 Jan 2019 21:00:14 +0100 Subject: [PATCH] deep subcategory solution --- frontend-react/src/components/App.js | 9 +++-- .../src/components/categories/Nekretnine.js | 38 +++++------------- .../src/components/categories/Vozila.js | 39 ++++++------------- .../components/widgets/DeepCategoryWrapper.js | 30 ++++++++++++++ frontend-react/src/reducers/subcategory.js | 18 ++++----- frontend-react/src/utils/createOlxLink.js | 12 ++++-- frontend-react/src/utils/helpers.js | 2 +- 7 files changed, 75 insertions(+), 73 deletions(-) create mode 100644 frontend-react/src/components/widgets/DeepCategoryWrapper.js diff --git a/frontend-react/src/components/App.js b/frontend-react/src/components/App.js index bf43794..1a85898 100644 --- a/frontend-react/src/components/App.js +++ b/frontend-react/src/components/App.js @@ -6,8 +6,9 @@ import { hoc, areObjectEqual } from "utils/helpers"; import { createOlxLink } from "utils/createOlxLink"; import axios from "axios"; -import Vozila from "./categories/Vozila"; -import Nekretnine from "./categories/Nekretnine"; +import * as Vozila from "./categories/Vozila"; +import * as Nekretnine from "./categories/Nekretnine"; +import DeepCategoryWrapper from "components/widgets/DeepCategoryWrapper"; import ItemsContainer from "./items/itemscontainer/ItemsContainer"; const options = [ @@ -77,8 +78,8 @@ class App extends React.Component { options={options} /> {hoc(category && category.value, { - Vozila: , - Nekretnine: + Vozila: , + Nekretnine: })} diff --git a/frontend-react/src/components/categories/Nekretnine.js b/frontend-react/src/components/categories/Nekretnine.js index 41721e4..2c4434c 100644 --- a/frontend-react/src/components/categories/Nekretnine.js +++ b/frontend-react/src/components/categories/Nekretnine.js @@ -1,35 +1,17 @@ import React from "react"; -import Select from "react-select"; -import { subcategorywrapper } from "utils/subcategorywrapper"; -import { hoc } from "utils/helpers"; import Stanovi from "../subcategories/nekretnine/Stanovi"; import Kuce from "../subcategories/nekretnine/Kuce"; const options = [{ value: 23, label: "Stanovi" }, { value: 24, label: "Kuce" }]; +const depth = 0; +const childrenComponents = { + 23: , + 24: +}; -class Nekretnine extends React.Component { - handleChange = selectedOption => { - this.props.onSubCategoryChanged(selectedOption); - }; - - render() { - const { subcategory } = this.props; - - return ( -
- - {hoc(subcategory && subcategory.value, { - 18: , - 21: - })} -
- ); - } -} - -export default subcategorywrapper(Vozila); +export const properties = { + options, + depth, + childrenComponents +}; diff --git a/frontend-react/src/components/widgets/DeepCategoryWrapper.js b/frontend-react/src/components/widgets/DeepCategoryWrapper.js new file mode 100644 index 0000000..d0ea539 --- /dev/null +++ b/frontend-react/src/components/widgets/DeepCategoryWrapper.js @@ -0,0 +1,30 @@ +import React from "react"; +import Select from "react-select"; +import { subcategorywrapper } from "utils/subcategorywrapper"; +import { hoc } from "utils/helpers"; + +class DeepCategoryWrapper extends React.Component { + handleOptionChange = selectedOption => { + const { depth, onSubCategoryChanged } = this.props; + onSubCategoryChanged({ selectedOption, depth }); + }; + + render() { + const { options, depth, childrenComponents } = this.props; + const { + subcategory: { [depth]: deepSubCategory } + } = this.props; + + return ( +
+