mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2026-01-01 21:42:44 +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:
@@ -15,9 +15,7 @@ const ToolBar = ({ displayOptions, onDisplayOptionsChange, visiblePages, totalPa
|
|||||||
const [toolsVisible, setToolsVisible] = useState(true);
|
const [toolsVisible, setToolsVisible] = useState(true);
|
||||||
|
|
||||||
useEffect(()=>{
|
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]);
|
}, [visiblePages]);
|
||||||
|
|
||||||
const handleZoomButton = (zoom)=>{
|
const handleZoomButton = (zoom)=>{
|
||||||
@@ -74,12 +72,9 @@ const ToolBar = ({ displayOptions, onDisplayOptionsChange, visiblePages, totalPa
|
|||||||
return deltaZoom;
|
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)=>{
|
const formatVisiblePages = (pages)=>{
|
||||||
if(pages.length === 0) return '';
|
return pages.length === 1 ? `${pages[0]}` : `${pages[0]} - ${pages.at(-1)}`;
|
||||||
|
|
||||||
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 (
|
return (
|
||||||
|
|||||||
Reference in New Issue
Block a user