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,40 +1,48 @@
|
|||
// Copyright 2019 Signal Messenger, LLC
|
||||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
import { connect } from 'react-redux';
|
||||
import { mapDispatchToProps } from '../actions';
|
||||
import React, { memo } from 'react';
|
||||
import { useSelector } from 'react-redux';
|
||||
import { StickerPreviewModal } from '../../components/stickers/StickerPreviewModal';
|
||||
import type { StateType } from '../reducer';
|
||||
|
||||
import { getIntl, getStickersPath, getTempPath } from '../selectors/user';
|
||||
import {
|
||||
getBlessedPacks,
|
||||
getPacks,
|
||||
translatePackFromDB,
|
||||
} from '../selectors/stickers';
|
||||
import { useStickersActions } from '../ducks/stickers';
|
||||
import { useGlobalModalActions } from '../ducks/globalModals';
|
||||
|
||||
export type ExternalProps = {
|
||||
packId: string;
|
||||
};
|
||||
|
||||
const mapStateToProps = (state: StateType, props: ExternalProps) => {
|
||||
const { packId } = props;
|
||||
const stickersPath = getStickersPath(state);
|
||||
const tempPath = getTempPath(state);
|
||||
export const SmartStickerPreviewModal = memo(function SmartStickerPreviewModal({
|
||||
packId,
|
||||
}: ExternalProps) {
|
||||
const i18n = useSelector(getIntl);
|
||||
const packs = useSelector(getPacks);
|
||||
const blessedPacks = useSelector(getBlessedPacks);
|
||||
const stickersPath = useSelector(getStickersPath);
|
||||
const tempPath = useSelector(getTempPath);
|
||||
|
||||
const packs = getPacks(state);
|
||||
const blessedPacks = getBlessedPacks(state);
|
||||
const pack = packs[packId];
|
||||
const { downloadStickerPack, installStickerPack, uninstallStickerPack } =
|
||||
useStickersActions();
|
||||
const { closeStickerPackPreview } = useGlobalModalActions();
|
||||
|
||||
return {
|
||||
...props,
|
||||
pack: pack
|
||||
? translatePackFromDB(pack, packs, blessedPacks, stickersPath, tempPath)
|
||||
: undefined,
|
||||
i18n: getIntl(state),
|
||||
};
|
||||
};
|
||||
const packDb = packs[packId];
|
||||
const pack = packDb
|
||||
? translatePackFromDB(packDb, packs, blessedPacks, stickersPath, tempPath)
|
||||
: undefined;
|
||||
|
||||
const smart = connect(mapStateToProps, mapDispatchToProps);
|
||||
|
||||
export const SmartStickerPreviewModal = smart(StickerPreviewModal);
|
||||
return (
|
||||
<StickerPreviewModal
|
||||
closeStickerPackPreview={closeStickerPackPreview}
|
||||
downloadStickerPack={downloadStickerPack}
|
||||
i18n={i18n}
|
||||
installStickerPack={installStickerPack}
|
||||
pack={pack}
|
||||
uninstallStickerPack={uninstallStickerPack}
|
||||
/>
|
||||
);
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue