// Copyright 2019 Signal Messenger, LLC // SPDX-License-Identifier: AGPL-3.0-only import * as React from 'react'; import { StickerManagerPackRow } from './StickerManagerPackRow'; import { StickerPreviewModal } from './StickerPreviewModal'; import type { LocalizerType } from '../../types/Util'; import type { StickerPackType } from '../../state/ducks/stickers'; import { Tabs } from '../Tabs'; export type OwnProps = { readonly blessedPacks: ReadonlyArray; readonly closeStickerPackPreview: () => unknown; readonly downloadStickerPack: (packId: string, packKey: string) => unknown; readonly i18n: LocalizerType; readonly installStickerPack: (packId: string, packKey: string) => unknown; readonly installedPacks: ReadonlyArray; readonly knownPacks?: ReadonlyArray; readonly receivedPacks: ReadonlyArray; readonly uninstallStickerPack: (packId: string, packKey: string) => unknown; }; export type Props = OwnProps; enum TabViews { Available = 'Available', Installed = 'Installed', } export const StickerManager = React.memo(function StickerManagerInner({ blessedPacks, closeStickerPackPreview, downloadStickerPack, i18n, installStickerPack, installedPacks, knownPacks, receivedPacks, uninstallStickerPack, }: 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}
{({ selectedTab }) => ( <> {selectedTab === TabViews.Available && ( <>

{i18n('icu:stickers--StickerManager--BlessedPacks')}

{blessedPacks.length > 0 ? ( blessedPacks.map(pack => ( )) ) : (
{i18n( 'icu:stickers--StickerManager--BlessedPacks--Empty' )}
)}

{i18n('icu:stickers--StickerManager--ReceivedPacks')}

{receivedPacks.length > 0 ? ( receivedPacks.map(pack => ( )) ) : (
{i18n( 'icu:stickers--StickerManager--ReceivedPacks--Empty' )}
)} )} {selectedTab === TabViews.Installed && (installedPacks.length > 0 ? ( installedPacks.map(pack => ( )) ) : (
{i18n( 'icu:stickers--StickerManager--InstalledPacks--Empty' )}
))} )}
); });