From d9e34cbf04904a7eb415ecc3519d34d9198e5c5c Mon Sep 17 00:00:00 2001 From: Michael Fix Date: Tue, 1 Oct 2019 16:38:26 -0700 Subject: [PATCH] add loading state to export button (#876) --- components/ExportMenu.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/components/ExportMenu.js b/components/ExportMenu.js index c25d2b4..e681329 100644 --- a/components/ExportMenu.js +++ b/components/ExportMenu.js @@ -1,6 +1,6 @@ import React from 'react' import { withRouter } from 'next/router' -import { useCopyTextHandler, useOnline, useKeyboardListener } from 'actionsack' +import { useCopyTextHandler, useOnline, useKeyboardListener, useAsyncCallback } from 'actionsack' import { COLORS, EXPORT_SIZES } from '../lib/constants' import Button from './Button' @@ -67,12 +67,13 @@ function ExportMenu({ exportSize, isVisible, toggleVisibility, - exportImage + exportImage: exp }) { const tooLarge = React.useMemo(() => !verifyPayloadSize(backgroundImage), [backgroundImage]) const online = useOnline() const isSafari = useSafari() + const [exportImage, { loading }] = useAsyncCallback(exp) useKeyboardListener('⌘-⇧-e', () => exportImage()) const disablePNG = isSafari && (tooLarge || !online) @@ -98,8 +99,9 @@ function ExportMenu({ selected={isVisible} onClick={toggleVisibility} data-cy="export-button" + style={{ width: 92 }} > - Export + {loading ? 'Exporting...' : 'Export'} PNG @@ -161,6 +164,7 @@ function ExportMenu({ color={COLORS.DARK_PURPLE} onClick={handleExport('svg')} id="export-svg" + disabled={loading} > SVG