From b69c1828cbd6129700e47cdcaf287f75a7aefe2e Mon Sep 17 00:00:00 2001 From: Josh Hawkins <32435876+hawkeye217@users.noreply.github.com> Date: Thu, 2 May 2024 15:05:20 -0500 Subject: [PATCH] Fix overflowing portrait images in debug and motion tuner views (#11209) * fix overflowing camera image and remove mse console debug * move calc into onLoad * check container aspect --- web/src/components/camera/CameraImage.tsx | 14 +++++++++++++- web/src/components/player/MsePlayer.tsx | 6 ++---- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/web/src/components/camera/CameraImage.tsx b/web/src/components/camera/CameraImage.tsx index ab0bfdf08..b4fb707bc 100644 --- a/web/src/components/camera/CameraImage.tsx +++ b/web/src/components/camera/CameraImage.tsx @@ -2,6 +2,7 @@ import { useApiHost } from "@/api"; import { useEffect, useRef, useState } from "react"; import useSWR from "swr"; import ActivityIndicator from "../indicators/activity-indicator"; +import { useResizeObserver } from "@/hooks/resize-observer"; type CameraImageProps = { className?: string; @@ -24,6 +25,7 @@ export default function CameraImage({ const { name } = config ? config.cameras[camera] : ""; const enabled = config ? config.cameras[camera].enabled : "True"; + const [isPortraitImage, setIsPortraitImage] = useState(false); useEffect(() => { if (!config || !imgRef.current) { @@ -35,15 +37,25 @@ export default function CameraImage({ }`; }, [apiHost, name, imgRef, searchParams, config]); + const [{ width: containerWidth, height: containerHeight }] = + useResizeObserver(containerRef); + return (
{enabled ? ( { setHasLoaded(true); + if (imgRef.current) { + const { naturalHeight, naturalWidth } = imgRef.current; + setIsPortraitImage( + naturalWidth / naturalHeight < containerWidth / containerHeight, + ); + } + if (onload) { onload(); } diff --git a/web/src/components/player/MsePlayer.tsx b/web/src/components/player/MsePlayer.tsx index 222f2ebcd..63f78006f 100644 --- a/web/src/components/player/MsePlayer.tsx +++ b/web/src/components/player/MsePlayer.tsx @@ -215,8 +215,7 @@ function MSEPlayer({ } } } catch (e) { - // eslint-disable-next-line no-console - console.debug(e); + // no-op } }); @@ -233,8 +232,7 @@ function MSEPlayer({ try { sb?.appendBuffer(data); } catch (e) { - // eslint-disable-next-line no-console - console.debug(e); + // no-op } } };