Unified · Split
| @@ -60,18 +60,16 @@ function useExpandedImageKeyboardShortcuts(input: { · 59 unmodified lines | |||
| 60 | } | 60 | } |
| 61 | 61 | ||
| 62 | function ExpandedImageDialogContent({ preview, onClose }: ExpandedImageDialogProps) { | 62 | function 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({ |
| @@ -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 | } |
Binary file not shown.