diff --git a/web/js/components/image-download/image-download-panel.js b/web/js/components/image-download/image-download-panel.js index 42821aa500..f40de23cce 100644 --- a/web/js/components/image-download/image-download-panel.js +++ b/web/js/components/image-download/image-download-panel.js @@ -1,4 +1,4 @@ -import React from 'react'; +import React, { useState } from 'react'; import PropTypes from 'prop-types'; import googleTagManager from 'googleTagManager'; import { @@ -30,25 +30,38 @@ const RESOLUTION_KEY = { * @class resolutionSelection * @extends React.Component */ -export default class ImageDownloadPanel extends React.Component { - constructor(props) { - super(props); +function ImageDownloadPanel(props) { + const { + fileType, + isWorldfile, + resolution, + getLayers, + url, + lonlats, + projection, + date, + markerCoordinates, + onPanelChange, + fileTypeOptions, + fileTypes, + secondLabel, + worldFileOptions, + datelineMessage, + map, + viewExtent, + resolutions, + maxImageSize, + firstLabel, + geoLatLong, + onLatLongChange, + } = props; - this.state = { - fileType: props.fileType, - isWorldfile: props.isWorldfile, - resolution: props.resolution, - debugUrl: '', - }; - this.handleChange = this.handleChange.bind(this); - this.onDownload = this.onDownload.bind(this); - } + const [currFileType, setFileType] = useState(fileType); + const [currIsWorldfile, setIsWorldfile] = useState(isWorldfile); + const [currResolution, setResolution] = useState(resolution); + const [debugUrl, setDebugUrl] = useState(''); - onDownload(width, height) { - const { - getLayers, url, lonlats, projection, date, markerCoordinates, - } = this.props; - const { fileType, isWorldfile, resolution } = this.state; + const onDownload = (width, height) => { const time = new Date(date.getTime()); const layerList = getLayers(); @@ -59,15 +72,13 @@ export default class ImageDownloadPanel extends React.Component { lonlats, { width, height }, time, - fileType, - fileType === 'application/vnd.google-earth.kmz' ? false : isWorldfile, + currFileType, + currFileType === 'application/vnd.google-earth.kmz' ? false : currIsWorldfile, markerCoordinates, ); if (url) { window.open(dlURL, '_blank'); - } else { - console.log(url); } googleTagManager.pushEvent({ event: 'image_download', @@ -75,60 +86,48 @@ export default class ImageDownloadPanel extends React.Component { activeCount: layerList.length, }, image: { - resolution: RESOLUTION_KEY[resolution], - format: fileType, - worldfile: isWorldfile, + resolution: RESOLUTION_KEY[currResolution], + format: currFileType, + worldfile: currIsWorldfile, }, }); - this.setState({ debugUrl: dlURL }); - } + setDebugUrl(dlURL); + }; - handleChange(type, value) { - const { onPanelChange } = this.props; + const handleChange = (type, value) => { if (type === 'resolution') { - this.setState({ - resolution: value, - }); + setResolution(value); } else if (type === 'worldfile') { - value = Boolean(Number(value)); - this.setState({ - isWorldfile: value, - }); + setIsWorldfile(Boolean(Number(value))); } else { - this.setState({ - fileType: value, - }); + setFileType(value); } onPanelChange(type, value); - } + }; - _renderFileTypeSelect() { - const { fileTypeOptions, fileTypes, secondLabel } = this.props; - const { fileType } = this.state; + const _renderFileTypeSelect = () => { if (fileTypeOptions) { return (
{secondLabel}
); } - } + }; - _renderWorldfileSelect() { - const { worldFileOptions } = this.props; - const { isWorldfile, fileType } = this.state; + const _renderWorldfileSelect = () => { if (worldFileOptions) { - const value = isWorldfile ? 1 : 0; + const value = currIsWorldfile ? 1 : 0; return (
- {fileType === 'application/vnd.google-earth.kmz' ? ( + {currFileType === 'application/vnd.google-earth.kmz' ? ( @@ -136,7 +135,7 @@ export default class ImageDownloadPanel extends React.Component {