fix(ui): block gallery navigation when staging images on canvas

This commit is contained in:
Thomas Mello 2024-01-28 03:09:11 +03:00 committed by psychedelicious
parent 287d3c2b04
commit c4291f2136

View File

@ -1,11 +1,22 @@
import { useAppSelector } from 'app/store/storeHooks';
import { isStagingSelector } from 'features/canvas/store/canvasSelectors';
import { useGalleryImages } from 'features/gallery/hooks/useGalleryImages';
import { useGalleryNavigation } from 'features/gallery/hooks/useGalleryNavigation';
import { activeTabNameSelector } from 'features/ui/store/uiSelectors';
import { useMemo } from 'react';
import { useHotkeys } from 'react-hotkeys-hook';
/**
* Registers gallery hotkeys. This hook is a singleton.
*/
export const useGalleryHotkeys = () => {
const activeTabName = useAppSelector(activeTabNameSelector);
const isStaging = useAppSelector(isStagingSelector);
// block navigation on Unified Canvas tab when staging new images
const canNavigateGallery = useMemo(() => {
return activeTabName !== 'unifiedCanvas' || !isStaging;
}, [activeTabName, isStaging]);
const {
areMoreImagesAvailable,
handleLoadMoreImages,
@ -18,14 +29,17 @@ export const useGalleryHotkeys = () => {
useHotkeys(
'left',
() => {
handleLeftImage();
canNavigateGallery && handleLeftImage();
},
[handleLeftImage]
[handleLeftImage, canNavigateGallery]
);
useHotkeys(
'right',
() => {
if (!canNavigateGallery) {
return;
}
if (isOnLastImage && areMoreImagesAvailable && !isFetching) {
handleLoadMoreImages();
return;
@ -34,7 +48,7 @@ export const useGalleryHotkeys = () => {
handleRightImage();
}
},
[isOnLastImage, areMoreImagesAvailable, handleLoadMoreImages, isFetching, handleRightImage]
[isOnLastImage, areMoreImagesAvailable, handleLoadMoreImages, isFetching, handleRightImage, canNavigateGallery]
);
useHotkeys(