fix: Address PR review comments

- Remove redundant useMemo wrapper in usePatternValidation
  Inline the calculation logic directly in useMemo instead of
  useCallback + useMemo pattern for better clarity and efficiency

- Remove unnecessary 'Early return' comment in usePatternRotationUpload
  The return statement is self-explanatory
This commit is contained in:
Jan-Henrik Bruhn 2025-12-27 11:39:48 +01:00
parent c905c4f5f7
commit e63a96b024
2 changed files with 4 additions and 12 deletions

View file

@ -119,7 +119,7 @@ export function usePatternRotationUpload({
pesData, // Original unrotated pattern for caching
);
return; // Early return
return;
}
// No rotation case

View file

@ -1,4 +1,4 @@
import { useCallback, useMemo } from "react";
import { useMemo } from "react";
import type { PesPatternData } from "../formats/import/pesImporter";
import type { MachineInfo } from "../types/machine";
import { calculateRotatedBounds } from "../utils/rotationUtils";
@ -31,8 +31,8 @@ export function usePatternValidation({
patternOffset,
patternRotation,
}: UsePatternValidationParams): PatternBoundsCheckResult {
// Check if pattern (with offset and rotation) fits within hoop bounds
const checkPatternFitsInHoop = useCallback((): PatternBoundsCheckResult => {
// Memoize the bounds check calculation to avoid unnecessary recalculations
return useMemo((): PatternBoundsCheckResult => {
if (!pesData || !machineInfo) {
return { fits: true, error: null };
}
@ -94,12 +94,4 @@ export function usePatternValidation({
return { fits: true, error: null };
}, [pesData, machineInfo, patternOffset, patternRotation]);
// Memoize the result to avoid unnecessary recalculations
const boundsCheck = useMemo(
() => checkPatternFitsInHoop(),
[checkPatternFitsInHoop],
);
return boundsCheck;
}