From caae728962298ae042b20a94436c1377d4387526 Mon Sep 17 00:00:00 2001 From: Badsha1996 Date: Thu, 16 Oct 2025 23:44:22 +0530 Subject: [PATCH] mobile fixes --- .../src/components/pages/HomePage.tsx | 192 ++++--- .../frontend/src/layouts/BackgroundLayout.tsx | 485 +++++++----------- 2 files changed, 292 insertions(+), 385 deletions(-) diff --git a/apps/frontend/src/components/pages/HomePage.tsx b/apps/frontend/src/components/pages/HomePage.tsx index e86a71c..a06ff78 100644 --- a/apps/frontend/src/components/pages/HomePage.tsx +++ b/apps/frontend/src/components/pages/HomePage.tsx @@ -86,6 +86,7 @@ const features = [ "Study Material Creation", "Progress Tracking", ]; + const avatarPool = [ "https://api.dicebear.com/6.x/adventurer/svg?seed=anime1", "https://api.dicebear.com/6.x/adventurer/svg?seed=anime2", @@ -121,16 +122,8 @@ function HomePage() { useEffect(() => { const checkDevice = () => { const width = window.innerWidth; - const isMobileDevice = width < 768; - - // Check for low-end devices - const isLowEndDevice = - (navigator.hardwareConcurrency && navigator.hardwareConcurrency <= 4) || - /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test( - navigator.userAgent - ); - - setIsMobile(isMobileDevice || isLowEndDevice); + const isMobileDevice = width < 1024; // Changed from 768 to 1024 + setIsMobile(isMobileDevice); }; checkDevice(); @@ -178,14 +171,16 @@ function HomePage() { })); }, [realTestimonials]); - // Handle WebGL context loss useEffect(() => { + if (isMobile) { + return; + } + const handleContextLost = (event: Event) => { event.preventDefault(); console.warn("WebGL context lost, attempting to restore..."); setWebglError(true); - // Attempt to restore after a delay setTimeout(() => { setCanvasKey((prev) => prev + 1); setWebglError(false); @@ -213,50 +208,69 @@ function HomePage() { ); } }; - }, [canvasKey]); + }, [canvasKey, isMobile]); - // Main page loading effect + // Reduced page loading time useEffect(() => { - const minLoadTime = setTimeout(() => { - setPageLoading(false); - }, 2000); + const minLoadTime = setTimeout( + () => { + setPageLoading(false); + }, + isMobile ? 1000 : 2000 + ); // Faster on mobile return () => clearTimeout(minLoadTime); - }, []); + }, [isMobile]); - // Content animations after loading + // Optimized content animations useEffect(() => { if (!pageLoading) { setIsVisible(true); const text = "A single AI-driven platform that transforms the way students and teachers prepare effective study materials"; - let index = 0; - const timer = setInterval(() => { - if (index <= text.length) { - setTypewriterText(text.slice(0, index)); - index++; - } else { - clearInterval(timer); - } - }, 50); - - const featureTimer = setInterval(() => { - setCurrentFeature((prev) => (prev + 1) % features.length); - }, 3000); - - const statsTimer = setTimeout(() => { - setStats({ users: 25000, questions: 500000, notes: 150000 }); - }, 1500); + + // Instant text on mobile, typewriter on desktop + if (isMobile) { + setTypewriterText(text); + } else { + let index = 0; + const timer = setInterval(() => { + if (index <= text.length) { + setTypewriterText(text.slice(0, index)); + index++; + } else { + clearInterval(timer); + } + }, 50); + + return () => clearInterval(timer); + } + + // Slower feature rotation on mobile + const featureTimer = setInterval( + () => { + setCurrentFeature((prev) => (prev + 1) % features.length); + }, + isMobile ? 5000 : 3000 + ); + + // Instant stats on mobile + const statsTimer = setTimeout( + () => { + setStats({ users: 25000, questions: 500000, notes: 150000 }); + }, + isMobile ? 500 : 1500 + ); return () => { - clearInterval(timer); clearInterval(featureTimer); clearTimeout(statsTimer); }; } - }, [pageLoading]); + }, [pageLoading, isMobile]); + // Optimized counter for mobile const AnimatedCounter: React.FC<{ end: number; duration?: number; @@ -266,6 +280,13 @@ function HomePage() { useEffect(() => { if (end === 0) return; + + // Instant on mobile + if (isMobile) { + setCount(end); + return; + } + let startTime: number; const animate = (timestamp: number) => { if (!startTime) startTime = timestamp; @@ -274,7 +295,7 @@ function HomePage() { if (progress < 1) requestAnimationFrame(animate); }; requestAnimationFrame(animate); - }, [end, duration]); + }, [end, duration, isMobile]); return ( @@ -302,41 +323,44 @@ function HomePage() { animate={{ opacity: 1 }} transition={{ duration: 0.5 }} > -
-
-
-
-
+ {/* Simplified floating blobs - static on mobile */} + {!isMobile && ( +
+
+
+
+ )}
-
- {webglError && ( -
-
- Restoring 3D view... + {/* 3D Model - Desktop only */} + {!isMobile && ( +
+ {webglError && ( +
+
+ Restoring 3D view... +
-
- )} + )} - {!modelLoaded && !webglError && !isMobile && ( - - )} + {!modelLoaded && !webglError && ( + + )} - {!isMobile && ( @@ -367,14 +391,14 @@ function HomePage() { - )} -
+
+ )}

- + DOCLIN NOTE @@ -385,38 +409,38 @@ function HomePage() {

{typewriterText} - | + {!isMobile && ( + | + )}

Currently featuring:{" "} - - {features[currentFeature]} - + {features[currentFeature]}