Skip to content

Invoke is a leading creative engine that uses image and video generation models to empower professionals, artists, and enthusiasts to generate and create visual media using the latest AI-driven technologies. The solution offers an industry-leading application interface, and serves as the foundation for multiple commercial products.

refactor(gallery): share the thumbnail shell and report upload results

Josh Corbett03594c2d8e65
diff --git a/invokeai/frontend/webv2/src/app/GalleryUiAdapter.tsx b/invokeai/frontend/webv2/src/app/GalleryUiAdapter.tsx
index 459d9683da..4c4f25f7c4 100644
--- a/invokeai/frontend/webv2/src/app/GalleryUiAdapter.tsx
+++ b/invokeai/frontend/webv2/src/app/GalleryUiAdapter.tsx
@@ -5,6 +5,7 @@ import { GalleryUiProvider } from '@features/gallery/react';
import { useActiveProgressTarget } from '@features/queue/react';
import { useMountEffect } from '@platform/react/useMountEffect';
import { useExportLibraryProject } from '@workbench/projects/useProjectFileActions';
+import { useOpenWorkbenchWidget } from '@workbench/useOpenWorkbenchWidget';
import { getProjectWidgetValues } from '@workbench/widgetState';
import {
useActiveProjectId,
@@ -39,6 +40,7 @@ export const GalleryUiAdapterProvider = ({ children }: { children: ReactNode })
const liveProgressTarget = useActiveProgressTarget();
const { account, gallery, notifications, widgets } = useWorkbenchCommands();
const exportProject = useExportLibraryProject();
+ const openWorkbenchWidget = useOpenWorkbenchWidget();
// These are `lazy()` children of an adapter that only ever mounts in the
// editor, and the gallery widget needs them as soon as it renders a row.
// Left to Suspense they were fetched at ~476ms — a full round trip after the
@@ -64,7 +66,10 @@ export const GalleryUiAdapterProvider = ({ children }: { children: ReactNode })
projectId,
projectName,
queueItems,
- widgets: { patchGalleryValues: (values) => widgets.patchValues('gallery', values) },
+ widgets: {
+ openGallery: () => openWorkbenchWidget('gallery').ok,
+ patchGalleryValues: (values) => widgets.patchValues('gallery', values),
+ },
}),
[
account,
@@ -76,6 +81,7 @@ export const GalleryUiAdapterProvider = ({ children }: { children: ReactNode })
liveFollowEnabled,
liveProgressTarget,
notifications,
+ openWorkbenchWidget,
projectId,
projectName,
queueItems,
diff --git a/invokeai/frontend/webv2/src/features/gallery/ui/GalleryImageGrid.browser.test.tsx b/invokeai/frontend/webv2/src/features/gallery/ui/GalleryImageGrid.browser.test.tsx
index 01fbe58359..789420d4f6 100644
--- a/invokeai/frontend/webv2/src/features/gallery/ui/GalleryImageGrid.browser.test.tsx
+++ b/invokeai/frontend/webv2/src/features/gallery/ui/GalleryImageGrid.browser.test.tsx
@@ -341,7 +341,7 @@ const createAdapter = (): GalleryUiAdapter =>
projectId: 'project-1',
projectName: 'Project',
queueItems: [],
- widgets: { patchGalleryValues: noop },
+ widgets: { openGallery: () => true, patchGalleryValues: noop },
}) as unknown as GalleryUiAdapter;
let host: HTMLDivElement | null = null;
diff --git a/invokeai/frontend/webv2/src/features/gallery/ui/GalleryLayout.browser.test.tsx b/invokeai/frontend/webv2/src/features/gallery/ui/GalleryLayout.browser.test.tsx
index a6850374d5..c928bf3e08 100644
--- a/invokeai/frontend/webv2/src/features/gallery/ui/GalleryLayout.browser.test.tsx
+++ b/invokeai/frontend/webv2/src/features/gallery/ui/GalleryLayout.browser.test.tsx
@@ -122,7 +122,7 @@ const adapter = {
ImageContextMenu: () => null,
account: { enableLiveFollow: vi.fn() },
antialiasProgressImages: false,
- widgets: { patchGalleryValues: vi.fn() },
+ widgets: { openGallery: vi.fn(() => true), patchGalleryValues: vi.fn() },
} as unknown as GalleryUiAdapter;
let host: HTMLDivElement | null = null;
diff --git a/invokeai/frontend/webv2/src/features/gallery/ui/GalleryThumbnail.tsx b/invokeai/frontend/webv2/src/features/gallery/ui/GalleryThumbnail.tsx
index 2a750b6cb0..742273ba15 100644
--- a/invokeai/frontend/webv2/src/features/gallery/ui/GalleryThumbnail.tsx
+++ b/invokeai/frontend/webv2/src/features/gallery/ui/GalleryThumbnail.tsx
@@ -1,44 +1,26 @@
import type { GalleryItem, GalleryItemRef } from '@features/gallery/core/items';
import type { GalleryThumbnailFit } from '@features/gallery/core/settings';
-import { Badge, Box } from '@chakra-ui/react';
+import { Badge } from '@chakra-ui/react';
import { useDraggable } from '@dnd-kit/core';
import { CSS } from '@dnd-kit/utilities';
import { formatGalleryVideoDuration, toGalleryItemRef } from '@features/gallery/core/items';
import { IconButton } from '@platform/ui/Button';
-import { PlayIcon, StarIcon } from 'lucide-react';
+import { StarIcon } from 'lucide-react';
import { useCallback, useLayoutEffect, useMemo, useRef, useState, type KeyboardEvent, type MouseEvent } from 'react';
import { createPortal } from 'react-dom';
import { useTranslation } from 'react-i18next';
import { getGalleryItemDragData, getGalleryItemDragId } from './galleryDnd';
-
-const THUMBNAIL_HOVER_CSS = {
- '&:focus-within': { outline: '2px solid {colors.accent.solid}', outlineOffset: '-2px' },
- '&:hover .gallery-thumb-overlay, &:focus-within .gallery-thumb-overlay': { opacity: 1 },
-} as const;
-
-/**
- * The tile while its image is being dragged: desaturated, the visible half of
- * the touch drag cue. The other half is the portalled drag preview, which
- * carries the same desaturation so the change is visible under a finger that
- * has not moved yet — the moment the drag hold completes.
- */
-const THUMBNAIL_DRAG_CSS = {
- ...THUMBNAIL_HOVER_CSS,
- filter: 'saturate(0)',
-} as const;
+import { GalleryTileFrame } from './GalleryTileFrame';
/**
- * The tile while a touch hold has armed the drag gate (before movement starts
- * the drag): the same desaturation, easing in as the hold completes so the
- * user can see the gesture flip from scroll to drag. Set as
- * `data-drag-armed` by the hold-to-drag sensor.
+ * Desaturation is the touch drag cue: the tile while dragged, or while a
+ * sustained hold has armed the drag gate (`data-drag-armed`, set by the
+ * hold-to-drag sensor). The portalled preview carries the same filter.
*/
-const THUMBNAIL_ARMED_CSS = {
- ...THUMBNAIL_HOVER_CSS,
- '&[data-drag-armed=true]': { filter: 'saturate(0)' },
-} as const;
+const THUMBNAIL_DRAG_CSS = { filter: 'saturate(0)' } as const;
+const THUMBNAIL_ARMED_CSS = { '&[data-drag-armed=true]': { filter: 'saturate(0)' } } as const;
const PREVIEW_IMAGE_STYLE = {
borderRadius: '0.375rem',
@@ -182,28 +164,22 @@ const GalleryThumbnail = ({
);
return (
- <Box
+ <GalleryTileFrame
ref={setTileRef}
{...listeners}
- aspectRatio={1}
- bg="bg"
- borderColor={isSelected || isCompared ? 'accent.solid' : 'border.subtle'}
- borderWidth="2px"
+ alwaysShowDimensions={alwaysShowDimensions}
boxShadow={isCompared ? 'inset 0 0 0 1px {colors.accent.solid}' : undefined}
css={isDragging ? THUMBNAIL_DRAG_CSS : THUMBNAIL_ARMED_CSS}
- minW="0"
+ isSelected={isSelected || isCompared}
+ item={item}
opacity={isDragging ? 0.4 : undefined}
- overflow="hidden"
- position="relative"
role="listitem"
- rounded="md"
// Pan, don't drag: `none` would hand every touch-drag to the drag
// sensor before the browser could scroll the grid. Allowing the pan
// lets a moving finger scroll (the hold-to-drag sensor releases the
// gesture when the browser claims it); dragging still works after a
// sustained hold.
touchAction="pan-y"
- w="full"
onContextMenu={handleContextMenu}
>
<button
@@ -260,41 +236,6 @@ const GalleryThumbnail = ({
>
<StarIcon fill={item.starred ? 'currentColor' : 'none'} />
</IconButton>
- {item.kind === 'image' && item.width > 0 && item.height > 0 && (
- <Badge
- bottom="1"
- className="gallery-thumb-overlay"
- insetInlineStart="1"
- opacity={alwaysShowDimensions ? 1 : 0}
- pointerEvents="none"
- position="absolute"
- size="xs"
- transition="opacity var(--wb-motion-duration-medium) ease"
- variant="solid"
- zIndex="1"
- >
- {item.width}x{item.height}
- </Badge>
- )}
- {duration !== null && (
- <Badge
- bottom="1"
- display="flex"
- fontVariantNumeric="tabular-nums"
- gap="1"
- insetInlineStart="1"
- opacity={1}
- pointerEvents="none"
- position="absolute"
- size="xs"
- transition="opacity var(--wb-motion-duration-medium) ease"
- variant="solid"
- zIndex="1"
- >
- <PlayIcon aria-hidden="true" fill="currentColor" />
- {duration}
- </Badge>
- )}
{previewStyle
? createPortal(
<div aria-hidden="true" style={previewStyle}>
@@ -303,7 +244,7 @@ const GalleryThumbnail = ({
document.body
)
: null}
- </Box>
+ </GalleryTileFrame>
);
};
diff --git a/invokeai/frontend/webv2/src/features/gallery/ui/GalleryTileFrame.browser.test.tsx b/invokeai/frontend/webv2/src/features/gallery/ui/GalleryTileFrame.browser.test.tsx
new file mode 100644
index 0000000000..a52b0c3054
--- /dev/null
+++ b/invokeai/frontend/webv2/src/features/gallery/ui/GalleryTileFrame.browser.test.tsx
@@ -0,0 +1,134 @@
+import type { GalleryItem } from '@features/gallery/core/items';
+
+import { ChakraProvider } from '@chakra-ui/react';
+import { system } from '@theme/system';
+import { act } from 'react';
+import { createRoot, type Root } from 'react-dom/client';
+import { afterEach, beforeEach, describe, expect, it } from 'vitest';
+
+import { GalleryTileFrame, type GalleryTileFrameProps } from './GalleryTileFrame';
+
+let host: HTMLDivElement | null = null;
+let root: Root | null = null;
+(globalThis as typeof globalThis & { IS_REACT_ACT_ENVIRONMENT: boolean }).IS_REACT_ACT_ENVIRONMENT = true;
+
+const image: GalleryItem = {
+ boardId: 'board',
+ category: 'general',
+ createdAt: '2026-09-01T00:00:00.000Z',
+ fullUrl: '/full/a.png',
+ height: 96,
+ isIntermediate: false,
+ kind: 'image',
+ name: 'a.png',
+ starred: false,
+ thumbnailUrl: '/thumb/a.png',
+ width: 128,
+};
+
+const video: GalleryItem = {
+ boardId: 'board',
+ category: 'general',
+ createdAt: '2026-09-01T00:00:00.000Z',
+ durationSeconds: 66,
+ fullUrl: '/video/v.mp4',
+ height: 96,
+ isIntermediate: false,
+ kind: 'video',
+ name: 'v.mp4',
+ starred: false,
+ thumbnailUrl: '/video-thumb/v.mp4',
+ width: 128,
+};
+
+const renderFrame = async (props: Partial<GalleryTileFrameProps> = {}) => {
+ await act(() =>
+ root?.render(
+ <ChakraProvider value={system}>
+ <GalleryTileFrame data-testid="frame" item={image} {...props} />
+ </ChakraProvider>
+ )
+ );
+
+ const frame = host?.querySelector<HTMLElement>('[data-testid="frame"]');
+
+ if (!frame) {
+ throw new Error('frame did not render');
+ }
+
+ return frame;
+};
+
+const accentBorder = () => {
+ const probe = document.createElement('div');
+
+ probe.style.borderColor = 'var(--chakra-colors-accent-solid)';
+ host?.appendChild(probe);
+
+ const color = getComputedStyle(probe).borderTopColor;
+
+ probe.remove();
+ return color;
+};
+
+beforeEach(() => {
+ host = document.createElement('div');
+ document.body.appendChild(host);
+ root = createRoot(host);
+});
+
+afterEach(async () => {
+ await act(() => root?.unmount());
+ host?.remove();
+ host = null;
+ root = null;
+});
+
+describe('GalleryTileFrame', () => {
+ it('flips the border to accent when selected and keeps the shell props as invariants', async () => {
+ const unselected = await renderFrame({ rounded: 'none', w: '10px' });
+
+ expect(getComputedStyle(unselected).borderTopColor).not.toBe(accentBorder());
+ expect(getComputedStyle(unselected).aspectRatio).toBe('1 / 1');
+ expect(getComputedStyle(unselected).width).not.toBe('10px');
+
+ const selected = await renderFrame({ isSelected: true });
+
+ expect(getComputedStyle(selected).borderTopColor).toBe(accentBorder());
+ });
+
+ it('hides the dimensions badge until hovered, and composes caller css on top of its own', async () => {
+ const frame = await renderFrame({
+ children: <button type="button">focus me</button>,
+ css: { opacity: 0.5 },
+ });
+ const badge = frame.querySelector<HTMLElement>('.gallery-thumb-overlay');
+
+ expect(badge?.textContent).toBe('128x96');
+ expect(badge && getComputedStyle(badge).opacity).toBe('0');
+ expect(getComputedStyle(frame).opacity).toBe('0.5');
+ expect(getComputedStyle(frame).outlineStyle).toBe('none');
+
+ await act(() => frame.querySelector('button')?.focus());
+
+ // The focus ring comes from the frame's own css, so it proves the caller's
+ // css was composed rather than substituted.
+ expect(getComputedStyle(frame).outlineWidth).toBe('2px');
+ expect(getComputedStyle(frame).outlineColor).toBe(accentBorder());
+ });
+
+ it('pins the dimensions badge when asked', async () => {
+ const frame = await renderFrame({ alwaysShowDimensions: true });
+ const badge = frame.querySelector<HTMLElement>('.gallery-thumb-overlay');
+
+ expect(badge && getComputedStyle(badge).opacity).toBe('1');
+ });
+
+ it('shows a duration badge for videos instead of dimensions', async () => {
+ const frame = await renderFrame({ item: video });
+
+ expect(frame.querySelector('.gallery-thumb-overlay')).toBeNull();
+ expect(frame.textContent).toContain('1:06');
+ expect(frame.querySelector('svg.lucide-play[aria-hidden="true"]')).not.toBeNull();
+ });
+});
diff --git a/invokeai/frontend/webv2/src/features/gallery/ui/GalleryTileFrame.tsx b/invokeai/frontend/webv2/src/features/gallery/ui/GalleryTileFrame.tsx
new file mode 100644
index 0000000000..6a250a3271
--- /dev/null
+++ b/invokeai/frontend/webv2/src/features/gallery/ui/GalleryTileFrame.tsx
@@ -0,0 +1,92 @@
+import type { BoxProps, SystemStyleObject } from '@chakra-ui/react';
+import type { GalleryItem } from '@features/gallery/core/items';
+import type { ReactNode, Ref } from 'react';
+
+import { Badge, Box } from '@chakra-ui/react';
+import { formatGalleryVideoDuration } from '@features/gallery/core/items';
+import { PlayIcon } from 'lucide-react';
+import { useMemo } from 'react';
+
+const TILE_CSS: SystemStyleObject = {
+ '&:focus-within': { outline: '2px solid {colors.accent.solid}', outlineOffset: '-2px' },
+ '&:hover .gallery-thumb-overlay, &:focus-within .gallery-thumb-overlay': { opacity: 1 },
+};
+
+const BADGE_TRANSITION = 'opacity var(--wb-motion-duration-medium) ease';
+
+export interface GalleryTileFrameProps extends Omit<BoxProps, 'children'> {
+ alwaysShowDimensions?: boolean;
+ /** The interactive layer (image button, drag listeners, extra badges). */
+ children?: ReactNode;
+ isSelected?: boolean;
+ item: GalleryItem;
+ ref?: Ref<HTMLDivElement>;
+}
+
+/**
+ * The thumbnail shell shared by every gallery surface: square, accent border
+ * when selected, hover-revealed dimensions badge, video duration badge.
+ * Caller `css` composes on top; the shell's own props are invariants.
+ */
+export const GalleryTileFrame = ({
+ alwaysShowDimensions = false,
+ children,
+ css,
+ isSelected = false,
+ item,
+ ...boxProps
+}: GalleryTileFrameProps) => {
+ const duration = item.kind === 'video' ? formatGalleryVideoDuration(item.durationSeconds) : null;
+ const tileCss = useMemo(() => (css ? [TILE_CSS, css] : TILE_CSS), [css]);
+
+ return (
+ <Box
+ {...boxProps}
+ aspectRatio={1}
+ bg="bg"
+ borderColor={isSelected ? 'accent.solid' : 'border.subtle'}
+ borderWidth="2px"
+ css={tileCss}
+ minW="0"
+ overflow="hidden"
+ position="relative"
+ rounded="md"
+ w="full"
+ >
+ {children}
+ {item.kind === 'image' && item.width > 0 && item.height > 0 ? (
+ <Badge
+ bottom="1"
+ className="gallery-thumb-overlay"
+ insetInlineStart="1"
+ opacity={alwaysShowDimensions ? 1 : 0}
+ pointerEvents="none"
+ position="absolute"
+ size="xs"
+ transition={BADGE_TRANSITION}
+ variant="solid"
+ zIndex="1"
+ >
+ {item.width}x{item.height}
+ </Badge>
+ ) : null}
+ {duration !== null ? (
+ <Badge
+ bottom="1"
+ display="flex"
+ fontVariantNumeric="tabular-nums"
+ gap="1"
+ insetInlineStart="1"
+ pointerEvents="none"
+ position="absolute"
+ size="xs"
+ variant="solid"
+ zIndex="1"
+ >
+ <PlayIcon aria-hidden="true" fill="currentColor" />
+ {duration}
+ </Badge>
+ ) : null}
+ </Box>
+ );
+};
diff --git a/invokeai/frontend/webv2/src/features/gallery/ui/GalleryUiContext.tsx b/invokeai/frontend/webv2/src/features/gallery/ui/GalleryUiContext.tsx
index ac5137988e..89ecc5e88e 100644
--- a/invokeai/frontend/webv2/src/features/gallery/ui/GalleryUiContext.tsx
+++ b/invokeai/frontend/webv2/src/features/gallery/ui/GalleryUiContext.tsx
@@ -113,7 +113,11 @@ export interface GalleryUiAdapter {
queueItems: QueueItem[];
liveFollowEnabled: boolean;
liveProgressTarget: GalleryLiveTarget | null;
- widgets: { patchGalleryValues(values: Record<string, unknown>): void };
+ widgets: {
+ /** Open (or reveal) the Gallery widget; false when no region can host it. */
+ openGallery(): boolean;
+ patchGalleryValues(values: Record<string, unknown>): void;
+ };
}
const GalleryUiContext = createContext<GalleryUiAdapter | null>(null);
diff --git a/invokeai/frontend/webv2/src/features/gallery/ui/GalleryUploadButton.tsx b/invokeai/frontend/webv2/src/features/gallery/ui/GalleryUploadButton.tsx
index 4ff1366476..8b6c8e617b 100644
--- a/invokeai/frontend/webv2/src/features/gallery/ui/GalleryUploadButton.tsx
+++ b/invokeai/frontend/webv2/src/features/gallery/ui/GalleryUploadButton.tsx
@@ -17,7 +17,7 @@ export const GalleryUploadButton = ({
}: {
boards: GalleryBoard[];
selectedBoardId: string;
- onUploadFiles: (files: File[]) => Promise<void>;
+ onUploadFiles: (files: File[]) => Promise<unknown>;
}) => {
const { t } = useTranslation();
const selectedBoard = boards.find((board) => board.id === selectedBoardId);
diff --git a/invokeai/frontend/webv2/src/features/gallery/ui/GalleryWidgetContext.tsx b/invokeai/frontend/webv2/src/features/gallery/ui/GalleryWidgetContext.tsx
index eb97ef200f..249b95b07b 100644
--- a/invokeai/frontend/webv2/src/features/gallery/ui/GalleryWidgetContext.tsx
+++ b/invokeai/frontend/webv2/src/features/gallery/ui/GalleryWidgetContext.tsx
@@ -35,7 +35,8 @@ export interface GalleryActions {
setView: (galleryView: GalleryView) => void;
toggleItemInSelection: (item: GalleryItem, nextPrimaryItem: GalleryItem | null) => void;
updateSettings: (settings: Partial<Omit<GallerySettings, 'starredFirst'>>) => void;
- uploadFiles: (files: File[]) => Promise<void>;
+ /** Resolves with the confirmed uploads; empty when nothing landed. */
+ uploadFiles: (files: File[]) => Promise<GalleryItem[]>;
}
export interface GalleryWidgetContextValue {
diff --git a/invokeai/frontend/webv2/src/features/gallery/ui/galleryGridLayout.test.ts b/invokeai/frontend/webv2/src/features/gallery/ui/galleryGridLayout.test.ts
index 0644ac1b37..0b5a3c0e8f 100644
--- a/invokeai/frontend/webv2/src/features/gallery/ui/galleryGridLayout.test.ts
+++ b/invokeai/frontend/webv2/src/features/gallery/ui/galleryGridLayout.test.ts
@@ -11,6 +11,7 @@ import {
GALLERY_STARRED_SEPARATOR_HEIGHT_PX,
getGalleryCellSizePx,
getGalleryColumnCount,
+ getGalleryColumnCountForCell,
getGalleryGridRowHeightPx,
getGalleryGridRowIndexForItem,
} from './galleryGridLayout';
@@ -50,6 +51,20 @@ const buildRows = (overrides: Partial<Parameters<typeof buildGalleryGridRows>[0]
...overrides,
});
+describe('getGalleryColumnCountForCell', () => {
+ it('rounds to the nearest whole cell and clamps to the caller bounds', () => {
+ const bounds = { max: 8, min: 3, targetCellPx: 72 };
+
+ expect(getGalleryColumnCountForCell({ ...bounds, widthPx: 320 })).toBe(4);
+ expect(getGalleryColumnCountForCell({ ...bounds, widthPx: 120 })).toBe(3);
+ expect(getGalleryColumnCountForCell({ ...bounds, widthPx: 2000 })).toBe(8);
+ });
+
+ it('falls back to the minimum before the width is measured', () => {
+ expect(getGalleryColumnCountForCell({ max: 8, min: 3, targetCellPx: 72, widthPx: 0 })).toBe(3);
+ });
+});
+
describe('getGalleryColumnCount', () => {
it('gives the same answer at the same width regardless of placement', () => {
// The whole point of measuring rather than branching on layout: a 600px
diff --git a/invokeai/frontend/webv2/src/features/gallery/ui/galleryGridLayout.ts b/invokeai/frontend/webv2/src/features/gallery/ui/galleryGridLayout.ts
index c1938850ef..a6110f8114 100644
--- a/invokeai/frontend/webv2/src/features/gallery/ui/galleryGridLayout.ts
+++ b/invokeai/frontend/webv2/src/features/gallery/ui/galleryGridLayout.ts
@@ -35,21 +35,32 @@ export const getGalleryTargetCellPx = (imageDensityPercent: number): number => {
return GALLERY_MAX_CELL_PX - ((GALLERY_MAX_CELL_PX - GALLERY_MIN_CELL_PX) * percent) / 100;
};
+/** How many `targetCellPx` cells fit in `widthPx`, clamped; an unmeasured width yields `min`. */
+export const getGalleryColumnCountForCell = ({
+ max,
+ min,
+ targetCellPx,
+ widthPx,
+}: {
+ max: number;
+ min: number;
+ targetCellPx: number;
+ widthPx: number;
+}): number => (widthPx <= 0 ? min : Math.min(max, Math.max(min, Math.round(widthPx / targetCellPx))));
+
export const getGalleryColumnCount = ({
imageDensityPercent,
widthPx,
}: {
imageDensityPercent: number;
widthPx: number;
-}): number => {
- if (widthPx <= 0) {
- return GALLERY_MIN_COLUMN_COUNT;
- }
-
- const columnCount = Math.round(widthPx / getGalleryTargetCellPx(imageDensityPercent));
-
- return Math.min(GALLERY_MAX_COLUMN_COUNT, Math.max(GALLERY_MIN_COLUMN_COUNT, columnCount));
-};
+}): number =>
+ getGalleryColumnCountForCell({
+ max: GALLERY_MAX_COLUMN_COUNT,
+ min: GALLERY_MIN_COLUMN_COUNT,
+ targetCellPx: getGalleryTargetCellPx(imageDensityPercent),
+ widthPx,
+ });
/** Falls back to a plausible square before the viewport has been measured. */
export const getGalleryCellSizePx = ({ columnCount, widthPx }: { columnCount: number; widthPx: number }): number =>
diff --git a/invokeai/frontend/webv2/src/features/gallery/ui/useGalleryActions.browser.test.tsx b/invokeai/frontend/webv2/src/features/gallery/ui/useGalleryActions.browser.test.tsx
index 65e920c27b..107089d36a 100644
--- a/invokeai/frontend/webv2/src/features/gallery/ui/useGalleryActions.browser.test.tsx
+++ b/invokeai/frontend/webv2/src/features/gallery/ui/useGalleryActions.browser.test.tsx
@@ -187,7 +187,7 @@ const adapter: GalleryUiAdapter = {
projectId: 'project-1',
projectName: 'Project',
queueItems: [],
- widgets: { patchGalleryValues },
+ widgets: { openGallery: () => true, patchGalleryValues },
};
let selectedBoardId = 'board-1';
@@ -497,7 +497,7 @@ describe('mixed gallery upload', () => {
.mockRejectedValueOnce(new Error('bad second video'))
.mockResolvedValueOnce(videoUpload('third.mp4', '2026-07-30T12:00:05.000Z'));
- let upload: Promise<void> | undefined;
+ let upload: Promise<unknown> | undefined;
act(() => {
upload = actionsRef.current?.uploadFiles([
new File(['image'], 'one.png', { type: 'image/png' }),
@@ -564,7 +564,7 @@ describe('mixed gallery upload', () => {
})
);
- let upload: Promise<void> | undefined;
+ let upload: Promise<unknown> | undefined;
act(() => {
upload = actionsRef.current?.uploadFiles([new File(['image'], 'photo.png', { type: 'image/png' })]);
});
@@ -601,7 +601,7 @@ describe('mixed gallery upload', () => {
})
);
- let upload: Promise<void> | undefined;
+ let upload: Promise<unknown> | undefined;
act(() => {
upload = actionsRef.current?.uploadFiles([new File(['image'], 'photo.png', { type: 'image/png' })]);
});
@@ -650,7 +650,7 @@ describe('mixed gallery upload', () => {
})
);
- let upload: Promise<void> | undefined;
+ let upload: Promise<unknown> | undefined;
act(() => {
upload = actionsRef.current?.uploadFiles([
new File(['video'], 'one.mp4', { type: 'video/mp4' }),
diff --git a/invokeai/frontend/webv2/src/features/gallery/ui/useGalleryUploadAction.browser.test.tsx b/invokeai/frontend/webv2/src/features/gallery/ui/useGalleryUploadAction.browser.test.tsx
index 023d4abf83..7647f5e3e5 100644
--- a/invokeai/frontend/webv2/src/features/gallery/ui/useGalleryUploadAction.browser.test.tsx
+++ b/invokeai/frontend/webv2/src/features/gallery/ui/useGalleryUploadAction.browser.test.tsx
@@ -106,7 +106,7 @@ const adapter: GalleryUiAdapter = {
projectId: 'project-1',
projectName: 'Project',
queueItems: [],
- widgets: { patchGalleryValues: noop },
+ widgets: { openGallery: () => true, patchGalleryValues: noop },
};
const Probe = ({
@@ -223,7 +223,9 @@ describe('focused gallery upload action', () => {
await renderProbe();
await act(async () => {
- await uploadFilesRef.current?.([new File(['image'], 'photo.png', { type: 'image/png' })]);
+ await expect(
+ uploadFilesRef.current?.([new File(['image'], 'photo.png', { type: 'image/png' })])
+ ).resolves.toEqual([]);
});
expect(mocks.uploadGalleryImage).not.toHaveBeenCalled();
@@ -254,7 +256,7 @@ describe('focused gallery upload action', () => {
.mockRejectedValueOnce(new Error('bad second video'))
.mockResolvedValueOnce(videoUpload('third.mp4', '2026-07-30T12:00:05.000Z'));
- let upload: Promise<void> | undefined;
+ let upload: Promise<unknown> | undefined;
act(() => {
upload = uploadFilesRef.current?.([
new File(['image'], 'one.png', { type: 'image/png' }),
@@ -289,6 +291,12 @@ describe('focused gallery upload action', () => {
title: 'Uploaded 4 of 5 files',
});
expect(selectItem).toHaveBeenCalledExactlyOnceWith(expect.objectContaining({ kind: 'video', name: 'third.mp4' }));
+ await expect(upload).resolves.toEqual([
+ expect.objectContaining({ kind: 'image', name: 'one.png' }),
+ expect.objectContaining({ kind: 'image', name: 'two.webp' }),
+ expect.objectContaining({ kind: 'video', name: 'one.mp4' }),
+ expect.objectContaining({ kind: 'video', name: 'third.mp4' }),
+ ]);
});
it('does not select an upload from the launch board after the active board changes in flight', async () => {
@@ -299,7 +307,7 @@ describe('focused gallery upload action', () => {
})
);
- let upload: Promise<void> | undefined;
+ let upload: Promise<unknown> | undefined;
act(() => {
upload = uploadFilesRef.current?.([new File(['image'], 'photo.png', { type: 'image/png' })]);
});
@@ -315,6 +323,7 @@ describe('focused gallery upload action', () => {
expect(selectItem).not.toHaveBeenCalled();
expect(mocks.invalidateGallery).toHaveBeenCalledOnce();
+ await expect(upload).resolves.toEqual([expect.objectContaining({ kind: 'image', name: 'photo.png' })]);
});
it('does not schedule another expensive video after the account lifetime aborts', async () => {
@@ -325,7 +334,7 @@ describe('focused gallery upload action', () => {
})
);
- let upload: Promise<void> | undefined;
+ let upload: Promise<unknown> | undefined;
act(() => {
upload = uploadFilesRef.current?.([
new File(['video'], 'one.mp4', { type: 'video/mp4' }),
@@ -343,6 +352,7 @@ describe('focused gallery upload action', () => {
expect(mocks.uploadGalleryVideo).toHaveBeenCalledOnce();
expect(mocks.notificationsAdd).not.toHaveBeenCalled();
expect(mocks.notificationsReportError).not.toHaveBeenCalled();
+ await expect(upload).resolves.toEqual([]);
});
it('uses the localized Uncategorized label in a successful upload notification', async () => {
@@ -363,7 +373,9 @@ describe('focused gallery upload action', () => {
mocks.uploadGalleryImage.mockRejectedValue(new ApiError('{"detail":"Image storage maintenance is active"}', 409));
await act(async () => {
- await uploadFilesRef.current?.([new File(['image'], 'photo.png', { type: 'image/png' })]);
+ await expect(
+ uploadFilesRef.current?.([new File(['image'], 'photo.png', { type: 'image/png' })])
+ ).resolves.toEqual([]);
});
expect(mocks.notificationsReportError).toHaveBeenCalledWith({
@@ -373,4 +385,20 @@ describe('focused gallery upload action', () => {
});
expect(mocks.notificationsAdd).not.toHaveBeenCalled();
});
+
+ it('rejects unsupported files without a request and resolves empty', async () => {
+ await act(async () => {
+ await expect(
+ uploadFilesRef.current?.([new File(['notes'], 'notes.txt', { type: 'text/plain' })])
+ ).resolves.toEqual([]);
+ });
+
+ expect(mocks.uploadGalleryImage).not.toHaveBeenCalled();
+ expect(mocks.uploadGalleryVideo).not.toHaveBeenCalled();
+ expect(mocks.notificationsReportError).toHaveBeenCalledWith({
+ area: 'gallery-upload',
+ message: 'No supported media files to upload (PNG, JPEG, WebP, or MP4).',
+ namespace: 'gallery',
+ });
+ });
});
diff --git a/invokeai/frontend/webv2/src/features/gallery/ui/useGalleryUploadAction.ts b/invokeai/frontend/webv2/src/features/gallery/ui/useGalleryUploadAction.ts
index 436866a149..1814d2414d 100644
--- a/invokeai/frontend/webv2/src/features/gallery/ui/useGalleryUploadAction.ts
+++ b/invokeai/frontend/webv2/src/features/gallery/ui/useGalleryUploadAction.ts
@@ -49,7 +49,7 @@ export const useGalleryUploadAction = ({
message: t('widgets.gallery.uploadDateBoardUnavailable'),
namespace: 'gallery',
});
- return;
+ return [];
}
const accepted = files.flatMap((file) => {
@@ -64,7 +64,7 @@ export const useGalleryUploadAction = ({
message: t('widgets.gallery.uploadUnsupported'),
namespace: 'gallery',
});
- return;
+ return [];
}
const getBoard = (boardId: string) => boards.find((board) => board.id === boardId);
@@ -125,7 +125,7 @@ export const useGalleryUploadAction = ({
message: firstFailure ? getApiErrorMessage(firstFailure.reason, fallback) : fallback,
namespace: 'gallery',
});
- return;
+ return [];
}
const currentGalleryLocation = getCurrentGalleryLocation();
@@ -163,12 +163,14 @@ export const useGalleryUploadAction = ({
failedCount > 0 ? { succeeded: uploadedItems.length, total: files.length } : { count: uploadedItems.length }
),
});
+
+ return uploadedItems;
} catch (error: unknown) {
- if (!isAccountScopeCurrent(owner)) {
- return;
+ if (isAccountScopeCurrent(owner)) {
+ recordError(error);
}
- recordError(error);
+ return [];
}
},
[boards, gallery, getCurrentGalleryLocation, notifications, queryClient, selectedBoardId, t]
diff --git a/invokeai/frontend/webv2/src/features/gallery/ui/useGalleryUploadInput.ts b/invokeai/frontend/webv2/src/features/gallery/ui/useGalleryUploadInput.ts
index e04a41990a..aff6b59b45 100644
--- a/invokeai/frontend/webv2/src/features/gallery/ui/useGalleryUploadInput.ts
+++ b/invokeai/frontend/webv2/src/features/gallery/ui/useGalleryUploadInput.ts
@@ -4,7 +4,7 @@ export const ACCEPTED_UPLOAD_EXTENSIONS = 'image/png,image/jpeg,image/webp,video
export const UPLOAD_INPUT_STYLE = { display: 'none' } as const;
/** The hidden-input picker every gallery upload trigger shares: change extracts files, resets the input (so re-picking the same file fires), and forwards. */
-export const useGalleryUploadInput = (onUploadFiles: (files: File[]) => Promise<void> | void) => {
+export const useGalleryUploadInput = (onUploadFiles: (files: File[]) => Promise<unknown> | void) => {
const inputRef = useRef<HTMLInputElement | null>(null);
const onChange = useCallback(