2022-12-09 21:02:22 -05:00
|
|
|
// Copyright 2022 Signal Messenger, LLC
|
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
|
|
|
import { createSelector } from 'reselect';
|
2023-01-13 12:07:26 -08:00
|
|
|
import type { ReadonlyDeep } from 'type-fest';
|
2022-12-09 21:02:22 -05:00
|
|
|
import type { MediaItemType } from '../../types/MediaItem';
|
|
|
|
import type { StateType } from '../reducer';
|
|
|
|
import type { LightboxStateType } from '../ducks/lightbox';
|
|
|
|
|
|
|
|
export const getLightboxState = (state: StateType): LightboxStateType =>
|
|
|
|
state.lightbox;
|
|
|
|
|
|
|
|
export const shouldShowLightbox = createSelector(
|
|
|
|
getLightboxState,
|
|
|
|
({ isShowingLightbox }): boolean => isShowingLightbox
|
|
|
|
);
|
|
|
|
|
|
|
|
export const getIsViewOnce = createSelector(
|
|
|
|
getLightboxState,
|
|
|
|
(state): boolean => (state.isShowingLightbox ? state.isViewOnce : false)
|
|
|
|
);
|
|
|
|
|
|
|
|
export const getSelectedIndex = createSelector(
|
|
|
|
getLightboxState,
|
2022-12-12 18:03:16 -05:00
|
|
|
(state): number => {
|
|
|
|
if (!state.isShowingLightbox) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2023-09-26 17:38:21 +02:00
|
|
|
return state.selectedIndex ?? 0;
|
2022-12-12 18:03:16 -05:00
|
|
|
}
|
2022-12-09 21:02:22 -05:00
|
|
|
);
|
|
|
|
|
|
|
|
export const getMedia = createSelector(
|
|
|
|
getLightboxState,
|
2023-01-13 12:07:26 -08:00
|
|
|
(state): ReadonlyArray<ReadonlyDeep<MediaItemType>> =>
|
2022-12-21 16:07:02 -08:00
|
|
|
state.isShowingLightbox ? state.media : []
|
2022-12-09 21:02:22 -05:00
|
|
|
);
|
2023-03-03 19:03:15 -08:00
|
|
|
|
|
|
|
export const getHasPrevMessage = createSelector(
|
|
|
|
getLightboxState,
|
|
|
|
(state): boolean => state.isShowingLightbox && state.hasPrevMessage
|
|
|
|
);
|
|
|
|
|
|
|
|
export const getHasNextMessage = createSelector(
|
|
|
|
getLightboxState,
|
|
|
|
(state): boolean => state.isShowingLightbox && state.hasNextMessage
|
|
|
|
);
|
2024-02-02 15:39:32 -08:00
|
|
|
|
|
|
|
export const getPlaybackDisabled = createSelector(
|
|
|
|
getLightboxState,
|
|
|
|
(state): boolean => state.isShowingLightbox && state.playbackDisabled
|
|
|
|
);
|