From e096eef0497a9f82ea546f70e4bb2bb67ec8161d Mon Sep 17 00:00:00 2001 From: psychedelicious <4822129+psychedelicious@users.noreply.github.com> Date: Sun, 30 Oct 2022 16:02:57 +1100 Subject: [PATCH] Fixes next/prev image not working if category doesn't match --- frontend/src/features/gallery/gallerySlice.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) 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(