import * as React from 'react'; import PQueue from 'p-queue'; import { SortableContainer, SortableElement, SortEndHandler, } from 'react-sortable-hoc'; import * as styles from './StickerGrid.scss'; import { Props as StickerFrameProps, StickerFrame } from './StickerFrame'; import { stickersDuck } from '../store'; import { DropZone, Props as DropZoneProps } from '../elements/DropZone'; import { convertToWebp } from '../util/preload'; const queue = new PQueue({ concurrency: 3, timeout: 1000 * 60 * 2 }); const SmartStickerFrame = SortableElement( ({ id, showGuide, mode }: StickerFrameProps) => { const data = stickersDuck.useStickerData(id); const actions = stickersDuck.useStickerActions(); const image = data.webp ? data.webp.src : undefined; return ( ); } ); export type Props = Pick; export type InnerGridProps = Props & { ids: Array; }; const InnerGrid = SortableContainer( ({ ids, mode, showGuide }: InnerGridProps) => { const containerClassName = ids.length > 0 ? styles.grid : styles.drop; const frameMode = mode === 'add' ? 'removable' : 'pick-emoji'; const actions = stickersDuck.useStickerActions(); const handleDrop = React.useCallback( async paths => { actions.initializeStickers(paths); paths.forEach(path => { // tslint:disable-next-line no-floating-promises queue.add(async () => { try { const webp = await convertToWebp(path); actions.addWebp(webp); } catch (e) { window.log.error('Error processing image:', e); actions.removeSticker(path); actions.addToast({ key: 'StickerCreator--Toasts--errorProcessing', }); } }); }); }, [actions] ); return (
{ids.length > 0 ? ( <> {ids.map((p, i) => ( ))} {mode === 'add' && ids.length < stickersDuck.maxStickers ? ( ) : null} ) : ( )}
); } ); export const StickerGrid = SortableContainer((props: Props) => { const ids = stickersDuck.useStickerOrder(); const actions = stickersDuck.useStickerActions(); const handleSortEnd = React.useCallback( sortEnd => { actions.moveSticker(sortEnd); }, [actions] ); return ( ); });