Skip to content

Commit c957f4b

Browse files
feat(ui): use new uncategorized image counts & updated list boards queries
1 parent 924ad3b commit c957f4b

File tree

5 files changed

+32
-24
lines changed

5 files changed

+32
-24
lines changed
Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,12 @@
11
import { useTranslation } from 'react-i18next';
2-
import { useGetBoardAssetsTotalQuery, useGetBoardImagesTotalQuery } from 'services/api/endpoints/boards';
32

43
type Props = {
5-
board_id: string;
4+
imageCount: number;
5+
assetCount: number;
66
isArchived: boolean;
77
};
88

9-
export const BoardTotalsTooltip = ({ board_id, isArchived }: Props) => {
9+
export const BoardTotalsTooltip = ({ imageCount, assetCount, isArchived }: Props) => {
1010
const { t } = useTranslation();
11-
const { imagesTotal } = useGetBoardImagesTotalQuery(board_id, {
12-
selectFromResult: ({ data }) => {
13-
return { imagesTotal: data?.total ?? 0 };
14-
},
15-
});
16-
const { assetsTotal } = useGetBoardAssetsTotalQuery(board_id, {
17-
selectFromResult: ({ data }) => {
18-
return { assetsTotal: data?.total ?? 0 };
19-
},
20-
});
21-
return `${t('boards.imagesWithCount', { count: imagesTotal })}, ${t('boards.assetsWithCount', { count: assetsTotal })}${isArchived ? ` (${t('boards.archived')})` : ''}`;
11+
return `${t('boards.imagesWithCount', { count: imageCount })}, ${t('boards.assetsWithCount', { count: assetCount })}${isArchived ? ` (${t('boards.archived')})` : ''}`;
2212
};

invokeai/frontend/web/src/features/gallery/components/Boards/BoardsList/GalleryBoard.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,13 @@ const GalleryBoard = ({ board, isSelected, setBoardToDelete }: GalleryBoardProps
116116
<BoardContextMenu board={board} setBoardToDelete={setBoardToDelete}>
117117
{(ref) => (
118118
<Tooltip
119-
label={<BoardTotalsTooltip board_id={board.board_id} isArchived={Boolean(board.archived)} />}
119+
label={
120+
<BoardTotalsTooltip
121+
imageCount={board.image_count}
122+
assetCount={board.asset_count}
123+
isArchived={Boolean(board.archived)}
124+
/>
125+
}
120126
openDelay={1000}
121127
placement="left"
122128
closeOnScroll
@@ -166,7 +172,7 @@ const GalleryBoard = ({ board, isSelected, setBoardToDelete }: GalleryBoardProps
166172
</Editable>
167173
{autoAddBoardId === board.board_id && !editingDisclosure.isOpen && <AutoAddBadge />}
168174
{board.archived && !editingDisclosure.isOpen && <Icon as={PiArchiveBold} fill="base.300" />}
169-
{!editingDisclosure.isOpen && <Text variant="subtext">{board.image_count}</Text>}
175+
{!editingDisclosure.isOpen && <Text variant="subtext">{board.image_count + board.asset_count}</Text>}
170176

171177
<IAIDroppable data={droppableData} dropLabel={<Text fontSize="md">{t('unifiedCanvas.move')}</Text>} />
172178
</Flex>

invokeai/frontend/web/src/features/gallery/components/Boards/BoardsList/NoBoardBoard.tsx

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import NoBoardBoardContextMenu from 'features/gallery/components/Boards/NoBoardB
99
import { autoAddBoardIdChanged, boardIdSelected } from 'features/gallery/store/gallerySlice';
1010
import { memo, useCallback, useMemo } from 'react';
1111
import { useTranslation } from 'react-i18next';
12-
import { useGetBoardImagesTotalQuery } from 'services/api/endpoints/boards';
12+
import { useGetUncategorizedImageCountsQuery } from 'services/api/endpoints/boards';
1313
import { useBoardName } from 'services/api/hooks/useBoardName';
1414

1515
interface Props {
@@ -22,11 +22,7 @@ const _hover: SystemStyleObject = {
2222

2323
const NoBoardBoard = memo(({ isSelected }: Props) => {
2424
const dispatch = useAppDispatch();
25-
const { imagesTotal } = useGetBoardImagesTotalQuery('none', {
26-
selectFromResult: ({ data }) => {
27-
return { imagesTotal: data?.total ?? 0 };
28-
},
29-
});
25+
const { data } = useGetUncategorizedImageCountsQuery();
3026
const autoAddBoardId = useAppSelector((s) => s.gallery.autoAddBoardId);
3127
const autoAssignBoardOnClick = useAppSelector((s) => s.gallery.autoAssignBoardOnClick);
3228
const boardSearchText = useAppSelector((s) => s.gallery.boardSearchText);
@@ -60,7 +56,13 @@ const NoBoardBoard = memo(({ isSelected }: Props) => {
6056
<NoBoardBoardContextMenu>
6157
{(ref) => (
6258
<Tooltip
63-
label={<BoardTotalsTooltip board_id="none" isArchived={false} />}
59+
label={
60+
<BoardTotalsTooltip
61+
imageCount={data?.image_count ?? 0}
62+
assetCount={data?.asset_count ?? 0}
63+
isArchived={false}
64+
/>
65+
}
6466
openDelay={1000}
6567
placement="left"
6668
closeOnScroll
@@ -99,7 +101,7 @@ const NoBoardBoard = memo(({ isSelected }: Props) => {
99101
{boardName}
100102
</Text>
101103
{autoAddBoardId === 'none' && <AutoAddBadge />}
102-
<Text variant="subtext">{imagesTotal}</Text>
104+
<Text variant="subtext">{(data?.image_count ?? 0) + (data?.asset_count ?? 0)}</Text>
103105
<IAIDroppable data={droppableData} dropLabel={<Text fontSize="md">{t('unifiedCanvas.move')}</Text>} />
104106
</Flex>
105107
</Tooltip>

invokeai/frontend/web/src/services/api/endpoints/boards.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import type {
44
CreateBoardArg,
55
ListBoardsArgs,
66
OffsetPaginatedResults_ImageDTO_,
7+
S,
78
UpdateBoardArg,
89
} from 'services/api/types';
910
import { getListImagesUrl } from 'services/api/util';
@@ -55,6 +56,13 @@ export const boardsApi = api.injectEndpoints({
5556
keepUnusedDataFor: 0,
5657
}),
5758

59+
getUncategorizedImageCounts: build.query<S['UncategorizedImageCounts'], void>({
60+
query: () => ({
61+
url: buildBoardsUrl('uncategorized/counts'),
62+
}),
63+
providesTags: ['UncategorizedImageCounts', { type: 'Board', id: LIST_TAG }, { type: 'Board', id: 'none' }],
64+
}),
65+
5866
getBoardImagesTotal: build.query<{ total: number }, string | undefined>({
5967
query: (board_id) => ({
6068
url: getListImagesUrl({
@@ -129,4 +137,5 @@ export const {
129137
useCreateBoardMutation,
130138
useUpdateBoardMutation,
131139
useListAllImageNamesForBoardQuery,
140+
useGetUncategorizedImageCountsQuery,
132141
} = boardsApi;

invokeai/frontend/web/src/services/api/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ const tagTypes = [
4444
// This is invalidated on reconnect. It should be used for queries that have changing data,
4545
// especially related to the queue and generation.
4646
'FetchOnReconnect',
47+
'UncategorizedImageCounts',
4748
] as const;
4849
export type ApiTagDescription = TagDescription<(typeof tagTypes)[number]>;
4950
export const LIST_TAG = 'LIST';

0 commit comments

Comments
 (0)