changed order
This commit is contained in:
@@ -2,31 +2,63 @@ import React from "react";
|
||||
import { Home, ShoppingBag, ShoppingCart, Heart, User } from "lucide-react";
|
||||
import { Link, useLocation } from "react-router-dom";
|
||||
import styles from "./FooterBar.module.scss";
|
||||
import { useGetCartQuery } from "../../app/api/cartApi"; // Sepet API
|
||||
import { useGetFavoritesQuery } from "../../app/api/favoritesApi"; // Favori API
|
||||
import { useGetCartQuery } from "../../app/api/cartApi";
|
||||
import { useGetFavoritesQuery } from "../../app/api/favoritesApi";
|
||||
import { useTranslation } from "react-i18next";
|
||||
|
||||
const FooterBar = () => {
|
||||
const location = useLocation();
|
||||
|
||||
const { t } = useTranslation();
|
||||
const { data: cartData } = useGetCartQuery();
|
||||
const { data: favoriteData } = useGetFavoritesQuery();
|
||||
const { data: cartData } = useGetCartQuery();
|
||||
const { data: favoriteData } = useGetFavoritesQuery();
|
||||
|
||||
|
||||
|
||||
const cartCount =
|
||||
cartData?.data?.reduce((total, item) => {
|
||||
return total + (parseInt(item.product_quantity, 10) || 0);
|
||||
}, 0) || 0;
|
||||
|
||||
// FIX: Object içindeki tüm channel'ların item'larını birleştir
|
||||
const getCartCount = () => {
|
||||
if (!cartData?.data || typeof cartData.data !== 'object') {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Object.values ile tüm channel array'lerini al
|
||||
const allCartItems = Object.values(cartData.data).flat();
|
||||
|
||||
return allCartItems.reduce((total, item) => {
|
||||
return total + (parseInt(item.product_quantity, 10) || 0);
|
||||
}, 0);
|
||||
};
|
||||
|
||||
const cartCount = getCartCount();
|
||||
const favoriteCount = favoriteData?.length || 0;
|
||||
|
||||
const navItems = [
|
||||
{ id: 1, icon: <Home />, label: t("navbar.home"), count: 0, path: "/" },
|
||||
{ id: 2, icon: <ShoppingBag />, label: t("navbar.brands"), count: 0, path: "/brands" },
|
||||
{ id: 3, icon: <ShoppingCart />, label: t("navbar.cart"), count: cartCount, path: "/cart" },
|
||||
{ id: 4, icon: <Heart />, label: t("wishtList.likedProducts"), count: favoriteCount, path: "/wishlist" },
|
||||
{ id: 5, icon: <User />, label: t("profile.profile"), count: 0, path: "/profile" },
|
||||
{
|
||||
id: 2,
|
||||
icon: <ShoppingBag />,
|
||||
label: t("navbar.brands"),
|
||||
count: 0,
|
||||
path: "/brands",
|
||||
},
|
||||
{
|
||||
id: 3,
|
||||
icon: <ShoppingCart />,
|
||||
label: t("navbar.cart"),
|
||||
count: cartCount,
|
||||
path: "/cart",
|
||||
},
|
||||
{
|
||||
id: 4,
|
||||
icon: <Heart />,
|
||||
label: t("wishtList.likedProducts"),
|
||||
count: favoriteCount,
|
||||
path: "/wishlist",
|
||||
},
|
||||
{
|
||||
id: 5,
|
||||
icon: <User />,
|
||||
label: t("profile.profile"),
|
||||
count: 0,
|
||||
path: "/profile",
|
||||
},
|
||||
];
|
||||
|
||||
return (
|
||||
@@ -37,11 +69,15 @@ const FooterBar = () => {
|
||||
<Link
|
||||
key={item.id}
|
||||
to={item.path}
|
||||
className={`${styles.navItem} ${location.pathname === item.path ? styles.active : ""}`}
|
||||
className={`${styles.navItem} ${
|
||||
location.pathname === item.path ? styles.active : ""
|
||||
}`}
|
||||
>
|
||||
<div className={styles.iconWrapper}>
|
||||
<div className={styles.icon}>{item.icon}</div>
|
||||
{item.count > 0 && <div className={styles.badge}>{item.count}</div>}
|
||||
{item.count > 0 && (
|
||||
<div className={styles.badge}>{item.count}</div>
|
||||
)}
|
||||
</div>
|
||||
<span className={styles.label}>{item.label}</span>
|
||||
</Link>
|
||||
@@ -52,4 +88,4 @@ const FooterBar = () => {
|
||||
);
|
||||
};
|
||||
|
||||
export default FooterBar;
|
||||
export default FooterBar;
|
||||
Reference in New Issue
Block a user