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,11 +1,9 @@
|
|||
// Copyright 2019 Signal Messenger, LLC
|
||||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
import { connect } from 'react-redux';
|
||||
import { mapDispatchToProps } from '../actions';
|
||||
import React, { memo, useMemo } from 'react';
|
||||
import { useSelector } from 'react-redux';
|
||||
import { ShortcutGuideModal } from '../../components/ShortcutGuideModal';
|
||||
import type { StateType } from '../reducer';
|
||||
|
||||
import { countStickers } from '../../components/stickers/lib';
|
||||
import { getIntl, getPlatform } from '../selectors/user';
|
||||
import {
|
||||
|
@ -14,30 +12,35 @@ import {
|
|||
getKnownStickerPacks,
|
||||
getReceivedStickerPacks,
|
||||
} from '../selectors/stickers';
|
||||
import { useGlobalModalActions } from '../ducks/globalModals';
|
||||
|
||||
const mapStateToProps = (state: StateType) => {
|
||||
const blessedPacks = getBlessedStickerPacks(state);
|
||||
const installedPacks = getInstalledStickerPacks(state);
|
||||
const knownPacks = getKnownStickerPacks(state);
|
||||
const receivedPacks = getReceivedStickerPacks(state);
|
||||
export const SmartShortcutGuideModal = memo(function SmartShortcutGuideModal() {
|
||||
const i18n = useSelector(getIntl);
|
||||
const blessedPacks = useSelector(getBlessedStickerPacks);
|
||||
const installedPacks = useSelector(getInstalledStickerPacks);
|
||||
const knownPacks = useSelector(getKnownStickerPacks);
|
||||
const receivedPacks = useSelector(getReceivedStickerPacks);
|
||||
const platform = useSelector(getPlatform);
|
||||
|
||||
const hasInstalledStickers =
|
||||
countStickers({
|
||||
knownPacks,
|
||||
blessedPacks,
|
||||
installedPacks,
|
||||
receivedPacks,
|
||||
}) > 0;
|
||||
const { closeShortcutGuideModal } = useGlobalModalActions();
|
||||
|
||||
const platform = getPlatform(state);
|
||||
const hasInstalledStickers = useMemo(() => {
|
||||
return (
|
||||
countStickers({
|
||||
knownPacks,
|
||||
blessedPacks,
|
||||
installedPacks,
|
||||
receivedPacks,
|
||||
}) > 0
|
||||
);
|
||||
}, [blessedPacks, installedPacks, knownPacks, receivedPacks]);
|
||||
|
||||
return {
|
||||
hasInstalledStickers,
|
||||
platform,
|
||||
i18n: getIntl(state),
|
||||
};
|
||||
};
|
||||
|
||||
const smart = connect(mapStateToProps, mapDispatchToProps);
|
||||
|
||||
export const SmartShortcutGuideModal = smart(ShortcutGuideModal);
|
||||
return (
|
||||
<ShortcutGuideModal
|
||||
hasInstalledStickers={hasInstalledStickers}
|
||||
platform={platform}
|
||||
closeShortcutGuideModal={closeShortcutGuideModal}
|
||||
i18n={i18n}
|
||||
/>
|
||||
);
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue