0
0
mirror of https://github.com/naturalcrit/homebrewery.git synced 2026-01-17 01:32:45 +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); 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)=>{ const handlePageVisibilityChange = useCallback((pageNum, isVisible)=>{
setState((prevState)=>{ setState((prevState)=>{
const updatedVisiblePages = new Set(prevState.visiblePages); const updatedVisiblePages = new Set(prevState.visiblePages);
if(isVisible){ isVisible ? updatedVisiblePages.add(pageNum) : updatedVisiblePages.delete(pageNum);
updatedVisiblePages.add(pageNum);
} else {
updatedVisiblePages.delete(pageNum);
}
const pages = Array.from(updatedVisiblePages);
return { ...prevState, return {
visiblePages : _.sortBy(pages) ...prevState,
visiblePages : [...updatedVisiblePages].sort((a, b)=>a - b)
}; };
}); });
}, []); }, []);
@@ -154,7 +145,9 @@ const BrewRenderer = (props)=>{
...prevState, ...prevState,
centerPage : pageNum, centerPage : pageNum,
})); }));
}, []);
props.onPageChange(pageNum);
}, [props.onPageChange]);
const isInView = (index)=>{ const isInView = (index)=>{
if(!state.isMounted) if(!state.isMounted)

View File

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