From 35323db519a51ef73dde78c6d6c8f53115ecdbaa Mon Sep 17 00:00:00 2001 From: Josh Perez <60019601+josh-signal@users.noreply.github.com> Date: Mon, 12 Dec 2022 18:03:16 -0500 Subject: [PATCH] Fixes lightbox selectedIndex --- ts/state/selectors/lightbox.ts | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/ts/state/selectors/lightbox.ts b/ts/state/selectors/lightbox.ts index eb6a9f5b27b..317c7e6e7df 100644 --- a/ts/state/selectors/lightbox.ts +++ b/ts/state/selectors/lightbox.ts @@ -21,12 +21,17 @@ export const getIsViewOnce = createSelector( export const getSelectedIndex = createSelector( getLightboxState, - (state): number => - state.isShowingLightbox - ? state.media.findIndex( - item => item.attachment.path === state.selectedAttachmentPath - ) || 0 - : 0 + (state): number => { + if (!state.isShowingLightbox) { + return 0; + } + + const index = state.media.findIndex( + item => item.attachment.path === state.selectedAttachmentPath + ); + + return index > 0 ? index : 0; + } ); export const getMedia = createSelector(