import * as React from 'react'; import classNames from 'classnames'; import { StickerManagerPackRow } from './StickerManagerPackRow'; import { StickerPreviewModal } from './StickerPreviewModal'; import { LocalizerType } from '../../types/Util'; import { StickerPackType } from '../../state/ducks/stickers'; export type OwnProps = { readonly installedPacks: ReadonlyArray; readonly receivedPacks: ReadonlyArray; readonly blessedPacks: ReadonlyArray; readonly knownPacks?: ReadonlyArray; readonly downloadStickerPack: (packId: string, packKey: string) => unknown; readonly installStickerPack: (packId: string, packKey: string) => unknown; readonly uninstallStickerPack: (packId: string, packKey: string) => unknown; readonly i18n: LocalizerType; }; export type Props = OwnProps; function focusOnRender(el: HTMLElement | null) { if (el) { el.focus(); } } export const StickerManager = React.memo( // tslint:disable-next-line max-func-body-length ({ installedPacks, receivedPacks, knownPacks, blessedPacks, downloadStickerPack, installStickerPack, uninstallStickerPack, i18n, }: Props) => { const [ packToPreview, setPackToPreview, ] = React.useState(null); React.useEffect(() => { if (!knownPacks) { return; } knownPacks.forEach(pack => { downloadStickerPack(pack.id, pack.key); }); }, []); const clearPackToPreview = React.useCallback( () => { setPackToPreview(null); }, [setPackToPreview] ); const previewPack = React.useCallback( (pack: StickerPackType) => { setPackToPreview(pack); }, [clearPackToPreview] ); return ( <> {packToPreview ? ( ) : null}
{[ { i18nKey: 'stickers--StickerManager--InstalledPacks', i18nEmptyKey: 'stickers--StickerManager--InstalledPacks--Empty', packs: installedPacks, hideIfEmpty: false, }, { i18nKey: 'stickers--StickerManager--BlessedPacks', i18nEmptyKey: 'stickers--StickerManager--BlessedPacks--Empty', packs: blessedPacks, hideIfEmpty: true, }, { i18nKey: 'stickers--StickerManager--ReceivedPacks', i18nEmptyKey: 'stickers--StickerManager--ReceivedPacks--Empty', packs: receivedPacks, hideIfEmpty: false, }, ].map(section => { if (section.hideIfEmpty && section.packs.length === 0) { return; } return (

{i18n(section.i18nKey)}

{section.packs.length > 0 ? ( section.packs.map(pack => ( )) ) : (
{i18n(section.i18nEmptyKey)}
)}
); })}
); } );