@@ -2,13 +2,14 @@ import { Box, Flex, forwardRef, Grid, GridItem, Spinner, Text } from '@invoke-ai
2
2
import { createSelector } from '@reduxjs/toolkit' ;
3
3
import { logger } from 'app/logging/logger' ;
4
4
import { useAppSelector , useAppStore } from 'app/store/storeHooks' ;
5
- import { getFocusedRegion } from 'common/hooks/focus' ;
5
+ import { getFocusedRegion , useIsRegionFocused } from 'common/hooks/focus' ;
6
6
import { useRangeBasedImageFetching } from 'features/gallery/hooks/useRangeBasedImageFetching' ;
7
7
import type { selectGetImageNamesQueryArgs } from 'features/gallery/store/gallerySelectors' ;
8
8
import {
9
9
selectGalleryImageMinimumWidth ,
10
10
selectImageToCompare ,
11
11
selectLastSelectedImage ,
12
+ selectSelectionCount ,
12
13
} from 'features/gallery/store/gallerySelectors' ;
13
14
import { imageToCompareChanged , selectionChanged } from 'features/gallery/store/gallerySlice' ;
14
15
import { useRegisteredHotkeys } from 'features/system/components/HotkeysModal/useHotkeyData' ;
@@ -450,23 +451,10 @@ const useScrollableGallery = (rootRef: RefObject<HTMLDivElement>) => {
450
451
return scrollerRef ;
451
452
} ;
452
453
453
- export const NewGallery = memo ( ( ) => {
454
- const virtuosoRef = useRef < VirtuosoGridHandle > ( null ) ;
455
- const rangeRef = useRef < ListRange > ( { startIndex : 0 , endIndex : 0 } ) ;
456
- const rootRef = useRef < HTMLDivElement > ( null ) ;
457
-
458
- // Get the ordered list of image names - this is our primary data source for virtualization
459
- const { queryArgs, imageNames, isLoading } = useGalleryImageNames ( ) ;
460
-
461
- // Use range-based fetching for bulk loading image DTOs into cache based on the visible range
462
- const { onRangeChanged } = useRangeBasedImageFetching ( {
463
- imageNames,
464
- enabled : ! isLoading ,
465
- } ) ;
466
-
454
+ const useStarImageHotkey = ( ) => {
467
455
const lastSelectedImage = useAppSelector ( selectLastSelectedImage ) ;
468
- const selectionCount = useAppSelector ( ( state ) => state . gallery . selection . length ) ;
469
- const isGalleryFocused = getFocusedRegion ( ) === 'gallery' ;
456
+ const selectionCount = useAppSelector ( selectSelectionCount ) ;
457
+ const isGalleryFocused = useIsRegionFocused ( 'gallery' ) ;
470
458
const imageDTO = useImageDTO ( lastSelectedImage ) ;
471
459
const [ starImages ] = useStarImagesMutation ( ) ;
472
460
const [ unstarImages ] = useUnstarImagesMutation ( ) ;
@@ -475,12 +463,15 @@ export const NewGallery = memo(() => {
475
463
if ( ! imageDTO ) {
476
464
return ;
477
465
}
466
+ if ( ! isGalleryFocused ) {
467
+ return ;
468
+ }
478
469
if ( imageDTO . starred ) {
479
470
unstarImages ( { image_names : [ imageDTO . image_name ] } ) ;
480
471
} else {
481
472
starImages ( { image_names : [ imageDTO . image_name ] } ) ;
482
473
}
483
- } , [ imageDTO , starImages , unstarImages ] ) ;
474
+ } , [ imageDTO , isGalleryFocused , starImages , unstarImages ] ) ;
484
475
485
476
useRegisteredHotkeys ( {
486
477
id : 'starImage' ,
@@ -489,7 +480,23 @@ export const NewGallery = memo(() => {
489
480
options : { enabled : ! ! imageDTO && selectionCount === 1 && isGalleryFocused } ,
490
481
dependencies : [ imageDTO , selectionCount , isGalleryFocused , handleStarHotkey ] ,
491
482
} ) ;
483
+ } ;
484
+
485
+ export const NewGallery = memo ( ( ) => {
486
+ const virtuosoRef = useRef < VirtuosoGridHandle > ( null ) ;
487
+ const rangeRef = useRef < ListRange > ( { startIndex : 0 , endIndex : 0 } ) ;
488
+ const rootRef = useRef < HTMLDivElement > ( null ) ;
489
+
490
+ // Get the ordered list of image names - this is our primary data source for virtualization
491
+ const { queryArgs, imageNames, isLoading } = useGalleryImageNames ( ) ;
492
+
493
+ // Use range-based fetching for bulk loading image DTOs into cache based on the visible range
494
+ const { onRangeChanged } = useRangeBasedImageFetching ( {
495
+ imageNames,
496
+ enabled : ! isLoading ,
497
+ } ) ;
492
498
499
+ useStarImageHotkey ( ) ;
493
500
useKeepSelectedImageInView ( imageNames , virtuosoRef , rootRef , rangeRef ) ;
494
501
useKeyboardNavigation ( imageNames , virtuosoRef , rootRef ) ;
495
502
const scrollerRef = useScrollableGallery ( rootRef ) ;
0 commit comments