restore adhoc upscale button

This commit is contained in:
Mary Hipp 2024-07-18 11:01:13 -04:00 committed by psychedelicious
parent 3a2707ac02
commit 5a1ed99ca1
2 changed files with 29 additions and 7 deletions

View File

@ -11,8 +11,12 @@ import SingleSelectionMenuItems from 'features/gallery/components/ImageContextMe
import { useImageActions } from 'features/gallery/hooks/useImageActions';
import { sentImageToImg2Img } from 'features/gallery/store/actions';
import { selectLastSelectedImage } from 'features/gallery/store/gallerySelectors';
import { selectGallerySlice } from 'features/gallery/store/gallerySlice';
import { parseAndRecallImageDimensions } from 'features/metadata/util/handlers';
import { $templates } from 'features/nodes/store/nodesSlice';
import ParamUpscalePopover from 'features/parameters/components/Upscale/ParamUpscaleSettings';
import { useIsQueueMutationInProgress } from 'features/queue/hooks/useIsQueueMutationInProgress';
import { useFeatureStatus } from 'features/system/hooks/useFeatureStatus';
import { selectSystemSlice } from 'features/system/store/systemSlice';
import { setActiveTab } from 'features/ui/store/uiSlice';
import { useGetAndLoadEmbeddedWorkflow } from 'features/workflowLibrary/hooks/useGetAndLoadEmbeddedWorkflow';
@ -33,8 +37,9 @@ import { useGetImageDTOQuery } from 'services/api/endpoints/images';
const selectShouldDisableToolbarButtons = createSelector(
selectSystemSlice,
selectGallerySlice,
selectLastSelectedImage,
(system, lastSelectedImage) => {
(system, gallery, lastSelectedImage) => {
const hasProgressImage = Boolean(system.denoiseProgress?.progress_image);
return hasProgressImage || !lastSelectedImage;
}
@ -42,10 +47,13 @@ const selectShouldDisableToolbarButtons = createSelector(
const CurrentImageButtons = () => {
const dispatch = useAppDispatch();
const isConnected = useAppSelector((s) => s.system.isConnected);
const lastSelectedImage = useAppSelector(selectLastSelectedImage);
const selection = useAppSelector((s) => s.gallery.selection);
const shouldDisableToolbarButtons = useAppSelector(selectShouldDisableToolbarButtons);
const templates = useStore($templates);
const isUpscalingEnabled = useFeatureStatus('upscaling');
const isQueueMutationInProgress = useIsQueueMutationInProgress();
const { t } = useTranslation();
const { currentData: imageDTO } = useGetImageDTOQuery(lastSelectedImage?.image_name ?? skipToken);
@ -99,6 +107,17 @@ const CurrentImageButtons = () => {
dispatch(imagesToDeleteSelected(selection));
}, [dispatch, imageDTO, selection]);
useHotkeys(
'Shift+U',
() => {
handleClickUpscale();
},
{
enabled: () => Boolean(isUpscalingEnabled && !shouldDisableToolbarButtons && isConnected),
},
[isUpscalingEnabled, imageDTO, shouldDisableToolbarButtons, isConnected]
);
useHotkeys(
'delete',
() => {
@ -172,6 +191,12 @@ const CurrentImageButtons = () => {
/>
</ButtonGroup>
{isUpscalingEnabled && (
<ButtonGroup isDisabled={isQueueMutationInProgress}>
{isUpscalingEnabled && <ParamUpscalePopover imageDTO={imageDTO} />}
</ButtonGroup>
)}
<ButtonGroup>
<DeleteImageButton onClick={handleDelete} />
</ButtonGroup>

View File

@ -17,8 +17,7 @@ import { useTranslation } from 'react-i18next';
import { PiFrameCornersBold } from 'react-icons/pi';
import type { ImageDTO } from 'services/api/types';
import ParamSpandrelModel from './ParamSpandrelModel';
import { useSpandrelImageToImageModels } from '../../../../services/api/hooks/modelsByType';
import ParamESRGANModel from './ParamRealESRGANModel';
type Props = { imageDTO?: ImageDTO };
@ -29,7 +28,6 @@ const ParamUpscalePopover = (props: Props) => {
const { t } = useTranslation();
const { isOpen, onOpen, onClose } = useDisclosure();
const { isAllowedToUpscale, detail } = useIsAllowedToUpscale(imageDTO);
const [modelConfigs] = useSpandrelImageToImageModels();
const handleClickUpscale = useCallback(() => {
onClose();
@ -47,17 +45,16 @@ const ParamUpscalePopover = (props: Props) => {
onClick={onOpen}
icon={<PiFrameCornersBold />}
aria-label={t('parameters.upscale')}
isDisabled={!modelConfigs.length}
/>
</PopoverTrigger>
<PopoverContent>
<PopoverBody minW={96}>
<Flex flexDirection="column" gap={4}>
<ParamSpandrelModel />
<ParamESRGANModel />
<Button
tooltip={detail}
size="sm"
isDisabled={!imageDTO || inProgress || !isAllowedToUpscale || !modelConfigs.length}
isDisabled={!imageDTO || inProgress || !isAllowedToUpscale}
onClick={handleClickUpscale}
>
{t('parameters.upscaleImage')}