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
60}60}
61 61
62function ExpandedImageDialogContent({ preview, onClose }: ExpandedImageDialogProps) {62function ExpandedImageDialogContent({ preview, onClose }: ExpandedImageDialogProps) {
63 const [currentIndex, setCurrentIndex] = useState(preview.index);63 const [indexOffset, setIndexOffset] = useState(0);
64 const images = preview.images;64 const images = preview.images;
65 const canNavigate = images.length > 1;65 const canNavigate = images.length > 1;
66 const currentIndex = canNavigate
67 ? (preview.index + indexOffset + images.length) % images.length
68 : preview.index;
66 69
67 const navigateImage = (direction: -1 | 1) => {70 const navigateImage = (direction: -1 | 1) => {
68 setCurrentIndex((existingIndex) => {71 if (!canNavigate) return;
69 if (!canNavigate) return existingIndex;72 setIndexOffset((existingOffset) => existingOffset + direction);
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 });
75 };73 };
76 74
77 useExpandedImageKeyboardShortcuts({75 useExpandedImageKeyboardShortcuts({
docs/perf/expanded-image-dialog-react-scan-after.json+2−2
@@ -1,8 +1,8 @@
1{1{
2 "hasReactScan": true,2 "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",
4 "report": {4 "report": {
5 "reactScanReport": null,5 "reactScanReport": null,
6 "renderEvents": []6 "renderEvents": []
7 }7 }
8}8}
docs/perf/expanded-image-dialog-react-scan-after.webm+0−0

Binary file not shown.