Refactor smart components
Co-authored-by: Fedor Indutny <79877362+indutny-signal@users.noreply.github.com>
This commit is contained in:
parent
05c09ef769
commit
27b55e472d
109 changed files with 3583 additions and 2629 deletions
|
@ -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}
|
||||
/>
|
||||
);
|
||||
}
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue