mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2026-01-09 09:22:38 +00:00
Small cleanups
This commit is contained in:
@@ -32,10 +32,8 @@ const INITIAL_CONTENT = dedent`
|
|||||||
//v=====----------------------< Brew Page Component >---------------------=====v//
|
//v=====----------------------< Brew Page Component >---------------------=====v//
|
||||||
const BrewPage = (props)=>{
|
const BrewPage = (props)=>{
|
||||||
props = {
|
props = {
|
||||||
contents : '',
|
contents : '',
|
||||||
index : 0,
|
index : 0,
|
||||||
onVisibilityChange : ()=>{},
|
|
||||||
onCenterPageChange : ()=>{},
|
|
||||||
...props
|
...props
|
||||||
};
|
};
|
||||||
const pageRef = useRef(null);
|
const pageRef = useRef(null);
|
||||||
@@ -77,7 +75,7 @@ const BrewPage = (props)=>{
|
|||||||
visibleObserver.disconnect();
|
visibleObserver.disconnect();
|
||||||
centerObserver.disconnect();
|
centerObserver.disconnect();
|
||||||
};
|
};
|
||||||
}, [props.index, props.onVisibilityChange, props.onCenterPageChange]);
|
}, []);
|
||||||
|
|
||||||
return <div className={props.className} id={`p${props.index + 1}`} data-index={props.index} ref={pageRef} style={props.style}>
|
return <div className={props.className} id={`p${props.index + 1}`} data-index={props.index} ref={pageRef} style={props.style}>
|
||||||
<div className='columnWrapper' dangerouslySetInnerHTML={{ __html: cleanText }} />
|
<div className='columnWrapper' dangerouslySetInnerHTML={{ __html: cleanText }} />
|
||||||
|
|||||||
@@ -25,7 +25,6 @@ const ToolBar = ({ displayOptions, onDisplayOptionsChange, visiblePages, totalPa
|
|||||||
};
|
};
|
||||||
|
|
||||||
const handleOptionChange = (optionKey, newValue)=>{
|
const handleOptionChange = (optionKey, newValue)=>{
|
||||||
//setDisplayOptions(prevOptions => ({ ...prevOptions, [optionKey]: newValue }));
|
|
||||||
onDisplayOptionsChange({ ...displayOptions, [optionKey]: newValue });
|
onDisplayOptionsChange({ ...displayOptions, [optionKey]: newValue });
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -61,12 +60,10 @@ const ToolBar = ({ displayOptions, onDisplayOptionsChange, visiblePages, totalPa
|
|||||||
} else if(mode == 'fit'){
|
} else if(mode == 'fit'){
|
||||||
let minDimRatio;
|
let minDimRatio;
|
||||||
// find the page with the largest single dim (height or width) so that zoom can be adapted to fit it.
|
// find the page with the largest single dim (height or width) so that zoom can be adapted to fit it.
|
||||||
if(displayOptions.spread === 'facing'){
|
if(displayOptions.spread === 'facing')
|
||||||
minDimRatio = [...pages].reduce((minRatio, page)=>Math.min(minRatio, iframeWidth / page.offsetWidth / 2), Infinity); // if 'facing' spread, fit two pages in view
|
minDimRatio = [...pages].reduce((minRatio, page)=>Math.min(minRatio, iframeWidth / page.offsetWidth / 2), Infinity); // if 'facing' spread, fit two pages in view
|
||||||
} 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);
|
|
||||||
|
|
||||||
desiredZoom = minDimRatio * 100;
|
desiredZoom = minDimRatio * 100;
|
||||||
}
|
}
|
||||||
@@ -86,9 +83,8 @@ const ToolBar = ({ displayOptions, onDisplayOptionsChange, visiblePages, totalPa
|
|||||||
let start = sortedPages[0];
|
let start = sortedPages[0];
|
||||||
|
|
||||||
for (let i = 1; i <= sortedPages.length; i++) {
|
for (let i = 1; i <= sortedPages.length; i++) {
|
||||||
// If the current page is not consecutive or it's the end of the list
|
// If the current page is the end of the list or not consecutive
|
||||||
if(i === sortedPages.length || sortedPages[i] !== sortedPages[i - 1] + 1) {
|
if(i === sortedPages.length || sortedPages[i] !== sortedPages[i - 1] + 1) {
|
||||||
// Push the range to the list
|
|
||||||
ranges.push(
|
ranges.push(
|
||||||
start === sortedPages[i - 1] ? `${start}` : `${start} - ${sortedPages[i - 1]}`
|
start === sortedPages[i - 1] ? `${start}` : `${start} - ${sortedPages[i - 1]}`
|
||||||
);
|
);
|
||||||
@@ -233,7 +229,7 @@ const ToolBar = ({ displayOptions, onDisplayOptionsChange, visiblePages, totalPa
|
|||||||
title='Current page(s) in view'
|
title='Current page(s) in view'
|
||||||
inputMode='numeric'
|
inputMode='numeric'
|
||||||
pattern='[0-9]'
|
pattern='[0-9]'
|
||||||
value={`${pageNum}`}
|
value={pageNum}
|
||||||
onClick={(e)=>e.target.select()}
|
onClick={(e)=>e.target.select()}
|
||||||
onChange={(e)=>handlePageInput(e.target.value)}
|
onChange={(e)=>handlePageInput(e.target.value)}
|
||||||
onBlur={()=>scrollToPage(pageNum)}
|
onBlur={()=>scrollToPage(pageNum)}
|
||||||
@@ -257,6 +253,7 @@ const ToolBar = ({ displayOptions, onDisplayOptionsChange, visiblePages, totalPa
|
|||||||
const start = _.max(visiblePages);
|
const start = _.max(visiblePages);
|
||||||
scrollToPage(start);
|
scrollToPage(start);
|
||||||
if(start === _.max(visiblePages)){
|
if(start === _.max(visiblePages)){
|
||||||
|
console.log("oh no")
|
||||||
scrollToPage(start + 1);
|
scrollToPage(start + 1);
|
||||||
};
|
};
|
||||||
}}
|
}}
|
||||||
|
|||||||
Reference in New Issue
Block a user