From 908aa9beea395c1694423269f8214eaa014fc6da Mon Sep 17 00:00:00 2001 From: psychedelicious <4822129+psychedelicious@users.noreply.github.com> Date: Sat, 15 Jun 2024 20:24:00 +1000 Subject: [PATCH] refactor(ui): canvas v2 (wip) delete unused file --- .../ControlAdapter/CAOpacityAndFilter.tsx | 7 +- .../controlLayers/hooks/layerStateHooks.ts | 79 ------------------- 2 files changed, 4 insertions(+), 82 deletions(-) delete mode 100644 invokeai/frontend/web/src/features/controlLayers/hooks/layerStateHooks.ts diff --git a/invokeai/frontend/web/src/features/controlLayers/components/ControlAdapter/CAOpacityAndFilter.tsx b/invokeai/frontend/web/src/features/controlLayers/components/ControlAdapter/CAOpacityAndFilter.tsx index ce4e918f52..f6bfbdf6f8 100644 --- a/invokeai/frontend/web/src/features/controlLayers/components/ControlAdapter/CAOpacityAndFilter.tsx +++ b/invokeai/frontend/web/src/features/controlLayers/components/ControlAdapter/CAOpacityAndFilter.tsx @@ -12,10 +12,10 @@ import { PopoverTrigger, Switch, } from '@invoke-ai/ui-library'; -import { useAppDispatch } from 'app/store/storeHooks'; +import { useAppDispatch, useAppSelector } from 'app/store/storeHooks'; import { stopPropagation } from 'common/util/stopPropagation'; -import { useCALayerOpacity } from 'features/controlLayers/hooks/layerStateHooks'; import { caFilterChanged, caOpacityChanged } from 'features/controlLayers/store/canvasV2Slice'; +import { selectCAOrThrow } from 'features/controlLayers/store/controlAdaptersReducers'; import type { ChangeEvent } from 'react'; import { memo, useCallback } from 'react'; import { useTranslation } from 'react-i18next'; @@ -31,7 +31,8 @@ const formatPct = (v: number | string) => `${v} %`; export const CAOpacityAndFilter = memo(({ id }: Props) => { const { t } = useTranslation(); const dispatch = useAppDispatch(); - const { opacity, isFilterEnabled } = useCALayerOpacity(id); + const opacity = useAppSelector((s) => Math.round(selectCAOrThrow(s.canvasV2, id).opacity * 100)); + const isFilterEnabled = useAppSelector((s) => selectCAOrThrow(s.canvasV2, id).filter === 'LightnessToAlphaFilter'); const onChangeOpacity = useCallback( (v: number) => { dispatch(caOpacityChanged({ id, opacity: v / 100 })); diff --git a/invokeai/frontend/web/src/features/controlLayers/hooks/layerStateHooks.ts b/invokeai/frontend/web/src/features/controlLayers/hooks/layerStateHooks.ts deleted file mode 100644 index 28f6af7ea4..0000000000 --- a/invokeai/frontend/web/src/features/controlLayers/hooks/layerStateHooks.ts +++ /dev/null @@ -1,79 +0,0 @@ -import { createSelector } from '@reduxjs/toolkit'; -import { createMemoizedSelector } from 'app/store/createMemoizedSelector'; -import { useAppSelector } from 'app/store/storeHooks'; -import { selectCanvasV2Slice } from 'features/controlLayers/store/canvasV2Slice'; -import { isControlAdapterLayer, isRegionalGuidanceLayer } from 'features/controlLayers/store/types'; -import { useMemo } from 'react'; -import { assert } from 'tsafe'; - -export const useLayerPositivePrompt = (layerId: string) => { - const selectLayer = useMemo( - () => - createSelector(selectCanvasV2Slice, (controlLayers) => { - const layer = canvasV2.layers.find((l) => l.id === layerId); - assert(isRegionalGuidanceLayer(layer), `Layer ${layerId} not found or not an RP layer`); - assert(layer.positivePrompt !== null, `Layer ${layerId} does not have a positive prompt`); - return layer.positivePrompt; - }), - [layerId] - ); - const prompt = useAppSelector(selectLayer); - return prompt; -}; - -export const useLayerNegativePrompt = (layerId: string) => { - const selectLayer = useMemo( - () => - createSelector(selectCanvasV2Slice, (controlLayers) => { - const layer = canvasV2.layers.find((l) => l.id === layerId); - assert(isRegionalGuidanceLayer(layer), `Layer ${layerId} not found or not an RP layer`); - assert(layer.negativePrompt !== null, `Layer ${layerId} does not have a negative prompt`); - return layer.negativePrompt; - }), - [layerId] - ); - const prompt = useAppSelector(selectLayer); - return prompt; -}; - -export const useLayerIsEnabled = (layerId: string) => { - const selectLayer = useMemo( - () => - createSelector(selectCanvasV2Slice, (controlLayers) => { - const layer = canvasV2.layers.find((l) => l.id === layerId); - assert(layer, `Layer ${layerId} not found`); - return layer.isEnabled; - }), - [layerId] - ); - const isVisible = useAppSelector(selectLayer); - return isVisible; -}; - -export const useLayerType = (layerId: string) => { - const selectLayer = useMemo( - () => - createSelector(selectCanvasV2Slice, (controlLayers) => { - const layer = canvasV2.layers.find((l) => l.id === layerId); - assert(layer, `Layer ${layerId} not found`); - return layer.type; - }), - [layerId] - ); - const type = useAppSelector(selectLayer); - return type; -}; - -export const useCALayerOpacity = (layerId: string) => { - const selectLayer = useMemo( - () => - createMemoizedSelector(selectCanvasV2Slice, (controlLayers) => { - const layer = canvasV2.layers.filter(isControlAdapterLayer).find((l) => l.id === layerId); - assert(layer, `Layer ${layerId} not found`); - return { opacity: Math.round(layer.opacity * 100), isFilterEnabled: layer.isFilterEnabled }; - }), - [layerId] - ); - const opacity = useAppSelector(selectLayer); - return opacity; -};