Support duplicate attachments in lightbox

This commit is contained in:
Fedor Indutny 2023-09-26 17:38:21 +02:00 committed by GitHub
parent b885ced90d
commit 1a2976dae4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 35 additions and 45 deletions

View file

@ -32,7 +32,7 @@ export function SmartLightbox(): JSX.Element | null {
closeLightbox,
showLightboxForNextMessage,
showLightboxForPrevMessage,
setSelectedLightboxPath,
setSelectedLightboxIndex,
} = useLightboxActions();
const { toggleForwardMessagesModal } = useGlobalModalActions();
const { pauseVoiceNotePlayer } = useAudioPlayerActions();
@ -58,12 +58,11 @@ export function SmartLightbox(): JSX.Element | null {
}
return;
}
setSelectedLightboxPath(media[selectedIndex - 1]?.attachment.path);
setSelectedLightboxIndex(selectedIndex - 1);
}, [
showLightboxForPrevMessage,
media,
selectedIndex,
setSelectedLightboxPath,
setSelectedLightboxIndex,
hasPrevMessage,
]);
@ -74,22 +73,15 @@ export function SmartLightbox(): JSX.Element | null {
}
return;
}
setSelectedLightboxPath(media[selectedIndex + 1]?.attachment.path);
setSelectedLightboxIndex(selectedIndex + 1);
}, [
showLightboxForNextMessage,
media,
selectedIndex,
setSelectedLightboxPath,
setSelectedLightboxIndex,
hasNextMessage,
]);
const onSelectAttachment = useCallback(
(newIndex: number) => {
setSelectedLightboxPath(media[newIndex]?.attachment.path);
},
[setSelectedLightboxPath, media]
);
if (!isShowingLightbox) {
return null;
}
@ -107,7 +99,7 @@ export function SmartLightbox(): JSX.Element | null {
onMediaPlaybackStart={pauseVoiceNotePlayer}
onPrevAttachment={onPrevAttachment}
onNextAttachment={onNextAttachment}
onSelectAttachment={onSelectAttachment}
onSelectAttachment={setSelectedLightboxIndex}
hasNextMessage={hasNextMessage}
hasPrevMessage={hasPrevMessage}
/>