From c00f58bced05725a2b0516508126b694ca811cd0 Mon Sep 17 00:00:00 2001 From: Ahmed Darrazi Date: Thu, 18 Dec 2025 15:23:00 +0100 Subject: [PATCH] Optimize mobile load by lazy loading large modules --- .../dashboard/partials/nav-main-item.tsx | 6 ++-- resources/js/layouts/dashboard/sidebar.tsx | 4 ++- .../js/pages/intro/partials/home-4/hero.tsx | 28 +++++++++++-------- .../intro/partials/home-4/top-course.tsx | 28 +++++++++++-------- resources/js/pages/intro/partials/section.tsx | 23 ++++++++------- 5 files changed, 52 insertions(+), 37 deletions(-) diff --git a/resources/js/layouts/dashboard/partials/nav-main-item.tsx b/resources/js/layouts/dashboard/partials/nav-main-item.tsx index 900e4743..786a786a 100644 --- a/resources/js/layouts/dashboard/partials/nav-main-item.tsx +++ b/resources/js/layouts/dashboard/partials/nav-main-item.tsx @@ -1,5 +1,6 @@ import { AccordionContent, AccordionItem, AccordionTrigger } from '@/components/ui/accordion'; import { SidebarMenuButton, useSidebar } from '@/components/ui/sidebar'; +import { useIsMobile } from '@/hooks/use-mobile'; import { routeLastSegment, routeSecondSegment } from '@/lib/route'; import { cn } from '@/lib/utils'; import { SharedData } from '@/types/global'; @@ -14,6 +15,7 @@ const NavMainItem = (props: NavMainItemProps) => { const page = usePage(); const { auth, direction } = page.props; const { state, toggleSidebar } = useSidebar(); + const isMobile = useIsMobile(); const { pageRoute } = props; const { Icon, name, path, children, slug } = pageRoute; @@ -67,7 +69,7 @@ const NavMainItem = (props: NavMainItemProps) => { if (access.includes(auth.user.role)) { return ( - + {name} @@ -88,7 +90,7 @@ const NavMainItem = (props: NavMainItemProps) => { : '', )} > - + {name} diff --git a/resources/js/layouts/dashboard/sidebar.tsx b/resources/js/layouts/dashboard/sidebar.tsx index 60737011..47d4d61a 100644 --- a/resources/js/layouts/dashboard/sidebar.tsx +++ b/resources/js/layouts/dashboard/sidebar.tsx @@ -1,5 +1,6 @@ import AppLogo from '@/components/app-logo'; import { Sidebar, SidebarContent, SidebarFooter, SidebarHeader, SidebarMenu, SidebarMenuItem, useSidebar } from '@/components/ui/sidebar'; +import { useIsMobile } from '@/hooks/use-mobile'; import { NavMain } from '@/layouts/dashboard/partials/nav-main'; import { NavUser } from '@/layouts/dashboard/partials/nav-user'; import { SharedData } from '@/types/global'; @@ -9,6 +10,7 @@ const DashboardSidebar = () => { const { state } = useSidebar(); const { props } = usePage(); const compact = state === 'collapsed' ? true : false; + const isMobile = useIsMobile(); return ( @@ -16,7 +18,7 @@ const DashboardSidebar = () => { - + diff --git a/resources/js/pages/intro/partials/home-4/hero.tsx b/resources/js/pages/intro/partials/home-4/hero.tsx index e92b18a7..33913349 100644 --- a/resources/js/pages/intro/partials/home-4/hero.tsx +++ b/resources/js/pages/intro/partials/home-4/hero.tsx @@ -3,14 +3,16 @@ import RatingStars from '@/components/rating-stars'; import { Button } from '@/components/ui/button'; import { Card } from '@/components/ui/card'; import { Dialog, DialogContent, DialogTrigger } from '@/components/ui/dialog'; -import VideoPlayer from '@/components/video-player'; import { getPageSection, getPropertyArray } from '@/lib/page'; import { cn } from '@/lib/utils'; import { IntroPageProps } from '@/types/page'; import { Link, usePage } from '@inertiajs/react'; import { Play } from 'lucide-react'; +import { lazy, Suspense } from 'react'; import Section from '../section'; +const VideoPlayer = lazy(() => import('@/components/video-player')); + const Hero = () => { const { props } = usePage(); const { page } = props; @@ -65,17 +67,19 @@ const Hero = () => { - + + + )} diff --git a/resources/js/pages/intro/partials/home-4/top-course.tsx b/resources/js/pages/intro/partials/home-4/top-course.tsx index 058f5c49..e2d16ca7 100644 --- a/resources/js/pages/intro/partials/home-4/top-course.tsx +++ b/resources/js/pages/intro/partials/home-4/top-course.tsx @@ -1,12 +1,14 @@ import { Accordion, AccordionContent, AccordionItem, AccordionTrigger } from '@/components/ui/accordion'; import { Dialog, DialogContent, DialogTrigger } from '@/components/ui/dialog'; -import VideoPlayer from '@/components/video-player'; import { getPageSection } from '@/lib/page'; import { IntroPageProps } from '@/types/page'; import { usePage } from '@inertiajs/react'; import { File, FileQuestion, FileText, Image, Play, Video } from 'lucide-react'; +import { lazy, Suspense } from 'react'; import Section from '../section'; +const VideoPlayer = lazy(() => import('@/components/video-player')); + const TopCourse = () => { const { props } = usePage(); const { page, topCourse, customize } = props; @@ -34,17 +36,19 @@ const TopCourse = () => { - + + + )} diff --git a/resources/js/pages/intro/partials/section.tsx b/resources/js/pages/intro/partials/section.tsx index 3428eb24..6c1ae063 100644 --- a/resources/js/pages/intro/partials/section.tsx +++ b/resources/js/pages/intro/partials/section.tsx @@ -1,8 +1,9 @@ -import SectionEditor from '@/components/section-editor'; import { Button } from '@/components/ui/button'; import { cn } from '@/lib/utils'; import { Pencil } from 'lucide-react'; -import { ReactNode } from 'react'; +import { lazy, ReactNode, Suspense } from 'react'; + +const SectionEditor = lazy(() => import('@/components/section-editor')); interface SectionProps extends React.HTMLAttributes { children: ReactNode; @@ -19,14 +20,16 @@ const Section = ({ containerClass, contentClass, children, pageSection, customiz
{customize && pageSection && ( - - - - } - /> + + + + + } + /> + )} {/* Content */}