mirror of
https://github.com/invoke-ai/InvokeAI
synced 2024-08-30 20:32:17 +00:00
fix(ui): fix memoized selectors
Some had the memoize options twice.
This commit is contained in:
parent
72cb8b83fe
commit
977d309692
@ -7,7 +7,6 @@ import {
|
|||||||
setStageCoordinates,
|
setStageCoordinates,
|
||||||
} from 'features/canvas/store/canvasSlice';
|
} from 'features/canvas/store/canvasSlice';
|
||||||
import { KonvaEventObject } from 'konva/lib/Node';
|
import { KonvaEventObject } from 'konva/lib/Node';
|
||||||
import { isEqual } from 'lodash-es';
|
|
||||||
import { useCallback } from 'react';
|
import { useCallback } from 'react';
|
||||||
|
|
||||||
const selector = createMemoizedSelector(
|
const selector = createMemoizedSelector(
|
||||||
@ -19,8 +18,7 @@ const selector = createMemoizedSelector(
|
|||||||
isStaging,
|
isStaging,
|
||||||
isMovingBoundingBox,
|
isMovingBoundingBox,
|
||||||
};
|
};
|
||||||
},
|
}
|
||||||
{ memoizeOptions: { resultEqualityCheck: isEqual } }
|
|
||||||
);
|
);
|
||||||
|
|
||||||
const useCanvasDrag = () => {
|
const useCanvasDrag = () => {
|
||||||
|
@ -11,7 +11,6 @@ import getScaledCursorPosition from 'features/canvas/util/getScaledCursorPositio
|
|||||||
import { activeTabNameSelector } from 'features/ui/store/uiSelectors';
|
import { activeTabNameSelector } from 'features/ui/store/uiSelectors';
|
||||||
import Konva from 'konva';
|
import Konva from 'konva';
|
||||||
import { KonvaEventObject } from 'konva/lib/Node';
|
import { KonvaEventObject } from 'konva/lib/Node';
|
||||||
import { isEqual } from 'lodash-es';
|
|
||||||
import { MutableRefObject, useCallback } from 'react';
|
import { MutableRefObject, useCallback } from 'react';
|
||||||
import useColorPicker from './useColorUnderCursor';
|
import useColorPicker from './useColorUnderCursor';
|
||||||
|
|
||||||
@ -24,8 +23,7 @@ const selector = createMemoizedSelector(
|
|||||||
activeTabName,
|
activeTabName,
|
||||||
isStaging,
|
isStaging,
|
||||||
};
|
};
|
||||||
},
|
}
|
||||||
{ memoizeOptions: { resultEqualityCheck: isEqual } }
|
|
||||||
);
|
);
|
||||||
|
|
||||||
const useCanvasMouseDown = (stageRef: MutableRefObject<Konva.Stage | null>) => {
|
const useCanvasMouseDown = (stageRef: MutableRefObject<Konva.Stage | null>) => {
|
||||||
|
@ -10,7 +10,6 @@ import getScaledCursorPosition from 'features/canvas/util/getScaledCursorPositio
|
|||||||
import { activeTabNameSelector } from 'features/ui/store/uiSelectors';
|
import { activeTabNameSelector } from 'features/ui/store/uiSelectors';
|
||||||
import Konva from 'konva';
|
import Konva from 'konva';
|
||||||
import { Vector2d } from 'konva/lib/types';
|
import { Vector2d } from 'konva/lib/types';
|
||||||
import { isEqual } from 'lodash-es';
|
|
||||||
import { MutableRefObject, useCallback } from 'react';
|
import { MutableRefObject, useCallback } from 'react';
|
||||||
import useColorPicker from './useColorUnderCursor';
|
import useColorPicker from './useColorUnderCursor';
|
||||||
|
|
||||||
@ -24,8 +23,7 @@ const selector = createMemoizedSelector(
|
|||||||
activeTabName,
|
activeTabName,
|
||||||
isStaging,
|
isStaging,
|
||||||
};
|
};
|
||||||
},
|
}
|
||||||
{ memoizeOptions: { resultEqualityCheck: isEqual } }
|
|
||||||
);
|
);
|
||||||
|
|
||||||
const useCanvasMouseMove = (
|
const useCanvasMouseMove = (
|
||||||
|
@ -11,7 +11,6 @@ import {
|
|||||||
import getScaledCursorPosition from 'features/canvas/util/getScaledCursorPosition';
|
import getScaledCursorPosition from 'features/canvas/util/getScaledCursorPosition';
|
||||||
import { activeTabNameSelector } from 'features/ui/store/uiSelectors';
|
import { activeTabNameSelector } from 'features/ui/store/uiSelectors';
|
||||||
import Konva from 'konva';
|
import Konva from 'konva';
|
||||||
import { isEqual } from 'lodash-es';
|
|
||||||
import { MutableRefObject, useCallback } from 'react';
|
import { MutableRefObject, useCallback } from 'react';
|
||||||
|
|
||||||
const selector = createMemoizedSelector(
|
const selector = createMemoizedSelector(
|
||||||
@ -24,8 +23,7 @@ const selector = createMemoizedSelector(
|
|||||||
activeTabName,
|
activeTabName,
|
||||||
isStaging,
|
isStaging,
|
||||||
};
|
};
|
||||||
},
|
}
|
||||||
{ memoizeOptions: { resultEqualityCheck: isEqual } }
|
|
||||||
);
|
);
|
||||||
|
|
||||||
const useCanvasMouseUp = (
|
const useCanvasMouseUp = (
|
||||||
|
@ -12,20 +12,16 @@ import {
|
|||||||
} from 'features/canvas/util/constants';
|
} from 'features/canvas/util/constants';
|
||||||
import Konva from 'konva';
|
import Konva from 'konva';
|
||||||
import { KonvaEventObject } from 'konva/lib/Node';
|
import { KonvaEventObject } from 'konva/lib/Node';
|
||||||
import { clamp, isEqual } from 'lodash-es';
|
import { clamp } from 'lodash-es';
|
||||||
import { MutableRefObject, useCallback } from 'react';
|
import { MutableRefObject, useCallback } from 'react';
|
||||||
|
|
||||||
const selector = createMemoizedSelector(
|
const selector = createMemoizedSelector([stateSelector], ({ canvas }) => {
|
||||||
[stateSelector],
|
|
||||||
({ canvas }) => {
|
|
||||||
const { isMoveStageKeyHeld, stageScale } = canvas;
|
const { isMoveStageKeyHeld, stageScale } = canvas;
|
||||||
return {
|
return {
|
||||||
isMoveStageKeyHeld,
|
isMoveStageKeyHeld,
|
||||||
stageScale,
|
stageScale,
|
||||||
};
|
};
|
||||||
},
|
});
|
||||||
{ memoizeOptions: { resultEqualityCheck: isEqual } }
|
|
||||||
);
|
|
||||||
|
|
||||||
const useCanvasWheel = (stageRef: MutableRefObject<Konva.Stage | null>) => {
|
const useCanvasWheel = (stageRef: MutableRefObject<Konva.Stage | null>) => {
|
||||||
const dispatch = useAppDispatch();
|
const dispatch = useAppDispatch();
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { Box, Flex, Image } from '@chakra-ui/react';
|
import { Box, Flex } from '@chakra-ui/react';
|
||||||
import { skipToken } from '@reduxjs/toolkit/query';
|
import { skipToken } from '@reduxjs/toolkit/query';
|
||||||
import { createMemoizedSelector } from 'app/store/createMemoizedSelector';
|
import { createMemoizedSelector } from 'app/store/createMemoizedSelector';
|
||||||
import { stateSelector } from 'app/store/store';
|
import { stateSelector } from 'app/store/store';
|
||||||
@ -9,6 +9,7 @@ import {
|
|||||||
TypesafeDraggableData,
|
TypesafeDraggableData,
|
||||||
TypesafeDroppableData,
|
TypesafeDroppableData,
|
||||||
} from 'features/dnd/types';
|
} from 'features/dnd/types';
|
||||||
|
import ProgressImage from 'features/gallery/components/CurrentImage/ProgressImage';
|
||||||
import ImageMetadataViewer from 'features/gallery/components/ImageMetadataViewer/ImageMetadataViewer';
|
import ImageMetadataViewer from 'features/gallery/components/ImageMetadataViewer/ImageMetadataViewer';
|
||||||
import NextPrevImageButtons from 'features/gallery/components/NextPrevImageButtons';
|
import NextPrevImageButtons from 'features/gallery/components/NextPrevImageButtons';
|
||||||
import { useNextPrevImage } from 'features/gallery/hooks/useNextPrevImage';
|
import { useNextPrevImage } from 'features/gallery/hooks/useNextPrevImage';
|
||||||
@ -28,14 +29,13 @@ export const imagesSelector = createMemoizedSelector(
|
|||||||
shouldHidePreview,
|
shouldHidePreview,
|
||||||
shouldShowProgressInViewer,
|
shouldShowProgressInViewer,
|
||||||
} = ui;
|
} = ui;
|
||||||
const { denoiseProgress, shouldAntialiasProgressImage } = system;
|
const { denoiseProgress } = system;
|
||||||
return {
|
return {
|
||||||
shouldShowImageDetails,
|
shouldShowImageDetails,
|
||||||
shouldHidePreview,
|
shouldHidePreview,
|
||||||
imageName: lastSelectedImage?.image_name,
|
imageName: lastSelectedImage?.image_name,
|
||||||
denoiseProgress,
|
hasDenoiseProgress: Boolean(denoiseProgress),
|
||||||
shouldShowProgressInViewer,
|
shouldShowProgressInViewer,
|
||||||
shouldAntialiasProgressImage,
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
@ -44,9 +44,8 @@ const CurrentImagePreview = () => {
|
|||||||
const {
|
const {
|
||||||
shouldShowImageDetails,
|
shouldShowImageDetails,
|
||||||
imageName,
|
imageName,
|
||||||
denoiseProgress,
|
hasDenoiseProgress,
|
||||||
shouldShowProgressInViewer,
|
shouldShowProgressInViewer,
|
||||||
shouldAntialiasProgressImage,
|
|
||||||
} = useAppSelector(imagesSelector);
|
} = useAppSelector(imagesSelector);
|
||||||
|
|
||||||
const {
|
const {
|
||||||
@ -137,23 +136,8 @@ const CurrentImagePreview = () => {
|
|||||||
position: 'relative',
|
position: 'relative',
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{denoiseProgress?.progress_image && shouldShowProgressInViewer ? (
|
{hasDenoiseProgress && shouldShowProgressInViewer ? (
|
||||||
<Image
|
<ProgressImage />
|
||||||
src={denoiseProgress.progress_image.dataURL}
|
|
||||||
width={denoiseProgress.progress_image.width}
|
|
||||||
height={denoiseProgress.progress_image.height}
|
|
||||||
draggable={false}
|
|
||||||
data-testid="progress-image"
|
|
||||||
sx={{
|
|
||||||
objectFit: 'contain',
|
|
||||||
maxWidth: 'full',
|
|
||||||
maxHeight: 'full',
|
|
||||||
height: 'auto',
|
|
||||||
position: 'absolute',
|
|
||||||
borderRadius: 'base',
|
|
||||||
imageRendering: shouldAntialiasProgressImage ? 'auto' : 'pixelated',
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
) : (
|
) : (
|
||||||
<IAIDndImage
|
<IAIDndImage
|
||||||
imageDTO={imageDTO}
|
imageDTO={imageDTO}
|
||||||
|
@ -0,0 +1,37 @@
|
|||||||
|
import { Image } from '@chakra-ui/react';
|
||||||
|
import { useAppSelector } from 'app/store/storeHooks';
|
||||||
|
import { memo } from 'react';
|
||||||
|
|
||||||
|
const CurrentImagePreview = () => {
|
||||||
|
const progress_image = useAppSelector(
|
||||||
|
(state) => state.system.denoiseProgress?.progress_image
|
||||||
|
);
|
||||||
|
const shouldAntialiasProgressImage = useAppSelector(
|
||||||
|
(state) => state.system.shouldAntialiasProgressImage
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!progress_image) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Image
|
||||||
|
src={progress_image.dataURL}
|
||||||
|
width={progress_image.width}
|
||||||
|
height={progress_image.height}
|
||||||
|
draggable={false}
|
||||||
|
data-testid="progress-image"
|
||||||
|
sx={{
|
||||||
|
objectFit: 'contain',
|
||||||
|
maxWidth: 'full',
|
||||||
|
maxHeight: 'full',
|
||||||
|
height: 'auto',
|
||||||
|
position: 'absolute',
|
||||||
|
borderRadius: 'base',
|
||||||
|
imageRendering: shouldAntialiasProgressImage ? 'auto' : 'pixelated',
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default memo(CurrentImagePreview);
|
@ -38,7 +38,6 @@ import {
|
|||||||
setShouldShowProgressInViewer,
|
setShouldShowProgressInViewer,
|
||||||
setShouldUseSliders,
|
setShouldUseSliders,
|
||||||
} from 'features/ui/store/uiSlice';
|
} from 'features/ui/store/uiSlice';
|
||||||
import { isEqual } from 'lodash-es';
|
|
||||||
import {
|
import {
|
||||||
ChangeEvent,
|
ChangeEvent,
|
||||||
ReactElement,
|
ReactElement,
|
||||||
@ -56,9 +55,7 @@ import SettingsClearIntermediates from './SettingsClearIntermediates';
|
|||||||
import SettingsSchedulers from './SettingsSchedulers';
|
import SettingsSchedulers from './SettingsSchedulers';
|
||||||
import StyledFlex from './StyledFlex';
|
import StyledFlex from './StyledFlex';
|
||||||
|
|
||||||
const selector = createMemoizedSelector(
|
const selector = createMemoizedSelector([stateSelector], ({ system, ui }) => {
|
||||||
[stateSelector],
|
|
||||||
({ system, ui }) => {
|
|
||||||
const {
|
const {
|
||||||
shouldConfirmOnDelete,
|
shouldConfirmOnDelete,
|
||||||
enableImageDebugging,
|
enableImageDebugging,
|
||||||
@ -89,11 +86,7 @@ const selector = createMemoizedSelector(
|
|||||||
shouldAutoChangeDimensions,
|
shouldAutoChangeDimensions,
|
||||||
shouldEnableInformationalPopovers,
|
shouldEnableInformationalPopovers,
|
||||||
};
|
};
|
||||||
},
|
});
|
||||||
{
|
|
||||||
memoizeOptions: { resultEqualityCheck: isEqual },
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
type ConfigOptions = {
|
type ConfigOptions = {
|
||||||
shouldShowDeveloperSettings: boolean;
|
shouldShowDeveloperSettings: boolean;
|
||||||
|
@ -23,7 +23,6 @@ import {
|
|||||||
} from 'features/ui/store/uiSelectors';
|
} from 'features/ui/store/uiSelectors';
|
||||||
import { setActiveTab } from 'features/ui/store/uiSlice';
|
import { setActiveTab } from 'features/ui/store/uiSlice';
|
||||||
import { ResourceKey } from 'i18next';
|
import { ResourceKey } from 'i18next';
|
||||||
import { isEqual } from 'lodash-es';
|
|
||||||
import { MouseEvent, ReactNode, memo, useCallback, useMemo } from 'react';
|
import { MouseEvent, ReactNode, memo, useCallback, useMemo } from 'react';
|
||||||
import { useHotkeys } from 'react-hotkeys-hook';
|
import { useHotkeys } from 'react-hotkeys-hook';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
@ -96,9 +95,6 @@ const enabledTabsSelector = createMemoizedSelector(
|
|||||||
const { disabledTabs } = config;
|
const { disabledTabs } = config;
|
||||||
const enabledTabs = tabs.filter((tab) => !disabledTabs.includes(tab.id));
|
const enabledTabs = tabs.filter((tab) => !disabledTabs.includes(tab.id));
|
||||||
return enabledTabs;
|
return enabledTabs;
|
||||||
},
|
|
||||||
{
|
|
||||||
memoizeOptions: { resultEqualityCheck: isEqual },
|
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user