From e06611a90f666b016acee6b7d3dda7079cb517ea Mon Sep 17 00:00:00 2001 From: Gazook89 Date: Mon, 26 Aug 2024 16:16:13 -0500 Subject: [PATCH] set all zoom buttons to use handleZoomButton All zoom buttons run through same handler now. They no longer take only the delta of the current zoom and desired zoom-- they take the actual desired zoom. calculateZoom is now calculateChange, to help get the desired delta. --- .../homebrew/brewRenderer/toolBar/toolBar.jsx | 23 ++++++++----------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/client/homebrew/brewRenderer/toolBar/toolBar.jsx b/client/homebrew/brewRenderer/toolBar/toolBar.jsx index 7a111fbb8..227b40a64 100644 --- a/client/homebrew/brewRenderer/toolBar/toolBar.jsx +++ b/client/homebrew/brewRenderer/toolBar/toolBar.jsx @@ -20,8 +20,8 @@ const ToolBar = ({ onZoomChange, currentPage, onPageChange, totalPages })=>{ setPageNum(currentPage); }, [currentPage]); - const handleZoomButton = (delta)=>{ - setZoomLevel(_.round(_.clamp(zoomLevel + delta, MIN_ZOOM, MAX_ZOOM))); + const handleZoomButton = (zoom)=>{ + setZoomLevel(_.round(_.clamp(zoom, MIN_ZOOM, MAX_ZOOM))); }; const handlePageInput = (pageInput)=>{ @@ -39,7 +39,7 @@ const ToolBar = ({ onZoomChange, currentPage, onPageChange, totalPages })=>{ }; - const calculateZoom = (mode)=>{ + const calculateChange = (mode)=>{ const iframe = document.getElementById('BrewRenderer'); const iframeWidth = iframe.getBoundingClientRect().width; const iframeHeight = iframe.getBoundingClientRect().height; @@ -49,12 +49,7 @@ const ToolBar = ({ onZoomChange, currentPage, onPageChange, totalPages })=>{ if(mode == 'fill'){ // find widest page, in case pages are different widths, so that the zoom is adapted to not cut the widest page off screen. - let widestPage = 0; - [...pages].forEach((page)=>{ - const width = page.offsetWidth; - if(width > widestPage) - widestPage = width; - }); + const widestPage = _.maxBy([...pages], 'offsetWidth').offsetWidth; desiredZoom = (iframeWidth / widestPage) * 100; @@ -88,21 +83,21 @@ const ToolBar = ({ onZoomChange, currentPage, onPageChange, totalPages })=>{