History

Use derived preview index in expanded dialog

Cursor Agent committed 5 months ago

Commit 616d4931 parent 4b701b83 files · +7 −9Browse files

Unified · Split

3 files
  1. apps/web/src/components/chat/ExpandedImageDialog.tsx +6 −8
  2. docs/perf/expanded-image-dialog-react-scan-after.json +2 −2
  3. docs/perf/expanded-image-dialog-react-scan-after.webm +0 −0
apps/web/src/components/chat/ExpandedImageDialog.tsx+6−8
@@ -60,18 +60,16 @@ function useExpandedImageKeyboardShortcuts(input: { · 59 unmodified lines
6060 }
6161
6262 function ExpandedImageDialogContent({ preview, onClose }: ExpandedImageDialogProps) {
63− const [currentIndex, setCurrentIndex] = useState(preview.index);
63+ const [indexOffset, setIndexOffset] = useState(0);
6464 const images = preview.images;
6565 const canNavigate = images.length > 1;
66+ const currentIndex = canNavigate
67+ ? (preview.index + indexOffset + images.length) % images.length
68+ : preview.index;
6669
6770 const navigateImage = (direction: -1 | 1) => {
68− setCurrentIndex((existingIndex) => {
69− if (!canNavigate) return existingIndex;
70− const safeExistingIndex =
71− existingIndex >= 0 && existingIndex < images.length ? existingIndex : preview.index;
72− const nextIndex = (safeExistingIndex + direction + images.length) % images.length;
73− return nextIndex === existingIndex ? existingIndex : nextIndex;
74− });
71+ if (!canNavigate) return;
72+ setIndexOffset((existingOffset) => existingOffset + direction);
7573 };
7674
7775 useExpandedImageKeyboardShortcuts({
docs/perf/expanded-image-dialog-react-scan-after.json+2−2
@@ -1,8 +1,8 @@
11 {
22 "hasReactScan": true,
3− "summary": "Profiler commits: 3 total (1 mount, 2 update), last 1.30ms",
3+ "summary": "Profiler commits: 3 total (1 mount, 2 update), last 1.20ms",
44 "report": {
55 "reactScanReport": null,
66 "renderEvents": []
77 }
8−}
8+}
docs/perf/expanded-image-dialog-react-scan-after.webm+0−0

Binary file not shown.