// Copyright 2019-2020 Signal Messenger, LLC // SPDX-License-Identifier: AGPL-3.0-only import * as React from 'react'; import classNames from 'classnames'; import { StickerManagerPackRow } from './StickerManagerPackRow'; import { StickerPreviewModal } from './StickerPreviewModal'; import type { LocalizerType } from '../../types/Util'; import type { 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; export const StickerManager = React.memo( ({ installedPacks, receivedPacks, knownPacks, blessedPacks, downloadStickerPack, installStickerPack, uninstallStickerPack, i18n, }: Props) => { const focusRef = React.createRef(); const [packToPreview, setPackToPreview] = React.useState(null); React.useEffect(() => { if (!knownPacks) { return; } knownPacks.forEach(pack => { downloadStickerPack(pack.id, pack.key); }); // When this component is created, it's initially not part of the DOM, and then it's // added off-screen and animated in. This ensures that the focus takes. setTimeout(() => { if (focusRef.current) { focusRef.current.focus(); } }); // We only want to attempt downloads on initial load // eslint-disable-next-line react-hooks/exhaustive-deps }, []); const clearPackToPreview = React.useCallback(() => { setPackToPreview(null); }, [setPackToPreview]); const previewPack = React.useCallback((pack: StickerPackType) => { setPackToPreview(pack); }, []); 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 null; } return (

{i18n(section.i18nKey)}

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