@@ -17,7 +17,6 @@ import type { ImageViewerRef } from './ImageViewer';
1717// Custom hooks
1818import { useImageViewControls } from '@/hooks/useImageViewControls' ;
1919import { useSlideshow } from '@/hooks/useSlideshow' ;
20- import { useFavorites } from '@/hooks/useFavorites' ;
2120import { useKeyboardNavigation } from '@/hooks/useKeyboardNavigation' ;
2221import { useToggleFav } from '../../hooks/useToggleFav' ;
2322import { useLocation } from 'react-router' ;
@@ -33,8 +32,6 @@ export function MediaView({
3332 const currentViewIndex = useSelector ( selectCurrentViewIndex ) ;
3433 const totalImages = images . length ;
3534 // guard: images default to empty array in the signature so `images.length` is safe
36- // keep debug output minimal
37- // console.log(totalImages);
3835
3936 const currentImage = useMemo ( ( ) => {
4037 if ( currentViewIndex >= 0 && currentViewIndex < images . length ) {
@@ -52,8 +49,6 @@ export function MediaView({
5249
5350 // Custom hooks
5451 const { viewState, handlers } = useImageViewControls ( ) ;
55- const { favorites } = useFavorites ( ) ;
56- const [ isfav , setIsfav ] = useState ( currentImage ?. isFavourite || false ) ;
5752 // Navigation handlers
5853 const handleNextImage = useCallback ( ( ) => {
5954 if ( currentViewIndex < images . length - 1 ) {
@@ -84,13 +79,6 @@ export function MediaView({
8479
8580 const location = useLocation ( ) ;
8681 const { toggleFavourite } = useToggleFav ( ) ;
87- // handling toogle_favvvvv
88- const handle_favourite_toggle = ( ) => {
89- console . log ( location . pathname ) ;
90-
91- if ( ! currentImage ?. id ) return ;
92- toggleFavourite ( currentImage ?. id ) ;
93- } ;
9482
9583 // Slideshow functionality
9684 const { isSlideshowActive, toggleSlideshow } = useSlideshow (
@@ -115,13 +103,14 @@ export function MediaView({
115103 } , [ ] ) ;
116104
117105 // Hooks that depend on currentImage but always declared
118- const handleToggleFavorite = useCallback ( ( ) => {
106+ const handleToggleFavourite = useCallback ( ( ) => {
119107 if ( currentImage ) {
120- setIsfav ( ( prev ) => ! prev ) ;
121- handle_favourite_toggle ( ) ;
108+ if ( currentImage ?. id ) {
109+ toggleFavourite ( currentImage . id ) ;
110+ }
122111 if ( location . pathname === '/favourites' ) handleClose ( ) ;
123112 }
124- } , [ currentImage , isfav ] ) ;
113+ } , [ currentImage , toggleFavourite ] ) ;
125114
126115 const handleZoomIn = useCallback ( ( ) => {
127116 imageViewerRef . current ?. zoomIn ( ) ;
@@ -163,8 +152,8 @@ export function MediaView({
163152 < MediaViewControls
164153 showInfo = { showInfo }
165154 onToggleInfo = { toggleInfo }
166- onToggleFavorite = { handleToggleFavorite }
167- isFavorite = { isfav }
155+ onToggleFavourite = { handleToggleFavourite }
156+ isFavourite = { currentImage . isFavourite || false }
168157 onOpenFolder = { handleOpenFolder }
169158 isSlideshowActive = { isSlideshowActive }
170159 onToggleSlideshow = { toggleSlideshow }
@@ -217,7 +206,6 @@ export function MediaView({
217206 currentIndex = { currentViewIndex }
218207 showThumbnails = { showThumbnails }
219208 onThumbnailClick = { handleThumbnailClick }
220- favorites = { favorites }
221209 type = { type }
222210 />
223211 </ div >
0 commit comments