Refactor smart components

Co-authored-by: Fedor Indutny <79877362+indutny-signal@users.noreply.github.com>
This commit is contained in:
Jamie Kyle 2024-03-13 13:44:13 -07:00 committed by GitHub
parent 05c09ef769
commit 27b55e472d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
109 changed files with 3583 additions and 2629 deletions

View file

@ -1,14 +1,8 @@
// Copyright 2022 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
import React, { useCallback } from 'react';
import React, { memo, useCallback } from 'react';
import { useSelector } from 'react-redux';
import type { ReadonlyDeep } from 'type-fest';
import type { GetConversationByIdType } from '../selectors/conversations';
import type { LocalizerType } from '../../types/Util';
import type { MediaItemType } from '../../types/MediaItem';
import type { StateType } from '../reducer';
import { Lightbox } from '../../components/Lightbox';
import { getConversationSelector } from '../selectors/conversations';
import { getIntl } from '../selectors/user';
@ -26,8 +20,8 @@ import {
shouldShowLightbox,
} from '../selectors/lightbox';
export function SmartLightbox(): JSX.Element | null {
const i18n = useSelector<StateType, LocalizerType>(getIntl);
export const SmartLightbox = memo(function SmartLightbox() {
const i18n = useSelector(getIntl);
const { saveAttachment } = useConversationsActions();
const {
closeLightbox,
@ -38,20 +32,15 @@ export function SmartLightbox(): JSX.Element | null {
const { toggleForwardMessagesModal } = useGlobalModalActions();
const { pauseVoiceNotePlayer } = useAudioPlayerActions();
const conversationSelector = useSelector<StateType, GetConversationByIdType>(
getConversationSelector
);
const conversationSelector = useSelector(getConversationSelector);
const isShowingLightbox = useSelector<StateType, boolean>(shouldShowLightbox);
const isViewOnce = useSelector<StateType, boolean>(getIsViewOnce);
const media = useSelector<
StateType,
ReadonlyArray<ReadonlyDeep<MediaItemType>>
>(getMedia);
const hasPrevMessage = useSelector<StateType, boolean>(getHasPrevMessage);
const hasNextMessage = useSelector<StateType, boolean>(getHasNextMessage);
const selectedIndex = useSelector<StateType, number>(getSelectedIndex);
const playbackDisabled = useSelector<StateType, boolean>(getPlaybackDisabled);
const isShowingLightbox = useSelector(shouldShowLightbox);
const isViewOnce = useSelector(getIsViewOnce);
const media = useSelector(getMedia);
const hasPrevMessage = useSelector(getHasPrevMessage);
const hasNextMessage = useSelector(getHasNextMessage);
const selectedIndex = useSelector(getSelectedIndex);
const playbackDisabled = useSelector(getPlaybackDisabled);
const onPrevAttachment = useCallback(() => {
if (selectedIndex <= 0) {
@ -107,4 +96,4 @@ export function SmartLightbox(): JSX.Element | null {
hasPrevMessage={hasPrevMessage}
/>
);
}
});