0
0
mirror of https://github.com/naturalcrit/homebrewery.git synced 2025-12-27 22:22:42 +00:00

setZoomLevel to no longer use if/else

Remove the 'in'/'out' parameter of the function and just have the buttons send postive or negative integers equal to the desired change in the zoom.  No need for if/else statements using strings.
This commit is contained in:
Gazook89
2024-08-17 23:39:59 -05:00
parent d108088295
commit 7cc967ad49

View File

@@ -1,6 +1,7 @@
require('./toolBar.less');
const React = require('react');
const { useState, useEffect } = React;
const _ = require('lodash')
const maxZoom = 300;
const minZoom = 10;
@@ -26,13 +27,8 @@ const ToolBar = ({ onZoomChange, currentPage, onPageChange, totalPages })=>{
}));
}, [currentPage]);
const setZoomLevel = (direction)=>{
let zoomLevel = state.zoomLevel;
if(direction === 'in') {
zoomLevel += zoomStep;
} else {
zoomLevel -= zoomStep;
}
const setZoomLevel = (delta)=>{
const zoomLevel = _.clamp(state.zoomLevel + delta, minZoom, maxZoom);
setState((prevState)=>({
...prevState,
@@ -45,7 +41,7 @@ const ToolBar = ({ onZoomChange, currentPage, onPageChange, totalPages })=>{
<div className='toolBar'>
<div className='tool'>
<button
onClick={()=>setZoomLevel('out')}
onClick={()=>setZoomLevel(-20)}
disabled={state.zoomLevel <= minZoom}
>
<i className='fas fa-magnifying-glass-minus' />
@@ -80,7 +76,7 @@ const ToolBar = ({ onZoomChange, currentPage, onPageChange, totalPages })=>{
<div className='tool'>
<button
onClick={()=>setZoomLevel('in')}
onClick={()=>setZoomLevel(20)}
disabled={state.zoomLevel >= maxZoom}
>
<i className='fas fa-magnifying-glass-plus' />