mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2026-11-22 21:06:58 +00:00
fold handlePageChange directly into input onChange
Moved the single-line handler to operate directly in the onChange handler of the input that is calling it. Considered doing the same with handleZoomChange, but that handler is used by two buttons rather than just one.
This commit is contained in:
1 parent
769a03916b
commit
7f694e6ca7
1 file changed
+6
-12
@@ -19,14 +19,10 @@ const ToolBar = ({ onZoomChange, currentPage, onPageChange, totalPages })=>{
|
||||
setPageNum(currentPage);
|
||||
}, [currentPage])
|
||||
|
||||
const handleZoomChange = (delta)=>{
|
||||
const zoomChange = _.clamp(zoomLevel + delta, MIN_ZOOM, MAX_ZOOM);
|
||||
const handleZoomButton = (delta)=>{
|
||||
const newZoomLevel = _.clamp(zoomLevel + delta, MIN_ZOOM, MAX_ZOOM);
|
||||
|
||||
setZoomLevel(zoomChange);
|
||||
};
|
||||
|
||||
const handlePageChange = (page)=>{
|
||||
setPageNum(page);
|
||||
setZoomLevel(newZoomLevel);
|
||||
};
|
||||
|
||||
const scrollToPage = (pageNumber) => {
|
||||
@@ -47,7 +43,7 @@ const ToolBar = ({ onZoomChange, currentPage, onPageChange, totalPages })=>{
|
||||
<button
|
||||
id='zoom-out'
|
||||
className='tool'
|
||||
onClick={()=>handleZoomChange(-20)}
|
||||
onClick={()=>handleZoomButton(-20)}
|
||||
disabled={zoomLevel <= MIN_ZOOM}
|
||||
>
|
||||
<i className='fas fa-magnifying-glass-minus' />
|
||||
@@ -71,7 +67,7 @@ const ToolBar = ({ onZoomChange, currentPage, onPageChange, totalPages })=>{
|
||||
<button
|
||||
id='zoom-in'
|
||||
className='tool'
|
||||
onClick={()=>handleZoomChange(20)}
|
||||
onClick={()=>handleZoomButton(20)}
|
||||
disabled={zoomLevel >= MAX_ZOOM}
|
||||
>
|
||||
<i className='fas fa-magnifying-glass-plus' />
|
||||
@@ -97,12 +93,10 @@ const ToolBar = ({ onZoomChange, currentPage, onPageChange, totalPages })=>{
|
||||
inputMode='numeric'
|
||||
pattern='[0-9]'
|
||||
value={pageNum}
|
||||
onChange={(e)=>{
|
||||
handlePageChange(e.target.value == false ? e.target.value : parseInt(e.target.value));}}
|
||||
onChange={(e)=>{setPageNum(e.target.value == false ? e.target.value : parseInt(e.target.value));}}
|
||||
onBlur={()=>scrollToPage(pageNum)}
|
||||
onKeyDown={(e)=>{e.key == 'Enter' ? scrollToPage(pageNum) : null;}}
|
||||
/>
|
||||
|
||||
<span id='page-count'>/ {totalPages}</span>
|
||||
</div>
|
||||
|
||||
|
||||
Reference in new issue
Block a user