mirror of
https://github.com/invoke-ai/InvokeAI
synced 2024-08-30 20:32:17 +00:00
refactor(ui): canvas v2 (wip)
delete unused file
This commit is contained in:
parent
4071e96245
commit
908aa9beea
@ -12,10 +12,10 @@ import {
|
|||||||
PopoverTrigger,
|
PopoverTrigger,
|
||||||
Switch,
|
Switch,
|
||||||
} from '@invoke-ai/ui-library';
|
} 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 { stopPropagation } from 'common/util/stopPropagation';
|
||||||
import { useCALayerOpacity } from 'features/controlLayers/hooks/layerStateHooks';
|
|
||||||
import { caFilterChanged, caOpacityChanged } from 'features/controlLayers/store/canvasV2Slice';
|
import { caFilterChanged, caOpacityChanged } from 'features/controlLayers/store/canvasV2Slice';
|
||||||
|
import { selectCAOrThrow } from 'features/controlLayers/store/controlAdaptersReducers';
|
||||||
import type { ChangeEvent } from 'react';
|
import type { ChangeEvent } from 'react';
|
||||||
import { memo, useCallback } from 'react';
|
import { memo, useCallback } from 'react';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
@ -31,7 +31,8 @@ const formatPct = (v: number | string) => `${v} %`;
|
|||||||
export const CAOpacityAndFilter = memo(({ id }: Props) => {
|
export const CAOpacityAndFilter = memo(({ id }: Props) => {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const dispatch = useAppDispatch();
|
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(
|
const onChangeOpacity = useCallback(
|
||||||
(v: number) => {
|
(v: number) => {
|
||||||
dispatch(caOpacityChanged({ id, opacity: v / 100 }));
|
dispatch(caOpacityChanged({ id, opacity: v / 100 }));
|
||||||
|
@ -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;
|
|
||||||
};
|
|
Loading…
Reference in New Issue
Block a user