@@ -51,20 +51,25 @@ export function MediaView({
5151
5252 // Custom hooks
5353 const { viewState, handlers } = useImageViewControls ( ) ;
54+ const resetViewerState = useCallback ( ( ) => {
55+ handlers . resetZoom ( ) ;
56+ setResetSignal ( ( s ) => s + 1 ) ;
57+ } , [ handlers ] ) ;
58+
5459 // Navigation handlers
5560 const handleNextImage = useCallback ( ( ) => {
5661 if ( currentViewIndex < images . length - 1 ) {
5762 dispatch ( setCurrentViewIndex ( currentViewIndex + 1 ) ) ;
58- handlers . resetZoom ( ) ;
63+ resetViewerState ( ) ;
5964 }
60- } , [ dispatch , handlers , currentViewIndex , images . length ] ) ;
65+ } , [ dispatch , resetViewerState , currentViewIndex , images . length ] ) ;
6166
6267 const handlePreviousImage = useCallback ( ( ) => {
6368 if ( currentViewIndex > 0 ) {
6469 dispatch ( setCurrentViewIndex ( currentViewIndex - 1 ) ) ;
65- handlers . resetZoom ( ) ;
70+ resetViewerState ( ) ;
6671 }
67- } , [ dispatch , handlers , currentViewIndex ] ) ;
72+ } , [ dispatch , resetViewerState , currentViewIndex ] ) ;
6873
6974 const handleClose = useCallback ( ( ) => {
7075 dispatch ( closeImageView ( ) ) ;
@@ -74,9 +79,9 @@ export function MediaView({
7479 const handleThumbnailClick = useCallback (
7580 ( index : number ) => {
7681 dispatch ( setCurrentViewIndex ( index ) ) ;
77- handlers . resetZoom ( ) ;
82+ resetViewerState ( ) ;
7883 } ,
79- [ dispatch , handlers ] ,
84+ [ dispatch , resetViewerState ] ,
8085 ) ;
8186
8287 const location = useLocation ( ) ;
@@ -85,8 +90,8 @@ export function MediaView({
8590 // Loop to first image handler for slideshow
8691 const handleLoopToStart = useCallback ( ( ) => {
8792 dispatch ( setCurrentViewIndex ( 0 ) ) ;
88- handlers . resetZoom ( ) ;
89- } , [ dispatch , handlers ] ) ;
93+ resetViewerState ( ) ;
94+ } , [ dispatch , resetViewerState ] ) ;
9095
9196 // Slideshow functionality
9297 const { isSlideshowActive, toggleSlideshow } = useSlideshow (
@@ -142,9 +147,8 @@ export function MediaView({
142147
143148 const handleResetZoom = useCallback ( ( ) => {
144149 imageViewerRef . current ?. reset ( ) ;
145- handlers . resetZoom ( ) ;
146- setResetSignal ( ( s ) => s + 1 ) ;
147- } , [ handlers ] ) ;
150+ resetViewerState ( ) ;
151+ } , [ resetViewerState ] ) ;
148152
149153 // Keyboard navigation
150154 useKeyboardNavigation ( {
@@ -164,6 +168,7 @@ export function MediaView({
164168
165169 // Safe variables
166170 const currentImagePath = currentImage . path ;
171+ const currentImageKey = currentImage . id || currentImage . path ;
167172 // console.log(currentImage);
168173 const currentImageAlt = `image-${ currentViewIndex } ` ;
169174 return (
@@ -190,6 +195,7 @@ export function MediaView({
190195 >
191196 { type === 'image' && (
192197 < ImageViewer
198+ key = { currentImageKey }
193199 ref = { imageViewerRef }
194200 imagePath = { currentImagePath }
195201 alt = { currentImageAlt }
0 commit comments