diff --git a/frontend/src/features/gallery/gallerySlice.ts b/frontend/src/features/gallery/gallerySlice.ts index f0d560239e..10234a3aff 100644 --- a/frontend/src/features/gallery/gallerySlice.ts +++ b/frontend/src/features/gallery/gallerySlice.ts @@ -157,7 +157,9 @@ export const gallerySlice = createSlice({ selectNextImage: (state, action: PayloadAction) => { const category = action.payload; const { currentImage } = state; - const tempImages = state.categories[category].images; + if (!currentImage) return; + const tempImages = + state.categories[currentImage.category as GalleryCategory].images; if (currentImage) { const currentImageIndex = tempImages.findIndex( @@ -173,7 +175,9 @@ export const gallerySlice = createSlice({ selectPrevImage: (state, action: PayloadAction) => { const category = action.payload; const { currentImage } = state; - const tempImages = state.categories[category].images; + if (!currentImage) return; + const tempImages = + state.categories[currentImage.category as GalleryCategory].images; if (currentImage) { const currentImageIndex = tempImages.findIndex(