Use bindActionCreators in StickerCreator

This commit is contained in:
Ken Powers 2020-04-29 17:58:05 -04:00 committed by Scott Nonnenberg
parent ba5e2ff6e5
commit d6924c0088
4 changed files with 40 additions and 26 deletions

View File

@ -20,10 +20,12 @@ export const ShareStage = () => {
const images = stickersDuck.useOrderedImagePaths();
const shareUrl = stickersDuck.usePackUrl();
const [linkCopied, setLinkCopied] = React.useState(false);
const onCopy = React.useCallback(() => setLinkCopied(true), [setLinkCopied]);
const resetLinkCopied = React.useCallback(() => setLinkCopied(false), [
setLinkCopied,
]);
const onCopy = React.useCallback(() => {
setLinkCopied(true);
}, [setLinkCopied]);
const resetLinkCopied = React.useCallback(() => {
setLinkCopied(false);
}, [setLinkCopied]);
const handleNext = React.useCallback(() => {
window.close();

View File

@ -11,7 +11,9 @@ import { encryptAndUpload } from '../../util/preload';
import { useI18n } from '../../util/i18n';
import { Toaster } from '../../components/Toaster';
const handleCancel = () => history.push('/add-meta');
const handleCancel = () => {
history.push('/add-meta');
};
export const UploadStage = () => {
const i18n = useI18n();
@ -24,8 +26,11 @@ export const UploadStage = () => {
const [complete, setComplete] = React.useState(0);
React.useEffect(() => {
// tslint:disable-next-line: no-floating-promises
(async () => {
const onProgress = () => setComplete(i => i + 1);
const onProgress = () => {
setComplete(i => i + 1);
};
try {
const packMeta = await encryptAndUpload(
{ title, author },
@ -36,7 +41,10 @@ export const UploadStage = () => {
actions.setPackMeta(packMeta);
history.push('/share');
} catch (e) {
actions.addToast('StickerCreator--Toasts--errorUploading', [e.message]);
actions.addToast({
key: 'StickerCreator--Toasts--errorUploading',
subs: [e.message],
});
history.push('/add-meta');
}
})();

View File

@ -59,7 +59,9 @@ const InnerGrid = SortableContainer(
// @ts-ignore
window.log.error('Error processing image:', e);
actions.removeSticker(path);
actions.addToast('StickerCreator--Toasts--errorProcessing');
actions.addToast({
key: 'StickerCreator--Toasts--errorProcessing',
});
}
});
});

View File

@ -11,6 +11,7 @@ import { useDispatch, useSelector } from 'react-redux';
import { createSelector } from 'reselect';
import { clamp, find, isNumber, pull, remove, take, uniq } from 'lodash';
import { SortEnd } from 'react-sortable-hoc';
import { bindActionCreators } from 'redux';
import arrayMove from 'array-move';
import { AppState } from '../reducer';
import { PackMetaData, WebpData } from '../../util/preload';
@ -268,24 +269,25 @@ export const useStickerActions = () => {
const dispatch = useDispatch();
return useMemo(
() => ({
addWebp: (data: WebpData) => dispatch(addWebp(data)),
initializeStickers: (paths: Array<string>) =>
dispatch(initializeStickers(paths)),
removeSticker: (src: string) => dispatch(removeSticker(src)),
moveSticker: (sortEnd: SortEnd) => dispatch(moveSticker(sortEnd)),
setCover: (webp: WebpData) => dispatch(setCover(webp)),
setEmoji: (p: { id: string; emoji: EmojiPickDataType }) =>
dispatch(setEmoji(p)),
setTitle: (title: string) => dispatch(setTitle(title)),
setAuthor: (author: string) => dispatch(setAuthor(author)),
setPackMeta: (e: PackMetaData) => dispatch(setPackMeta(e)),
addToast: (key: string, subs?: Array<number>) =>
dispatch(addToast({ key, subs })),
dismissToast: () => dispatch(dismissToast()),
reset: () => dispatch(reset()),
resetStatus: () => dispatch(resetStatus()),
}),
() =>
bindActionCreators(
{
addWebp,
initializeStickers,
removeSticker,
moveSticker,
setCover,
setEmoji,
setTitle,
setAuthor,
setPackMeta,
addToast,
dismissToast,
reset,
resetStatus,
},
dispatch
),
[dispatch]
);
};