0
0
mirror of https://github.com/naturalcrit/homebrewery.git synced 2025-12-30 00:12:56 +00:00

lint and refactor

This commit is contained in:
Gazook89
2024-11-07 10:40:44 -06:00
parent 88b34a7ba3
commit 9ef11bca99
2 changed files with 12 additions and 19 deletions

View File

@@ -128,23 +128,14 @@ const BrewRenderer = (props)=>{
rawPages = props.text.split(/^\\page$/gm);
}
// update centerPage (aka "current page") and pass it up to parent components
useEffect(()=>{
props.onPageChange(state.centerPage);
}, [state.centerPage]);
const handlePageVisibilityChange = useCallback((pageNum, isVisible)=>{
setState((prevState)=>{
const updatedVisiblePages = new Set(prevState.visiblePages);
if(isVisible){
updatedVisiblePages.add(pageNum);
} else {
updatedVisiblePages.delete(pageNum);
}
const pages = Array.from(updatedVisiblePages);
isVisible ? updatedVisiblePages.add(pageNum) : updatedVisiblePages.delete(pageNum);
return { ...prevState,
visiblePages : _.sortBy(pages)
return {
...prevState,
visiblePages : [...updatedVisiblePages].sort((a, b)=>a - b)
};
});
}, []);
@@ -154,7 +145,9 @@ const BrewRenderer = (props)=>{
...prevState,
centerPage : pageNum,
}));
}, []);
props.onPageChange(pageNum);
}, [props.onPageChange]);
const isInView = (index)=>{
if(!state.isMounted)

View File

@@ -66,7 +66,7 @@ const ToolBar = ({ displayOptions, onDisplayOptionsChange, visiblePages, totalPa
} else {
minDimRatio = [...pages].reduce((minRatio, page)=>Math.min(minRatio, iframeWidth / page.offsetWidth, iframeHeight / page.offsetHeight), Infinity);
}
console.log(minDimRatio)
console.log(minDimRatio);
desiredZoom = minDimRatio * 100;
}
@@ -249,14 +249,14 @@ const ToolBar = ({ displayOptions, onDisplayOptionsChange, visiblePages, totalPa
title='Next Page(s)'
onClick={()=>{
// if there are multiple pages in a 'row' and they are in 'view',
// then the 'max'/last page in view will always be the same, and
// 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,
// 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);
const start = _.max(visiblePages);
scrollToPage(start);
if(start === _.max(visiblePages)){
scrollToPage(start + 1)
scrollToPage(start + 1);
};
}}
disabled={pageNum >= totalPages}