mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2026-01-06 20:52:40 +00:00
Simplify logic for previous/next buttons
This commit is contained in:
@@ -199,8 +199,7 @@ const ToolBar = ({ displayOptions, onDisplayOptionsChange, visiblePages, totalPa
|
|||||||
type='button'
|
type='button'
|
||||||
title='Previous Page(s)'
|
title='Previous Page(s)'
|
||||||
onClick={()=>{
|
onClick={()=>{
|
||||||
const rangeOffset = visiblePages.length > 1 ? 1 : 0;
|
scrollToPage(_.min(visiblePages) - visiblePages.length);
|
||||||
scrollToPage(_.min(visiblePages) - visiblePages.length + rangeOffset);
|
|
||||||
}}
|
}}
|
||||||
disabled={visiblePages.includes(1)}
|
disabled={visiblePages.includes(1)}
|
||||||
>
|
>
|
||||||
@@ -232,17 +231,7 @@ const ToolBar = ({ displayOptions, onDisplayOptionsChange, visiblePages, totalPa
|
|||||||
type='button'
|
type='button'
|
||||||
title='Next Page(s)'
|
title='Next Page(s)'
|
||||||
onClick={()=>{
|
onClick={()=>{
|
||||||
// if there are multiple pages in a 'row' and they are in 'view',
|
scrollToPage(_.max(visiblePages) + 1);
|
||||||
// then the 'max'/last page in view will always be the same, and
|
|
||||||
// the other pages will always be the same (since the viewport doesn't change).
|
|
||||||
// So this needs to scroll to the 'max', then see what is newly in view,
|
|
||||||
// and if the same pages are visible, do it again but +1.
|
|
||||||
const start = _.max(visiblePages);
|
|
||||||
scrollToPage(start);
|
|
||||||
if(start === _.max(visiblePages)){
|
|
||||||
console.log("oh no")
|
|
||||||
scrollToPage(start + 1);
|
|
||||||
};
|
|
||||||
}}
|
}}
|
||||||
disabled={visiblePages.includes(totalPages)}
|
disabled={visiblePages.includes(totalPages)}
|
||||||
>
|
>
|
||||||
|
|||||||
Reference in New Issue
Block a user