diff --git a/src/PozoApp/Components/Footer.jsx b/src/PozoApp/Components/Footer.jsx index 89d3e27..79ef874 100644 --- a/src/PozoApp/Components/Footer.jsx +++ b/src/PozoApp/Components/Footer.jsx @@ -10,6 +10,7 @@ import { useDispatch } from "react-redux"; import { gsap } from "gsap"; import { ScrollTrigger } from "gsap/ScrollTrigger"; import { useNavigate } from "react-router-dom"; +import { sessionStore } from "../../Services/others"; gsap.registerPlugin(ScrollTrigger); const subDirectory = import.meta.env.ENV_BASE_URL @@ -17,58 +18,108 @@ const Footer = () => { const navigate = useNavigate(); const logoRef = useRef(null); const productsRef = useRef(null); + const footerRef = useRef(null); const dispatch = useDispatch(); const [email, setEmail] = useState(""); const [isLoading, setIsLoading] = useState(false); const [message, setMessage] = useState(""); const [messageType, setMessageType] = useState(""); + const [appList, setAppList] = useState([]); + const [isFooterVisible, setIsFooterVisible] = useState(false); const scrollToTop = () => { window.scrollTo({ top: 0, behavior: "smooth" }); }; useEffect(() => { - fetchApplicationData(); + // Intersection Observer for lazy loading + const observer = new IntersectionObserver( + (entries) => { + entries.forEach((entry) => { + console.log("👁️ Footer visibility:", entry.isIntersecting); + if (entry.isIntersecting && !isFooterVisible) { + console.log("🎯 Footer is visible! Loading apps..."); + setIsFooterVisible(true); + fetchApplicationData(); + } + }); + }, + { threshold: 0.1 } + ); + + if (footerRef.current) { + console.log("✅ Observer attached to footer"); + observer.observe(footerRef.current); + } else { + console.log("❌ footerRef is null"); + } // Logo animation - gsap.fromTo( - logoRef.current, - { opacity: 0, scale: 0.8, rotation: -10 }, - { - opacity: 1, - scale: 1, - rotation: 0, - duration: 1.2, - ease: "back.out(1.7)", - scrollTrigger: { - trigger: logoRef.current, - start: "top 85%", - toggleActions: "play none none reverse", + if (logoRef.current) { + gsap.fromTo( + logoRef.current, + { opacity: 0, scale: 0.8, rotation: -10 }, + { + opacity: 1, + scale: 1, + rotation: 0, + duration: 1.2, + ease: "back.out(1.7)", + scrollTrigger: { + trigger: logoRef.current, + start: "top 85%", + toggleActions: "play none none reverse", + }, }, - }, - ); + ); + } // Products section animation - gsap.fromTo( - productsRef.current, - { opacity: 0, y: 50 }, - { - opacity: 1, - y: 0, - duration: 1, - ease: "power2.out", - scrollTrigger: { - trigger: productsRef.current, - start: "top 85%", - toggleActions: "play none none reverse", + if (productsRef.current) { + gsap.fromTo( + productsRef.current, + { opacity: 0, y: 50 }, + { + opacity: 1, + y: 0, + duration: 1, + ease: "power2.out", + scrollTrigger: { + trigger: productsRef.current, + start: "top 85%", + toggleActions: "play none none reverse", + }, }, - }, - ); + ); + } + + return () => { + if (footerRef.current) { + observer.unobserve(footerRef.current); + } + }; }, []); const fetchApplicationData = async () => { - const res = await dispatch(getApplicationData())?.unwrap(); - console.log(res?.data?.data); + try { + console.log("🔥 Footer: Fetching apps data..."); + const res = await dispatch(getApplicationData())?.unwrap(); + console.log("📦 Footer API Response:", res?.data); + if (res?.data?.statusCode === 1) { + const activeApps = res?.data?.data?.filter(app => app.ActiveStatus === "A") || []; + console.log("✅ Footer Active Apps:", activeApps.length, activeApps); + setAppList(activeApps); + } + } catch (error) { + console.error("❌ Error fetching apps:", error); + } + }; + + const redirectApp = (appName, appId) => { + sessionStore("AppId", appId); + sessionStore("AppName", appName); + navigate(`${subDirectory}${appName}`); + window.scrollTo(0, 0); }; const handleSubscribe = async () => { @@ -115,7 +166,7 @@ const Footer = () => { return ( <> -
Restaurant
-Bakery
-Dairy Delights
-Electrical, Electronics and Computers
-Mobile & Accessories
-Groceries
-Cement
-Lifestyle and Fashion
-Fashion Jewellery
-Footwear
-Salon, Spa and Beauty Parlour
-Beauty and Cosmetics shop
-Fitness
-Departmental Stores
-Wholesale
-Manufacturer
-Save Me
-Smart Parking
-Boating
+ {(() => { + console.log("🔍 Rendering Footer Products:"); + console.log(" - isFooterVisible:", isFooterVisible); + console.log(" - appList.length:", appList.length); + console.log(" - Showing:", isFooterVisible && appList.length > 0 ? "Dynamic" : "Static"); + return null; + })()} + {isFooterVisible && appList.length > 0 ? ( + appList.slice(0, 15).map((app) => ( +redirectApp(app.AppName?.toLowerCase(), app.AppId)} + style={{ cursor: 'pointer' }} + > + {app.AppName} +
+ )) + ) : ( + <> +Restaurant
+Bakery
+Dairy Delights
+Electrical, Electronics and Computers
+Mobile & Accessories
+Groceries
+Cement
+Lifestyle and Fashion
+Fashion Jewellery
+Footwear
+Salon, Spa and Beauty Parlour
+Beauty and Cosmetics shop
+Fitness
+Departmental Stores
+Wholesale
+ > + )}- redirectApp(app.AppName?.toLowerCase(), app.AppId) - } - > - {app.AppName} -
- //- // redirectApp(app.AppName?.toLowerCase(), app.AppId) - // } - // > - // {app.AppName} - //
- ))} + + {/* Food & Beverages */} + {categorized.foodBeverages.length > 0 && ( + <> +redirectApp(app.AppName?.toLowerCase(), app.AppId)} + > + {app.AppName} +
+ ))} + > + )} + + {/* Wellness */} + {categorized.wellness.length > 0 && ( + <> +redirectApp(app.AppName?.toLowerCase(), app.AppId)} + > + {app.AppName} +
+ ))} + > + )} + + {/* Fashion */} + {categorized.fashion.length > 0 && ( + <> +redirectApp(app.AppName?.toLowerCase(), app.AppId)} + > + {app.AppName} +
+ ))} + > + )} + + {/* Electronics */} + {categorized.electronics.length > 0 && ( + <> +redirectApp(app.AppName?.toLowerCase(), app.AppId)} + > + {app.AppName} +
+ ))} + > + )} + + {/* Grocery */} + {categorized.grocery.length > 0 && ( + <> +redirectApp(app.AppName?.toLowerCase(), app.AppId)} + > + {app.AppName} +
+ ))} + > + )} + + {/* Services */} + {categorized.services.length > 0 && ( + <> +redirectApp(app.AppName?.toLowerCase(), app.AppId)} + > + {app.AppName} +
+ ))} + > + )} + + {/* Others */} + {categorized.others.length > 0 && ( + <> +redirectApp(app.AppName?.toLowerCase(), app.AppId)} + > + {app.AppName} +
+ ))} + > + )}- redirectApp(app.AppName?.toLowerCase(), app.AppId) - } - > - {app.AppName} -
- ))} + (/(healthcare|pharma)/i.test(app.CategoryName) || /(health|optical)/i.test(app.AppName)) + ).length > 0 && ( + <> +redirectApp(app.AppName?.toLowerCase(), app.AppId)} + > + {app.AppName} +
+ ))} + > + )} + + {/* Manufacturing */} + {AppCategory?.filter((app) => + (/(manufacturing)/i.test(app.CategoryName) || /(manufacturer)/i.test(app.AppName)) + ).length > 0 && ( + <> +redirectApp(app.AppName?.toLowerCase(), app.AppId)} + > + {app.AppName} +
+ ))} + > + )}redirectApp(app.AppName?.toLowerCase(), app.AppId)} - > - {app.AppName} -
- ))} + (/(transportation|logistics)/i.test(app.CategoryName) || /(parking|boating)/i.test(app.AppName)) + ).length > 0 && ( + <> +redirectApp(app.AppName?.toLowerCase(), app.AppId)} + > + {app.AppName} +
+ ))} + > + )} + + {/* Hospitality */} + {AppCategory?.filter((app) => + (/(hospitality|entertainment)/i.test(app.CategoryName) || /(hotel|resort)/i.test(app.AppName)) + ).length > 0 && ( + <> +redirectApp(app.AppName?.toLowerCase(), app.AppId)} + > + {app.AppName} +
+ ))} + > + )}Restaurant
- //Bakery
- //Dairy Delights
- //Lifestyle and Fashion
- //Fashion Jewellery
- //Footwear
- //Electrical, Electronics and Computers
- //Mobile & Accessories
- //Groceries
- //Departmental Stores
- //Salon, Spa and Beauty Parlour
- //Beauty and Cosmetics shop
- //Fitness
- //Cement
- //Wholesale NEW
- //Manufacturer
- //Save Me BETA
- //Smart Parking
- //Boating
- //