mirror of
https://github.com/invoke-ai/InvokeAI
synced 2024-08-30 20:32:17 +00:00
refactor(ui): fix gallery stuff
This commit is contained in:
parent
5e1a6ae334
commit
7ccc5ba398
@ -4,23 +4,18 @@ import { $customStarUI } from 'app/store/nanostores/customStarUI';
|
|||||||
import { useAppDispatch, useAppSelector } from 'app/store/storeHooks';
|
import { useAppDispatch, useAppSelector } from 'app/store/storeHooks';
|
||||||
import { useCopyImageToClipboard } from 'common/hooks/useCopyImageToClipboard';
|
import { useCopyImageToClipboard } from 'common/hooks/useCopyImageToClipboard';
|
||||||
import { useDownloadImage } from 'common/hooks/useDownloadImage';
|
import { useDownloadImage } from 'common/hooks/useDownloadImage';
|
||||||
import { setInitialCanvasImage } from 'features/canvas/store/canvasSlice';
|
|
||||||
import { imagesToChangeSelected, isModalOpenChanged } from 'features/changeBoardModal/store/slice';
|
import { imagesToChangeSelected, isModalOpenChanged } from 'features/changeBoardModal/store/slice';
|
||||||
import { iiLayerAdded } from 'features/controlLayers/store/canvasV2Slice';
|
|
||||||
import { selectOptimalDimension } from 'features/controlLayers/store/selectors';
|
|
||||||
import { imagesToDeleteSelected } from 'features/deleteImageModal/store/slice';
|
import { imagesToDeleteSelected } from 'features/deleteImageModal/store/slice';
|
||||||
import { useImageActions } from 'features/gallery/hooks/useImageActions';
|
import { useImageActions } from 'features/gallery/hooks/useImageActions';
|
||||||
import { sentImageToCanvas, sentImageToImg2Img } from 'features/gallery/store/actions';
|
import { sentImageToCanvas, sentImageToImg2Img } from 'features/gallery/store/actions';
|
||||||
import { imageToCompareChanged } from 'features/gallery/store/gallerySlice';
|
import { imageToCompareChanged } from 'features/gallery/store/gallerySlice';
|
||||||
import { $templates } from 'features/nodes/store/nodesSlice';
|
import { $templates } from 'features/nodes/store/nodesSlice';
|
||||||
import { selectOptimalDimension } from 'features/parameters/store/generationSlice';
|
|
||||||
import { upscaleInitialImageChanged } from 'features/parameters/store/upscaleSlice';
|
import { upscaleInitialImageChanged } from 'features/parameters/store/upscaleSlice';
|
||||||
import { toast } from 'features/toast/toast';
|
import { toast } from 'features/toast/toast';
|
||||||
import { setActiveTab } from 'features/ui/store/uiSlice';
|
import { setActiveTab } from 'features/ui/store/uiSlice';
|
||||||
import { useGetAndLoadEmbeddedWorkflow } from 'features/workflowLibrary/hooks/useGetAndLoadEmbeddedWorkflow';
|
import { useGetAndLoadEmbeddedWorkflow } from 'features/workflowLibrary/hooks/useGetAndLoadEmbeddedWorkflow';
|
||||||
import { size } from 'lodash-es';
|
import { size } from 'lodash-es';
|
||||||
import { memo, useCallback } from 'react';
|
import { memo, useCallback } from 'react';
|
||||||
import { flushSync } from 'react-dom';
|
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
import {
|
import {
|
||||||
PiArrowsCounterClockwiseBold,
|
PiArrowsCounterClockwiseBold,
|
||||||
@ -47,7 +42,6 @@ type SingleSelectionMenuItemsProps = {
|
|||||||
|
|
||||||
const SingleSelectionMenuItems = (props: SingleSelectionMenuItemsProps) => {
|
const SingleSelectionMenuItems = (props: SingleSelectionMenuItemsProps) => {
|
||||||
const { imageDTO } = props;
|
const { imageDTO } = props;
|
||||||
const optimalDimension = useAppSelector(selectOptimalDimension);
|
|
||||||
const maySelectForCompare = useAppSelector((s) => s.gallery.imageToCompare?.image_name !== imageDTO.image_name);
|
const maySelectForCompare = useAppSelector((s) => s.gallery.imageToCompare?.image_name !== imageDTO.image_name);
|
||||||
const dispatch = useAppDispatch();
|
const dispatch = useAppDispatch();
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
@ -86,24 +80,21 @@ const SingleSelectionMenuItems = (props: SingleSelectionMenuItemsProps) => {
|
|||||||
}, [dispatch, imageDTO]);
|
}, [dispatch, imageDTO]);
|
||||||
|
|
||||||
const handleSendToImageToImage = useCallback(() => {
|
const handleSendToImageToImage = useCallback(() => {
|
||||||
|
// TODO(psyche): restore send to img2img functionality
|
||||||
dispatch(sentImageToImg2Img());
|
dispatch(sentImageToImg2Img());
|
||||||
dispatch(iiLayerAdded(imageDTO));
|
|
||||||
dispatch(setActiveTab('generation'));
|
dispatch(setActiveTab('generation'));
|
||||||
}, [dispatch, imageDTO]);
|
}, [dispatch]);
|
||||||
|
|
||||||
const handleSendToCanvas = useCallback(() => {
|
const handleSendToCanvas = useCallback(() => {
|
||||||
|
// TODO(psyche): restore send to canvas functionality
|
||||||
dispatch(sentImageToCanvas());
|
dispatch(sentImageToCanvas());
|
||||||
flushSync(() => {
|
dispatch(setActiveTab('generation'));
|
||||||
dispatch(setActiveTab('canvas'));
|
|
||||||
});
|
|
||||||
dispatch(setInitialCanvasImage(imageDTO, optimalDimension));
|
|
||||||
|
|
||||||
toast({
|
toast({
|
||||||
id: 'SENT_TO_CANVAS',
|
id: 'SENT_TO_CANVAS',
|
||||||
title: t('toast.sentToUnifiedCanvas'),
|
title: t('toast.sentToUnifiedCanvas'),
|
||||||
status: 'success',
|
status: 'success',
|
||||||
});
|
});
|
||||||
}, [dispatch, imageDTO, t, optimalDimension]);
|
}, [dispatch, t]);
|
||||||
|
|
||||||
const handleChangeBoard = useCallback(() => {
|
const handleChangeBoard = useCallback(() => {
|
||||||
dispatch(imagesToChangeSelected([imageDTO]));
|
dispatch(imagesToChangeSelected([imageDTO]));
|
||||||
@ -202,14 +193,12 @@ const SingleSelectionMenuItems = (props: SingleSelectionMenuItemsProps) => {
|
|||||||
<MenuItem icon={<PiShareFatBold />} onClickCapture={handleSendToImageToImage} id="send-to-img2img">
|
<MenuItem icon={<PiShareFatBold />} onClickCapture={handleSendToImageToImage} id="send-to-img2img">
|
||||||
{t('parameters.sendToImg2Img')}
|
{t('parameters.sendToImg2Img')}
|
||||||
</MenuItem>
|
</MenuItem>
|
||||||
{isCanvasEnabled && (
|
|
||||||
<MenuItem icon={<PiShareFatBold />} onClickCapture={handleSendToCanvas} id="send-to-canvas">
|
|
||||||
{t('parameters.sendToUnifiedCanvas')}
|
|
||||||
</MenuItem>
|
|
||||||
)}
|
|
||||||
<MenuItem icon={<PiShareFatBold />} onClickCapture={handleSendToUpscale} id="send-to-upscale">
|
<MenuItem icon={<PiShareFatBold />} onClickCapture={handleSendToUpscale} id="send-to-upscale">
|
||||||
{t('parameters.sendToUpscale')}
|
{t('parameters.sendToUpscale')}
|
||||||
</MenuItem>
|
</MenuItem>
|
||||||
|
<MenuItem icon={<PiShareFatBold />} onClickCapture={handleSendToCanvas} id="send-to-canvas">
|
||||||
|
{t('parameters.sendToUnifiedCanvas')}
|
||||||
|
</MenuItem>
|
||||||
<MenuDivider />
|
<MenuDivider />
|
||||||
<MenuItem icon={<PiFoldersBold />} onClickCapture={handleChangeBoard}>
|
<MenuItem icon={<PiFoldersBold />} onClickCapture={handleChangeBoard}>
|
||||||
{t('boards.changeBoard')}
|
{t('boards.changeBoard')}
|
||||||
|
@ -4,7 +4,6 @@ import { createSelector } from '@reduxjs/toolkit';
|
|||||||
import { skipToken } from '@reduxjs/toolkit/query';
|
import { skipToken } from '@reduxjs/toolkit/query';
|
||||||
import { adHocPostProcessingRequested } from 'app/store/middleware/listenerMiddleware/listeners/addAdHocPostProcessingRequestedListener';
|
import { adHocPostProcessingRequested } from 'app/store/middleware/listenerMiddleware/listeners/addAdHocPostProcessingRequestedListener';
|
||||||
import { useAppDispatch, useAppSelector } from 'app/store/storeHooks';
|
import { useAppDispatch, useAppSelector } from 'app/store/storeHooks';
|
||||||
import { iiLayerAdded } from 'features/controlLayers/store/canvasV2Slice';
|
|
||||||
import { DeleteImageButton } from 'features/deleteImageModal/components/DeleteImageButton';
|
import { DeleteImageButton } from 'features/deleteImageModal/components/DeleteImageButton';
|
||||||
import { imagesToDeleteSelected } from 'features/deleteImageModal/store/slice';
|
import { imagesToDeleteSelected } from 'features/deleteImageModal/store/slice';
|
||||||
import SingleSelectionMenuItems from 'features/gallery/components/ImageContextMenu/SingleSelectionMenuItems';
|
import SingleSelectionMenuItems from 'features/gallery/components/ImageContextMenu/SingleSelectionMenuItems';
|
||||||
@ -86,8 +85,8 @@ const CurrentImageButtons = () => {
|
|||||||
if (!imageDTO) {
|
if (!imageDTO) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
// TODO(psyche): restore send to img2img functionality
|
||||||
dispatch(sentImageToImg2Img());
|
dispatch(sentImageToImg2Img());
|
||||||
dispatch(iiLayerAdded(imageDTO));
|
|
||||||
dispatch(setActiveTab('generation'));
|
dispatch(setActiveTab('generation'));
|
||||||
}, [dispatch, imageDTO]);
|
}, [dispatch, imageDTO]);
|
||||||
|
|
||||||
|
@ -1,10 +1,7 @@
|
|||||||
import { useAppSelector } from 'app/store/storeHooks';
|
import { useAppSelector } from 'app/store/storeHooks';
|
||||||
import { isStagingSelector } from 'features/canvas/store/canvasSelectors';
|
|
||||||
import { useGalleryNavigation } from 'features/gallery/hooks/useGalleryNavigation';
|
import { useGalleryNavigation } from 'features/gallery/hooks/useGalleryNavigation';
|
||||||
import { useGalleryPagination } from 'features/gallery/hooks/useGalleryPagination';
|
import { useGalleryPagination } from 'features/gallery/hooks/useGalleryPagination';
|
||||||
import { selectListImagesQueryArgs } from 'features/gallery/store/gallerySelectors';
|
import { selectListImagesQueryArgs } from 'features/gallery/store/gallerySelectors';
|
||||||
import { activeTabNameSelector } from 'features/ui/store/uiSelectors';
|
|
||||||
import { useMemo } from 'react';
|
|
||||||
import { useHotkeys } from 'react-hotkeys-hook';
|
import { useHotkeys } from 'react-hotkeys-hook';
|
||||||
import { useListImagesQuery } from 'services/api/endpoints/images';
|
import { useListImagesQuery } from 'services/api/endpoints/images';
|
||||||
|
|
||||||
@ -12,12 +9,7 @@ import { useListImagesQuery } from 'services/api/endpoints/images';
|
|||||||
* Registers gallery hotkeys. This hook is a singleton.
|
* Registers gallery hotkeys. This hook is a singleton.
|
||||||
*/
|
*/
|
||||||
export const useGalleryHotkeys = () => {
|
export const useGalleryHotkeys = () => {
|
||||||
const activeTabName = useAppSelector(activeTabNameSelector);
|
// TODO(psyche): Hotkeys when staging - cannot navigate gallery with arrow keys when staging!
|
||||||
const isStaging = useAppSelector(isStagingSelector);
|
|
||||||
// block navigation on Unified Canvas tab when staging new images
|
|
||||||
const canNavigateGallery = useMemo(() => {
|
|
||||||
return activeTabName !== 'canvas' || !isStaging;
|
|
||||||
}, [activeTabName, isStaging]);
|
|
||||||
|
|
||||||
const { goNext, goPrev, isNextEnabled, isPrevEnabled } = useGalleryPagination();
|
const { goNext, goPrev, isNextEnabled, isPrevEnabled } = useGalleryPagination();
|
||||||
const queryArgs = useAppSelector(selectListImagesQueryArgs);
|
const queryArgs = useAppSelector(selectListImagesQueryArgs);
|
||||||
@ -41,17 +33,14 @@ export const useGalleryHotkeys = () => {
|
|||||||
goPrev(e.altKey ? 'alt+arrow' : 'arrow');
|
goPrev(e.altKey ? 'alt+arrow' : 'arrow');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
canNavigateGallery && handleLeftImage(e.altKey);
|
handleLeftImage(e.altKey);
|
||||||
},
|
},
|
||||||
[handleLeftImage, canNavigateGallery, isOnFirstImageOfView, goPrev, isPrevEnabled, queryResult.isFetching]
|
[handleLeftImage, isOnFirstImageOfView, goPrev, isPrevEnabled, queryResult.isFetching]
|
||||||
);
|
);
|
||||||
|
|
||||||
useHotkeys(
|
useHotkeys(
|
||||||
['right', 'alt+right'],
|
['right', 'alt+right'],
|
||||||
(e) => {
|
(e) => {
|
||||||
if (!canNavigateGallery) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (isOnLastImageOfView && isNextEnabled && !queryResult.isFetching) {
|
if (isOnLastImageOfView && isNextEnabled && !queryResult.isFetching) {
|
||||||
goNext(e.altKey ? 'alt+arrow' : 'arrow');
|
goNext(e.altKey ? 'alt+arrow' : 'arrow');
|
||||||
return;
|
return;
|
||||||
@ -60,7 +49,7 @@ export const useGalleryHotkeys = () => {
|
|||||||
handleRightImage(e.altKey);
|
handleRightImage(e.altKey);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
[isOnLastImageOfView, goNext, isNextEnabled, queryResult.isFetching, handleRightImage, canNavigateGallery]
|
[isOnLastImageOfView, goNext, isNextEnabled, queryResult.isFetching, handleRightImage]
|
||||||
);
|
);
|
||||||
|
|
||||||
useHotkeys(
|
useHotkeys(
|
||||||
|
Loading…
Reference in New Issue
Block a user