From d36b9de4a6dff3855cd801ad68bfe3da25443243 Mon Sep 17 00:00:00 2001 From: Johannes Date: Sun, 14 Sep 2025 16:27:36 +0200 Subject: [PATCH] feat: Viewport lazy loading and video refresh support - Add intersection observer hooks for viewport detection - Lazy load iframes and control video autoplay based on visibility - Extend refresh button to restart videos from beginning - Show refresh button for both HTML animations and video content - Add intelligent feedback messages for mixed media types - Optimize performance by loading media only when in viewport --- frontend/src/components/FilePreview.js | 47 ++++++++++++++----- frontend/src/utils/adUtils.js | 34 +++++++++++--- frontend/src/utils/tabUtils.js | 6 +-- frontend/src/utils/viewportUtils.js | 62 ++++++++++++++++++++++++++ 4 files changed, 130 insertions(+), 19 deletions(-) create mode 100644 frontend/src/utils/viewportUtils.js diff --git a/frontend/src/components/FilePreview.js b/frontend/src/components/FilePreview.js index a8ea33e..1c28193 100644 --- a/frontend/src/components/FilePreview.js +++ b/frontend/src/components/FilePreview.js @@ -1,5 +1,6 @@ import React from 'react'; import { Spin } from 'antd'; +import { useVideoAutoPlay, useInViewport } from '../utils/viewportUtils'; // Hilfsfunktion für Dateigröße export function formatFileSize(bytes) { @@ -24,6 +25,10 @@ export default function FilePreview({ file, zoom = 1, darkMode = false }) { const width = file.width || 300; const height = file.height || 200; + // Viewport-Detection für Videos und iFrames + const { containerRef: videoContainerRef, videoRef, isInViewport: videoInViewport } = useVideoAutoPlay(); + const { ref: iframeRef, isInViewport: iframeInViewport } = useInViewport(); + // Wrapper für saubere Skalierung const wrapperStyle = { display: 'inline-block', @@ -45,7 +50,7 @@ export default function FilePreview({ file, zoom = 1, darkMode = false }) { const renderFileContent = () => { if (file.type === 'html') { return ( -
+
{!loaded && (
)} -