From c1d1c2d7e0db75b80e1ea7bd4fe8f59bedc435e1 Mon Sep 17 00:00:00 2001 From: Lars Date: Fri, 8 May 2026 09:02:19 +0200 Subject: [PATCH] feat: implement lazy loading for MediaLibraryPage and optimize video rendering - Refactored MediaLibraryPage to use React's lazy loading and Suspense for improved performance during page load. - Updated video rendering logic to utilize createElement for better flexibility and maintainability. - Enhanced loading state with a spinner to improve user experience while media content is being fetched. --- frontend/src/App.jsx | 28 ++++++++++-- frontend/src/pages/MediaLibraryPage.jsx | 58 ++++++++++++------------- 2 files changed, 53 insertions(+), 33 deletions(-) diff --git a/frontend/src/App.jsx b/frontend/src/App.jsx index 1c68048..4016a3c 100644 --- a/frontend/src/App.jsx +++ b/frontend/src/App.jsx @@ -1,4 +1,4 @@ -import React from 'react' +import React, { lazy, Suspense } from 'react' import { BrowserRouter as Router, Routes, @@ -32,10 +32,11 @@ import AdminMaturityModelsPage from './pages/AdminMaturityModelsPage' import TrainerContextsPage from './pages/TrainerContextsPage' import MediaWikiImportPage from './pages/MediaWikiImportPage' import AdminUsersPage from './pages/AdminUsersPage' -import MediaLibraryPage from './pages/MediaLibraryPage' import ActiveClubSwitcher from './components/ActiveClubSwitcher' import './app.css' +const MediaLibraryPage = lazy(() => import('./pages/MediaLibraryPage')) + // Bottom Navigation (Mobile) function Nav({ isAdmin }) { const items = getMainNavItems(isAdmin) @@ -159,7 +160,28 @@ function AppRoutes() { } /> } /> } /> - } /> + +
+
+ } + > + + + } + /> } /> } /> diff --git a/frontend/src/pages/MediaLibraryPage.jsx b/frontend/src/pages/MediaLibraryPage.jsx index 4ad8f22..73898ad 100644 --- a/frontend/src/pages/MediaLibraryPage.jsx +++ b/frontend/src/pages/MediaLibraryPage.jsx @@ -1,4 +1,4 @@ -import { useEffect, useState, useCallback, useRef } from 'react' +import { useEffect, useState, useCallback, useRef, createElement } from 'react' import { Link } from 'react-router-dom' import { LayoutGrid, @@ -162,24 +162,22 @@ function MediaThumb({ mediaId, mimeType }) { return
HEIC
} if (mime.startsWith('video/')) { - return ( -