diff --git a/src/App.js b/src/App.js
index b681309..8bc9b9c 100644
--- a/src/App.js
+++ b/src/App.js
@@ -27,6 +27,7 @@ import { db } from './firebase';
import SellerForm from './pages/SellerRegistration';
import GoToTop from './components/GoToTop/GoToTop';
import { Account } from './components/AccountDetails/Account';
+import Compare from './pages/Compare';
const MyContext = createContext();
@@ -49,10 +50,12 @@ function App() {
const [data, setData] = useState([]);
const [cartCount, setCartCount] = useState(0);
const [wishlistCount, setWishlistCount] = useState(0);
+ const [compareCount, setCompareCount] = useState(0);
useEffect(() => {
fetchCartProducts();
fetchWishlistProducts();
+ fetchCompareProducts();
}, [isLogin]);
const fetchCartProducts = async () => {
@@ -111,12 +114,26 @@ function App() {
const is_Login = localStorage.getItem('isLogin');
setIsLogin(is_Login);
-
+
setTimeout(() => {
setProductData(data[1]);
setIsloading(false);
}, 3000);
}, [isLogin]);
+ const fetchCompareProducts = async () => {
+ try {
+ const compareRef = doc(db, 'compare', uid);
+ const productsCollectionRef = collection(compareRef, 'products');
+ const querySnapshot = await getDocs(productsCollectionRef);
+ let products = [];
+ querySnapshot.forEach((doc) => {
+ products.push({ id: doc.id, ...doc.data() });
+ });
+ setCompareCount(products.length);
+ } catch (error) {
+ console.error('Error fetching compare products:', error);
+ }
+ };
const getData = async (url) => {
try {
@@ -222,7 +239,10 @@ function App() {
wishlistCount,
setWishlistCount,
fetchCartProducts,
- fetchWishlistProducts
+ fetchWishlistProducts,
+ fetchCompareProducts,
+ compareCount,
+ setCompareCount
};
return data && data.productData ? (
@@ -260,6 +280,7 @@ function App() {
/>
} />
} />
+ } />
} />
{/* sign in , signup Protection */}
diff --git a/src/components/header/header.js b/src/components/header/header.js
index 167032f..3754938 100644
--- a/src/components/header/header.js
+++ b/src/components/header/header.js
@@ -40,7 +40,7 @@ const Header = (props) => {
const [isOpenNav, setIsOpenNav] = useState(false);
const { cartCount, setCartCount } = useContext(MyContext);
const { wishlistCount, setWishlistCount } = useContext(MyContext);
-
+ const { compareCount } = useContext(MyContext)
const headerRef = useRef();
const searchInput = useRef();
const [profile, setProfile] = useState('');
@@ -254,13 +254,13 @@ const Header = (props) => {
{' '}
- 3
+ {compareCount}
Compare
@@ -395,7 +395,7 @@ const Header = (props) => {
-
+ toggleCompareItem(currentProduct)} className={`btn-lg addtocartbtn ml-3 ${
+ isAlreadyAddedInCompare === true
+ ? 'btn-borderWishlistAlreadyAdded'
+ : 'btn-border'
+ }`}>