|
1 |
| -import { Flex, IconButton, Spacer, Tag, TagCloseButton, TagLabel, Tooltip } from '@invoke-ai/ui-library'; |
| 1 | +import { Tag, TagCloseButton, TagLabel } from '@invoke-ai/ui-library'; |
2 | 2 | import { useAppDispatch, useAppSelector } from 'app/store/storeHooks';
|
3 | 3 | import { useGalleryImages } from 'features/gallery/hooks/useGalleryImages';
|
4 | 4 | import { selectionChanged } from 'features/gallery/store/gallerySlice';
|
5 | 5 | import { useCallback } from 'react';
|
| 6 | +import { useHotkeys } from 'react-hotkeys-hook'; |
6 | 7 | import { useTranslation } from 'react-i18next';
|
7 |
| -import { BiSelectMultiple } from 'react-icons/bi'; |
8 | 8 |
|
9 | 9 | export const GalleryBulkSelect = () => {
|
10 | 10 | const dispatch = useAppDispatch();
|
11 | 11 | const { selection } = useAppSelector((s) => s.gallery);
|
12 | 12 | const { t } = useTranslation();
|
13 | 13 | const { imageDTOs } = useGalleryImages();
|
14 | 14 |
|
15 |
| - const onClickClearSelection = useCallback(() => { |
| 15 | + const onClearSelection = useCallback(() => { |
16 | 16 | dispatch(selectionChanged([]));
|
17 | 17 | }, [dispatch]);
|
18 | 18 |
|
19 |
| - const onClickSelectAllPage = useCallback(() => { |
20 |
| - dispatch(selectionChanged(selection.concat(imageDTOs))); |
21 |
| - }, [dispatch, imageDTOs, selection]); |
| 19 | + const onSelectPage = useCallback(() => { |
| 20 | + dispatch(selectionChanged(imageDTOs)); |
| 21 | + }, [dispatch, imageDTOs]); |
22 | 22 |
|
23 |
| - return ( |
24 |
| - <Flex alignItems="center" justifyContent="space-between"> |
25 |
| - {selection.length > 0 ? ( |
26 |
| - <Tag> |
27 |
| - <TagLabel> |
28 |
| - {selection.length} {t('common.selected')} |
29 |
| - </TagLabel> |
30 |
| - <Tooltip label="Clear selection"> |
31 |
| - <TagCloseButton onClick={onClickClearSelection} /> |
32 |
| - </Tooltip> |
33 |
| - </Tag> |
34 |
| - ) : ( |
35 |
| - <Spacer /> |
36 |
| - )} |
| 23 | + useHotkeys(['ctrl+a', 'meta+a'], onSelectPage, { preventDefault: true }, [onSelectPage]); |
| 24 | + |
| 25 | + if (selection.length <= 1) { |
| 26 | + return null; |
| 27 | + } |
37 | 28 |
|
38 |
| - <Tooltip label={t('gallery.selectAllOnPage')}> |
39 |
| - <IconButton |
40 |
| - variant="outline" |
41 |
| - size="sm" |
42 |
| - icon={<BiSelectMultiple />} |
43 |
| - aria-label="Bulk select" |
44 |
| - onClick={onClickSelectAllPage} |
45 |
| - /> |
46 |
| - </Tooltip> |
47 |
| - </Flex> |
| 29 | + return ( |
| 30 | + <Tag |
| 31 | + position="absolute" |
| 32 | + bg="invokeBlue.800" |
| 33 | + color="base.50" |
| 34 | + py={1} |
| 35 | + px={3} |
| 36 | + userSelect="none" |
| 37 | + shadow="dark-lg" |
| 38 | + fontWeight="semibold" |
| 39 | + border={1} |
| 40 | + borderStyle="solid" |
| 41 | + borderColor="whiteAlpha.300" |
| 42 | + > |
| 43 | + <TagLabel> |
| 44 | + {selection.length} {t('common.selected')} |
| 45 | + </TagLabel> |
| 46 | + <TagCloseButton onClick={onClearSelection} /> |
| 47 | + </Tag> |
48 | 48 | );
|
49 | 49 | };
|
0 commit comments