sub nav
This commit is contained in:
parent
ac3baf77a1
commit
54c26806b3
|
|
@ -1,30 +1,30 @@
|
||||||
// Modules
|
// Modules
|
||||||
import { useLocation } from "react-router-dom";
|
import { useLocation } from 'react-router-dom';
|
||||||
import { v4 as uuidv4 } from "uuid";
|
import { v4 as uuidv4 } from 'uuid';
|
||||||
import { useDispatch, useSelector } from "react-redux";
|
import { useDispatch, useSelector } from 'react-redux';
|
||||||
import { useEffect, useState } from "react";
|
import { useEffect, useState } from 'react';
|
||||||
|
|
||||||
// Types
|
// Types
|
||||||
import { RootState } from "../../types/store.types";
|
import { RootState } from '../../types/store.types';
|
||||||
import { ICategoriesData } from "../../types/data.types";
|
import { ICategoriesData } from '../../types/data.types';
|
||||||
|
|
||||||
// Actions
|
// Actions
|
||||||
import { setActiveLink } from "../../actions/setActiveLink.action";
|
import { setActiveLink } from '../../actions/setActiveLink.action';
|
||||||
|
|
||||||
// Api
|
// Api
|
||||||
import { Api } from "../../api/Api";
|
import { Api } from '../../api/Api';
|
||||||
import { url } from "../../url";
|
import { url } from '../../url';
|
||||||
|
|
||||||
// Components
|
// Components
|
||||||
import Loader from "../global/Loader";
|
import Loader from '../global/Loader';
|
||||||
import SubNavLi from "./SubNavLi";
|
import SubNavLi from './SubNavLi';
|
||||||
|
|
||||||
const SubNav = () => {
|
const SubNav = () => {
|
||||||
const activeLink = useSelector<RootState, RootState["activeLink"]["active"]>(
|
const activeLink = useSelector<RootState, RootState['activeLink']['active']>(
|
||||||
(state) => state.activeLink.active
|
(state) => state.activeLink.active,
|
||||||
);
|
);
|
||||||
const language = useSelector<RootState, RootState["language"]["title"]>(
|
const language = useSelector<RootState, RootState['language']['title']>(
|
||||||
(state) => state.language.title
|
(state) => state.language.title,
|
||||||
);
|
);
|
||||||
|
|
||||||
const dispatch = useDispatch();
|
const dispatch = useDispatch();
|
||||||
|
|
@ -36,7 +36,7 @@ const SubNav = () => {
|
||||||
const [data, setData] = useState<ICategoriesData>();
|
const [data, setData] = useState<ICategoriesData>();
|
||||||
|
|
||||||
// Api
|
// Api
|
||||||
const api = new Api(url + "/categories");
|
const api = new Api(url + '/categories');
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
api.get(data, setData);
|
api.get(data, setData);
|
||||||
|
|
@ -44,7 +44,7 @@ const SubNav = () => {
|
||||||
|
|
||||||
const location = useLocation();
|
const location = useLocation();
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!location.pathname.includes("category")) return;
|
if (!location.pathname.includes('category')) return;
|
||||||
const category = location.pathname[location.pathname.length - 1];
|
const category = location.pathname[location.pathname.length - 1];
|
||||||
onClickLink(parseInt(category));
|
onClickLink(parseInt(category));
|
||||||
}, [location]);
|
}, [location]);
|
||||||
|
|
@ -57,7 +57,7 @@ const SubNav = () => {
|
||||||
<>
|
<>
|
||||||
<SubNavLi
|
<SubNavLi
|
||||||
isNotCategory
|
isNotCategory
|
||||||
dataEl={{ id: 0, name: "Главная" }}
|
dataEl={{ id: 0, name: 'Главная' }}
|
||||||
activeLink={activeLink}
|
activeLink={activeLink}
|
||||||
onClickLink={onClickLink}
|
onClickLink={onClickLink}
|
||||||
/>
|
/>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue