From 7bc0af9a8c37ae57c2a2d2952f64bdf588e91c2a Mon Sep 17 00:00:00 2001 From: Gazook89 Date: Tue, 27 Aug 2024 08:42:45 -0500 Subject: [PATCH] utilize Infinity and reduce() --- client/homebrew/brewRenderer/toolBar/toolBar.jsx | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/client/homebrew/brewRenderer/toolBar/toolBar.jsx b/client/homebrew/brewRenderer/toolBar/toolBar.jsx index 227b40a64..fb3b62067 100644 --- a/client/homebrew/brewRenderer/toolBar/toolBar.jsx +++ b/client/homebrew/brewRenderer/toolBar/toolBar.jsx @@ -55,19 +55,9 @@ const ToolBar = ({ onZoomChange, currentPage, onPageChange, totalPages })=>{ } else if(mode == 'fit'){ // find the page with the largest single dim (height or width) so that zoom can be adapted to fit it. - let maxDimRatio = 0; - - [...pages].forEach((page)=>{ - const widthRatio = iframeWidth / page.offsetWidth; - const heightRatio = iframeHeight / page.offsetHeight; - const dimensionRatio = Math.min(widthRatio, heightRatio); - if(dimensionRatio < maxDimRatio || maxDimRatio == 0){ - maxDimRatio = dimensionRatio; - } - }); - - desiredZoom = maxDimRatio * 100; + const minDimRatio = [...pages].reduce((minRatio, page) => Math.min(minRatio, iframeWidth / page.offsetWidth, iframeHeight / page.offsetHeight), Infinity); + desiredZoom = minDimRatio * 100; } const margin = 5; // extra space so page isn't edge to edge (not truly "to fill")