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, {
- 23: ,
- 24:
- })}
-
- );
- }
-}
-
-export default subcategorywrapper(Nekretnine);
+export const properties = {
+ options,
+ depth,
+ childrenComponents
+};
diff --git a/frontend-react/src/components/categories/Vozila.js b/frontend-react/src/components/categories/Vozila.js
index 5302c7b..60a1c12 100644
--- a/frontend-react/src/components/categories/Vozila.js
+++ b/frontend-react/src/components/categories/Vozila.js
@@ -1,37 +1,20 @@
import React from "react";
-import Select from "react-select";
+
import Automobili from "../subcategories/vozila/Automobili";
import Motocikli from "../subcategories/vozila/Motocikli";
-import { subcategorywrapper } from "utils/subcategorywrapper";
-import { hoc } from "utils/helpers";
const options = [
{ value: 18, label: "Automobili" },
{ value: 21, label: "Motocikli" }
];
+const depth = 0;
+const childrenComponents = {
+ 18: ,
+ 21:
+};
-class Vozila 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 (
+
+
+ {hoc(deepSubCategory && deepSubCategory.value, childrenComponents)}
+
+ );
+ }
+}
+export default subcategorywrapper(DeepCategoryWrapper);
diff --git a/frontend-react/src/reducers/subcategory.js b/frontend-react/src/reducers/subcategory.js
index eafd0f1..2474350 100644
--- a/frontend-react/src/reducers/subcategory.js
+++ b/frontend-react/src/reducers/subcategory.js
@@ -1,12 +1,12 @@
import { SUBCATEGORY_SELECT, CATEGORY_SELECT } from "constants/actionTypes";
-export default (state = null, action) => {
- switch (action.type) {
- case SUBCATEGORY_SELECT:
- return action.option;
- case CATEGORY_SELECT:
- return null;
- default:
- return state;
- }
+export default (state = {}, action) => {
+ switch (action.type) {
+ case SUBCATEGORY_SELECT:
+ return { ...state, [action.option.depth]: action.option.selectedOption };
+ case CATEGORY_SELECT:
+ return {};
+ default:
+ return state;
+ }
};
diff --git a/frontend-react/src/utils/createOlxLink.js b/frontend-react/src/utils/createOlxLink.js
index 3c284da..355c9d7 100644
--- a/frontend-react/src/utils/createOlxLink.js
+++ b/frontend-react/src/utils/createOlxLink.js
@@ -6,10 +6,16 @@ const mapOptionToLink = (options, option) =>
}&`
: "";
-export const createOlxLink = (category, subcategory, options) =>
- subcategory.value
+export const createOlxLink = (category, subcategory, options) => {
+ const deepSubCategory =
+ Boolean(Object.keys(subcategory).length) &&
+ subcategory[
+ Object.keys(subcategory).reduce((max, key) => (max < key ? key : max))
+ ];
+ return deepSubCategory
? Object.keys(options).reduce(
(link, option) => link + mapOptionToLink(options, option),
- `kategorija=${subcategory.value}&`
+ `kategorija=${deepSubCategory.value}&`
)
: "";
+};
diff --git a/frontend-react/src/utils/helpers.js b/frontend-react/src/utils/helpers.js
index d1e7e61..7e993a7 100644
--- a/frontend-react/src/utils/helpers.js
+++ b/frontend-react/src/utils/helpers.js
@@ -1,4 +1,4 @@
-export const hoc = (option, componentList) => componentList[option] || null;
+export const hoc = (option, componentList) => componentList[option];
export const areObjectEqual = function checkEquality(objectA, objectB) {
return (
Object.keys(objectA).length === Object.keys(objectB).length &&