add loading state to export button (#876)

main
Michael Fix 5 years ago committed by repo-ranger[bot]
parent fc02b0ec11
commit d9e34cbf04

@ -1,6 +1,6 @@
import React from 'react' import React from 'react'
import { withRouter } from 'next/router' 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 { COLORS, EXPORT_SIZES } from '../lib/constants'
import Button from './Button' import Button from './Button'
@ -67,12 +67,13 @@ function ExportMenu({
exportSize, exportSize,
isVisible, isVisible,
toggleVisibility, toggleVisibility,
exportImage exportImage: exp
}) { }) {
const tooLarge = React.useMemo(() => !verifyPayloadSize(backgroundImage), [backgroundImage]) const tooLarge = React.useMemo(() => !verifyPayloadSize(backgroundImage), [backgroundImage])
const online = useOnline() const online = useOnline()
const isSafari = useSafari() const isSafari = useSafari()
const [exportImage, { loading }] = useAsyncCallback(exp)
useKeyboardListener('⌘-⇧-e', () => exportImage()) useKeyboardListener('⌘-⇧-e', () => exportImage())
const disablePNG = isSafari && (tooLarge || !online) const disablePNG = isSafari && (tooLarge || !online)
@ -98,8 +99,9 @@ function ExportMenu({
selected={isVisible} selected={isVisible}
onClick={toggleVisibility} onClick={toggleVisibility}
data-cy="export-button" data-cy="export-button"
style={{ width: 92 }}
> >
Export {loading ? 'Exporting...' : 'Export'}
</Button> </Button>
</div> </div>
<Popout <Popout
@ -151,6 +153,7 @@ function ExportMenu({
color={COLORS.DARK_PURPLE} color={COLORS.DARK_PURPLE}
onClick={handleExport('png')} onClick={handleExport('png')}
id="export-png" id="export-png"
disabled={loading}
> >
PNG PNG
</Button> </Button>
@ -161,6 +164,7 @@ function ExportMenu({
color={COLORS.DARK_PURPLE} color={COLORS.DARK_PURPLE}
onClick={handleExport('svg')} onClick={handleExport('svg')}
id="export-svg" id="export-svg"
disabled={loading}
> >
SVG SVG
</Button> </Button>

Loading…
Cancel
Save