|
@@ -6,11 +6,19 @@ import { bindActionCreators } from 'redux';
|
|
import actionCatalogCard from './../reducers/reducerCat';
|
|
import actionCatalogCard from './../reducers/reducerCat';
|
|
|
|
|
|
|
|
|
|
|
|
+const CatalogSubLink = ({name, arr}) => {
|
|
|
|
+ const [show, changeValue] = useState(false);
|
|
|
|
+ return(
|
|
|
|
+ <li><span onClick = {() =>changeValue(!show)}>{name} </span>{<ul className="subCatalog">{ show && arr.map(key =>
|
|
|
|
+ <Links className = {"subLink"} key={key._id} url={`/catalog/` + key._id} text={key.name}> </Links>)}</ul>}</li>
|
|
|
|
+
|
|
|
|
+ )
|
|
|
|
+}
|
|
|
|
|
|
|
|
|
|
const Catalog = ({ state, categories = [], getData = () => console.log("no") }) => {
|
|
const Catalog = ({ state, categories = [], getData = () => console.log("no") }) => {
|
|
useEffect(() => categories.length == 0 && getData(), []);
|
|
useEffect(() => categories.length == 0 && getData(), []);
|
|
- //const [show, changeValue] = useState(false);
|
|
|
|
|
|
+
|
|
|
|
|
|
return (
|
|
return (
|
|
<>
|
|
<>
|
|
@@ -19,8 +27,10 @@ const Catalog = ({ state, categories = [], getData = () => console.log("no") })
|
|
category.subCategories == null ?
|
|
category.subCategories == null ?
|
|
<Links key={category._id} url={`/catalog/` + category._id} text={category.name}> </Links> :
|
|
<Links key={category._id} url={`/catalog/` + category._id} text={category.name}> </Links> :
|
|
|
|
|
|
- <li>{category.name} {<ul className="catalog">{category.subCategories.map(subCategory =>
|
|
|
|
- <Links key={subCategory._id} url={`/catalog/` + subCategory._id} text={subCategory.name}> </Links>)}</ul>}</li>
|
|
|
|
|
|
+ <CatalogSubLink name = {category.name} arr = {category.subCategories}/>
|
|
|
|
+
|
|
|
|
+ // <li onClick = {() =>changeValue(!show)}>{category.name} { show && <ul className="catalog">{category.subCategories.map(subCategory =>
|
|
|
|
+ // <Links key={subCategory._id} url={`/catalog/` + subCategory._id} text={subCategory.name}> </Links>)}</ul>}</li>
|
|
|
|
|
|
)}
|
|
)}
|
|
</ul>
|
|
</ul>
|
|
@@ -29,7 +39,7 @@ const Catalog = ({ state, categories = [], getData = () => console.log("no") })
|
|
}
|
|
}
|
|
|
|
|
|
const getCategories = state => {
|
|
const getCategories = state => {
|
|
- console.log("state", state)
|
|
|
|
|
|
+ // console.log("state", state)
|
|
if (state.promiseRed.categories && state.promiseRed.categories.payload) {
|
|
if (state.promiseRed.categories && state.promiseRed.categories.payload) {
|
|
return state.promiseRed.categories.payload.data.CategoryFind
|
|
return state.promiseRed.categories.payload.data.CategoryFind
|
|
}
|
|
}
|