diff --git a/components/ExportMenu.js b/components/ExportMenu.js index 33efb41..d2fb278 100644 --- a/components/ExportMenu.js +++ b/components/ExportMenu.js @@ -44,173 +44,177 @@ const CopyEmbed = withRouter(({ router: { asPath }, mapper, title, margin }) => const popoutStyle = { width: '280px', right: 0 } -class ExportMenu extends React.PureComponent { - input = React.createRef() +function useSafari() { + const [isSafari, setSafari] = React.useState(false) + React.useEffect(() => { + setSafari( + window.navigator && + window.navigator.userAgent.indexOf('Safari') !== -1 && + window.navigator.userAgent.indexOf('Chrome') === -1 + ) + }, []) + + return isSafari +} + +function ExportMenu({ + backgroundImage, + onChange, + exportSize, + isVisible, + toggleVisibility, + export: exportImage +}) { + const tooLarge = React.useMemo(() => !verifyPayloadSize(backgroundImage), [backgroundImage]) + const online = useOnline() + const isSafari = useSafari() + + const disablePNG = isSafari && (tooLarge || !online) - handleInputChange = ({ target: { name, value } }) => this.props.onChange(name, value) + const input = React.useRef() - handleExportSizeChange = selectedSize => () => this.props.onChange('exportSize', selectedSize) + const handleExportSizeChange = selectedSize => () => onChange('exportSize', selectedSize) - handleExport = format => () => - this.props.export(format, { - filename: this.input.current.value + const handleExport = format => () => + exportImage(format, { + filename: input.current.value }) - render() { - const { exportSize, isVisible, toggleVisibility, disablePNG } = this.props - - return ( -