import { AnimatePresence, motion } from "framer-motion";
import { useEffect, useState } from "react";
import { MenuList } from "@features/sidebar";
import { MakeOrderButton, PersonalAccount } from "@entities/sidebar";
import { LogotypeIcon } from "@shared/images";
import { useScreenResolution } from "@shared/libs/global";
import { BurgerIcon, HorizontalLine } from "@shared/ui";
import classes from "./Sidebar.module.scss";
const initialSidebarAnimate = {
x: -100,
opacity: 0,
};
const animateSidebarAnimate = {
x: 0,
opacity: 1,
};
const exitSidebarAnimate = {
x: -100,
opacity: 0,
};
const transitionSidebarAnimate = {
x: -100,
opacity: 0,
};
export const Sidebar = () => {
const [active, setActive] = useState<boolean>(false);
const [isMobile, setIsMobile] = useState(false);
const mobile = useScreenResolution();
const handlerBurgerMenu = () => setActive((state) => !state);
useEffect(() => {
setIsMobile(mobile);
}, [mobile]);
return (
<>
<BurgerIcon onClick={handlerBurgerMenu} active={active} />
<AnimatePresence>
{(!isMobile || (isMobile && active)) && (
<motion.header
transition={transitionSidebarAnimate}
initial={initialSidebarAnimate}
animate={animateSidebarAnimate}
exit={exitSidebarAnimate}
className={classes.headerSidebar}
>
<LogotypeIcon className={classes.logotypeSidebar} />
<MakeOrderButton className={classes.orderButton} />
<HorizontalLine />
<MenuList className={classes.menuList} />
<HorizontalLine />
<PersonalAccount className={classes.personalAccount} />
</motion.header>
)}
</AnimatePresence>
</>
);
};
import { AnimatePresence, motion } from "framer-motion";
import { useState } from "react";
import { MenuList } from "@features/sidebar";
import { MakeOrderButton, PersonalAccount } from "@entities/sidebar";
import { LogotypeIcon } from "@shared/images";
import { useScreenResolution } from "@shared/libs/global";
import { BurgerIcon, HorizontalLine } from "@shared/ui";
import classes from "./Sidebar.module.scss";
const initialSidebarAnimate = {
x: -100,
opacity: 0,
};
const animateSidebarAnimate = {
x: 0,
opacity: 1,
};
const exitSidebarAnimate = {
x: -100,
opacity: 0,
};
const transitionSidebarAnimate = {
x: -100,
opacity: 0,
};
export const Sidebar = () => {
const [active, setActive] = useState<boolean>(false);
const handlerBurgerMenu = () => setActive((state) => !state);
const mobile = useScreenResolution();
return (
<>
<BurgerIcon onClick={handlerBurgerMenu} active={active} />
<AnimatePresence>
{(!mobile || (mobile && active)) && (
<motion.header
transition={transitionSidebarAnimate}
initial={initialSidebarAnimate}
animate={animateSidebarAnimate}
exit={exitSidebarAnimate}
className={classes.headerSidebar}
>
<LogotypeIcon className={classes.logotypeSidebar} />
<MakeOrderButton className={classes.orderButton} />
<HorizontalLine />
<MenuList className={classes.menuList} />
<HorizontalLine />
<PersonalAccount className={classes.personalAccount} />
</motion.header>
)}
</AnimatePresence>
</>
);
};
import { AxiosResponse } from "axios";
import { GetServerSideProps, GetServerSidePropsContext, NextPage } from "next";
import { TracksList } from "@widgets/clips";
import { Title } from "@widgets/clips";
import { Pagination } from "@widgets/custom-pagination";
import { SidebarContainer } from "@widgets/sidebar";
import type { IFilterProps } from "@features/filter";
import { LIMIT } from "@/shared/libs/global";
import { AxiosInstance } from "@shared/api";
import { IResponseTracks } from "@shared/types";
interface IStaticProps extends IFilterProps {
tracks: IResponseTracks[];
totalTracks: number;
}
const Main: NextPage<IStaticProps> = ({
tracks,
totalTracks,
filter_type,
filter_category,
}) => (
<SidebarContainer>
<Title filter_category={filter_category} filter_type={filter_type} />
<TracksList tracks={tracks} />
<Pagination total={totalTracks} />
</SidebarContainer>
);
export default Main;
export const getServerSideProps: GetServerSideProps<IStaticProps> = async ({
query,
}: GetServerSidePropsContext) => {
try {
const { page, category, type } = query;
const type_filter = typeof type === "string" && `&type.name=${type}`;
const category_filter = typeof category === "string" && `&q=${category}`;
const response: AxiosResponse<IResponseTracks[]> = await AxiosInstance.get(
`tracks?_page=${page || 1}&_limit=${
LIMIT + (type_filter || "" + (category_filter || ""))
}`,
);
const totalTracks: number = parseInt(response.headers["x-total-count"]);
return {
props: {
tracks: response.data,
...(typeof type === "string" ? { filter_type: type } : {}),
...(typeof category === "string" ? { filter_category: category } : {}),
totalTracks,
},
};
} catch (e) {
return {
notFound: true,
};
}
};
Вот как в целом выглядит этот хук откуда я пытаюсь получить данные и фнукци