diff --git a/src/app/api/useCart.js b/src/app/api/useCart.js new file mode 100644 index 0000000..a7001c8 --- /dev/null +++ b/src/app/api/useCart.js @@ -0,0 +1,37 @@ +// hooks/useCart.js - YENİ DOSYA +import { useMemo } from 'react'; +import { useGetCartQuery } from './cartApi'; + +export const useCart = () => { + const { data: cartData, ...rest } = useGetCartQuery(undefined, { + pollingInterval: 0, + refetchOnMountOrArgChange: false, + refetchOnFocus: false, + refetchOnReconnect: false, + }); + + const cartItems = useMemo(() => { + if (!cartData?.data || typeof cartData.data !== 'object') return []; + return Object.values(cartData.data).flat(); + }, [cartData]); + + const cartCount = useMemo(() => { + return cartItems.reduce((total, item) => { + return total + (parseInt(item.product_quantity, 10) || 0); + }, 0); + }, [cartItems]); + + const getCartItem = (productId) => { + return cartItems.find( + item => item.product?.id === productId || item.product_id === productId + ); + }; + + return { + cartData, + cartItems, + cartCount, + getCartItem, + ...rest + }; +}; \ No newline at end of file diff --git a/src/pages/Cart/CartPage.module.scss b/src/pages/Cart/CartPage.module.scss index 7ff9509..718e103 100644 --- a/src/pages/Cart/CartPage.module.scss +++ b/src/pages/Cart/CartPage.module.scss @@ -52,8 +52,10 @@ display: flex; border-radius: 10px; gap: 16px; + justify-content: space-between; + width: 100%; - @media screen and (max-width: 768px) { + @media screen and (max-width: 1023px) { flex-direction: column; } } @@ -118,11 +120,17 @@ flex-direction: column; position: relative; } + h1{ + font-size: 1.2rem; + @media screen and (max-width: 720px) { + font-size: 16px; + } + } h3 { font-size: 1.2rem; margin-bottom: 0.5rem; @media screen and (max-width: 720px) { - font-size: 18px; + font-size: 14px; } } diff --git a/src/pages/Cart/index.jsx b/src/pages/Cart/index.jsx index 4b60e8a..cad86e9 100644 --- a/src/pages/Cart/index.jsx +++ b/src/pages/Cart/index.jsx @@ -323,9 +323,9 @@ const CartPage = () => { const handleEmptyCartConfirm = async () => { try { await cleanCart().unwrap(); - // ✅ RTK Query otomatik cache'i güncelleyecek - // ✅ Local state'i temizle + + setLocalQuantities({}); setPendingQuantities({}); setCheckoutStores({}); @@ -409,7 +409,7 @@ const CartPage = () => { }} /> ) : ( -