mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2026-01-06 07:52:40 +00:00
Change page range to only display a single range
Having multiple page ranges visible is a weird edge case that only happens in two-page view. Simplifying logic to just group all page ranges together if a middle page is partly obscured.
This commit is contained in:
@@ -79,20 +79,7 @@ const ToolBar = ({ displayOptions, onDisplayOptionsChange, visiblePages, totalPa
|
|||||||
if(pages.length === 0) return '';
|
if(pages.length === 0) return '';
|
||||||
|
|
||||||
const sortedPages = [...pages].sort((a, b)=>a - b); // Copy and sort the array
|
const sortedPages = [...pages].sort((a, b)=>a - b); // Copy and sort the array
|
||||||
const ranges = [];
|
return sortedPages.length == 1 ? `${sortedPages[0]}` : `${sortedPages[0]} - ${sortedPages.at(-1)}`;
|
||||||
let start = sortedPages[0];
|
|
||||||
|
|
||||||
for (let i = 1; i <= sortedPages.length; i++) {
|
|
||||||
// If the current page is the end of the list or not consecutive
|
|
||||||
if(i === sortedPages.length || sortedPages[i] !== sortedPages[i - 1] + 1) {
|
|
||||||
ranges.push(
|
|
||||||
start === sortedPages[i - 1] ? `${start}` : `${start} - ${sortedPages[i - 1]}`
|
|
||||||
);
|
|
||||||
start = sortedPages[i]; // Start a new range
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return ranges.join(', ');
|
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
Reference in New Issue
Block a user