Use "coerceIn" util function
This commit is contained in:
@@ -25,6 +25,7 @@ import Slider from '@mui/material/Slider';
|
||||
import DialogContentText from '@mui/material/DialogContentText';
|
||||
import InfoIcon from '@mui/icons-material/Info';
|
||||
import { SxProps, Theme } from '@mui/material/styles';
|
||||
import { coerceIn } from '@/lib/HelperFunctions.ts';
|
||||
|
||||
type BaseProps = {
|
||||
settingTitle: string;
|
||||
@@ -170,10 +171,8 @@ export const NumberSetting = ({
|
||||
type="number"
|
||||
onChange={(e) => {
|
||||
const newValue = Number(e.target.value);
|
||||
const newValueMinLimit = Math.min(newValue, maxValue ?? newValue);
|
||||
const newValueMaxLimit = Math.max(newValueMinLimit, minValue ?? newValueMinLimit);
|
||||
|
||||
updateValue(newValueMaxLimit, false);
|
||||
const newValueCoerced = coerceIn(newValue, minValue ?? newValue, maxValue ?? newValue);
|
||||
updateValue(newValueCoerced, false);
|
||||
}}
|
||||
slotProps={{
|
||||
input: {
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
|
||||
import { MutableRefObject, useEffect, useRef, useState } from 'react';
|
||||
import { ScrollDirection } from '@/modules/core/Core.types.ts';
|
||||
import { coerceIn } from '@/lib/HelperFunctions.ts';
|
||||
|
||||
type Positions = [OldestPos: number, SecondOldestPos: number, LatestPos: number];
|
||||
type ClickTimes = [OldestTime: number, SecondOldestTime: number, LatestTime: number];
|
||||
@@ -80,7 +81,7 @@ export const useMouseDragScroll = (
|
||||
return Math.abs(v0[X]);
|
||||
})();
|
||||
const unitVector = [v0[X] / a0V, v0[Y] / a0V];
|
||||
const a0VCoerced = Math.min(12, Math.max(-12, 1.2 * a0V));
|
||||
const a0VCoerced = coerceIn(1.2 * a0V, -12, 12);
|
||||
|
||||
const t = (Date.now() - previousClickTime.current[LATEST]) / 1000;
|
||||
const v =
|
||||
@@ -109,8 +110,8 @@ export const useMouseDragScroll = (
|
||||
element.scrollHeight - element.clientHeight,
|
||||
];
|
||||
const newScrollPos = [
|
||||
Math.min(maxScrollPos[X], Math.max(isRTL ? -maxScrollPos[X] : 0, scrollAtT0.current[X] - delta[X])),
|
||||
Math.min(maxScrollPos[Y], Math.max(0, scrollAtT0.current[Y] - delta[Y])),
|
||||
coerceIn(scrollAtT0.current[X] - delta[X], isRTL ? -maxScrollPos[X] : 0, maxScrollPos[X]),
|
||||
coerceIn(scrollAtT0.current[Y] - delta[Y], 0, maxScrollPos[Y]),
|
||||
];
|
||||
|
||||
const isScrollXPossible = newScrollPos[X] !== 0 || newScrollPos[X] !== maxScrollPos[X];
|
||||
|
||||
@@ -25,6 +25,7 @@ import {
|
||||
} from '@/modules/reader/utils/ReaderPager.utils.tsx';
|
||||
import { ReaderStatePages } from '@/modules/reader/types/ReaderProgressBar.types.ts';
|
||||
import { ReaderControls } from '@/modules/reader/services/ReaderControls.ts';
|
||||
import { coerceIn } from '@/lib/HelperFunctions.ts';
|
||||
|
||||
export const getInitialReaderPageIndex = (
|
||||
resumeMode: ReaderResumeMode,
|
||||
@@ -39,7 +40,7 @@ export const getInitialReaderPageIndex = (
|
||||
return lastPageIndex;
|
||||
}
|
||||
|
||||
return Math.max(0, Math.min(lastPageIndex, lastReadPageIndex));
|
||||
return coerceIn(lastReadPageIndex, 0, lastPageIndex);
|
||||
};
|
||||
|
||||
export const getReaderChapterFromCache = (id: ChapterIdInfo['id']): TChapterReader | null =>
|
||||
|
||||
Reference in New Issue
Block a user