0
0
mirror of https://github.com/naturalcrit/homebrewery.git synced 2025-12-25 03:12:40 +00:00

Remove toolbar checks for empty visiblePages list

With `centerPage`, ToolBar will never receive an empty visiblePages array. No need to check if visiblepages.length == 0
This commit is contained in:
Trevor Buckner
2024-12-24 00:18:37 -05:00
parent c0155052ea
commit 0632d78f71

View File

@@ -15,9 +15,7 @@ const ToolBar = ({ displayOptions, onDisplayOptionsChange, visiblePages, totalPa
const [toolsVisible, setToolsVisible] = useState(true);
useEffect(()=>{
if(visiblePages.length !== 0){ // If zoomed in enough, it's possible that no page fits the intersection criteria, so don't update.
setPageNum(formatVisiblePages(visiblePages));
}
setPageNum(formatVisiblePages(visiblePages));
}, [visiblePages]);
const handleZoomButton = (zoom)=>{
@@ -74,12 +72,9 @@ const ToolBar = ({ displayOptions, onDisplayOptionsChange, visiblePages, totalPa
return deltaZoom;
};
// format the visible pages to work with ranges, including separate ranges ("2-7, 10-15")
// format the visible pages into a range (e.g. "150-153")
const formatVisiblePages = (pages)=>{
if(pages.length === 0) return '';
const sortedPages = [...pages].sort((a, b)=>a - b); // Copy and sort the array
return sortedPages.length == 1 ? `${sortedPages[0]}` : `${sortedPages[0]} - ${sortedPages.at(-1)}`;
return pages.length === 1 ? `${pages[0]}` : `${pages[0]} - ${pages.at(-1)}`;
};
return (