Use derived preview index in expanded dialog

Co-authored-by: Julius Marminge <[email protected]>
This commit is contained in:
Cursor AgentandJulius Marminge committed 2026-05-30 16:13:50 +00:00
1 parent 4b701b8a97
commit 616d493bbc
3 files changed
+8 -10

No files matched your search

@@ -60,18 +60,16 @@ function useExpandedImageKeyboardShortcuts(input: {
}
function ExpandedImageDialogContent({ preview, onClose }: ExpandedImageDialogProps) {
const [currentIndex, setCurrentIndex] = useState(preview.index);
const [indexOffset, setIndexOffset] = useState(0);
const images = preview.images;
const canNavigate = images.length > 1;
const currentIndex = canNavigate
? (preview.index + indexOffset + images.length) % images.length
: preview.index;
const navigateImage = (direction: -1 | 1) => {
setCurrentIndex((existingIndex) => {
if (!canNavigate) return existingIndex;
const safeExistingIndex =
existingIndex >= 0 && existingIndex < images.length ? existingIndex : preview.index;
const nextIndex = (safeExistingIndex + direction + images.length) % images.length;
return nextIndex === existingIndex ? existingIndex : nextIndex;
});
if (!canNavigate) return;
setIndexOffset((existingOffset) => existingOffset + direction);
};
useExpandedImageKeyboardShortcuts({
@@ -1,8 +1,8 @@
{
"hasReactScan": true,
"summary": "Profiler commits: 3 total (1 mount, 2 update), last 1.30ms",
"summary": "Profiler commits: 3 total (1 mount, 2 update), last 1.20ms",
"report": {
"reactScanReport": null,
"renderEvents": []
}
}
}