diff --git a/client/modules/IDE/components/AssetList.jsx b/client/modules/IDE/components/AssetList.jsx index 559f60c580..e07b663abf 100644 --- a/client/modules/IDE/components/AssetList.jsx +++ b/client/modules/IDE/components/AssetList.jsx @@ -1,5 +1,5 @@ import PropTypes from 'prop-types'; -import React from 'react'; +import React, { useState, useEffect } from 'react'; import { connect } from 'react-redux'; import { bindActionCreators } from 'redux'; import { Link } from 'react-router-dom'; @@ -11,118 +11,99 @@ import Loader from '../../App/components/loader'; import * as AssetActions from '../actions/assets'; import DownFilledTriangleIcon from '../../../images/down-filled-triangle.svg'; -class AssetListRowBase extends React.Component { - constructor(props) { - super(props); - this.state = { - isFocused: false, - optionsOpen: false - }; - } - - onFocusComponent = () => { - this.setState({ isFocused: true }); - }; +function AssetListRowBase(props) { + const [isFocused, setIsFocused] = useState(false); + const [optionsOpen, setOptionsOpen] = useState(false); - onBlurComponent = () => { - this.setState({ isFocused: false }); + const onFocusComponent = () => { + setIsFocused(true); + }; + const closeOptions = () => { + setOptionsOpen(false); + }; + const onBlurComponent = () => { + setIsFocused(false); setTimeout(() => { - if (!this.state.isFocused) { - this.closeOptions(); + if (!isFocused) { + closeOptions(); } }, 200); }; - openOptions = () => { - this.setState({ - optionsOpen: true - }); + const openOptions = () => { + setOptionsOpen(true); }; - closeOptions = () => { - this.setState({ - optionsOpen: false - }); - }; - - toggleOptions = () => { - if (this.state.optionsOpen) { - this.closeOptions(); + const toggleOptions = () => { + if (optionsOpen) { + closeOptions(); } else { - this.openOptions(); + openOptions(); } }; - handleDropdownOpen = () => { - this.closeOptions(); - this.openOptions(); - }; - - handleAssetDelete = () => { - const { key, name } = this.props.asset; - this.closeOptions(); - if (window.confirm(this.props.t('Common.DeleteConfirmation', { name }))) { - this.props.deleteAssetRequest(key); + const handleAssetDelete = () => { + const { key, name } = props.asset; + closeOptions(); + if (window.confirm(props.t('Common.DeleteConfirmation', { name }))) { + props.deleteAssetRequest(key); } }; - render() { - const { asset, username, t } = this.props; - const { optionsOpen } = this.state; - return ( - - - - {asset.name} + const { asset, username, t } = props; + return ( + + + + {asset.name} + + + {prettyBytes(asset.size)} + + {asset.sketchId && ( + + {asset.sketchName} - - {prettyBytes(asset.size)} - - {asset.sketchId && ( - - {asset.sketchName} - - )} - - - - {optionsOpen && ( - - )} - - - ); - } + )} + + + + {optionsOpen && ( + + )} + + + ); } AssetListRowBase.propTypes = { @@ -154,65 +135,57 @@ const AssetListRow = connect( mapDispatchToPropsAssetListRow )(AssetListRowBase); -class AssetList extends React.Component { - constructor(props) { - super(props); - this.props.getAssets(); - } +function AssetList(props) { + useEffect(() => { + props.getAssets(); + }, []); - getAssetsTitle() { - return this.props.t('AssetList.Title'); - } + const getAssetsTitle = () => props.t('AssetList.Title'); - hasAssets() { - return !this.props.loading && this.props.assetList.length > 0; - } + const hasAssets = () => !props.loading && props.assetList.length > 0; - renderLoader() { - if (this.props.loading) return ; + const renderLoader = () => { + if (props.loading) return ; return null; - } + }; - renderEmptyTable() { - if (!this.props.loading && this.props.assetList.length === 0) { + const renderEmptyTable = () => { + if (!props.loading && props.assetList.length === 0) { return (

- {this.props.t('AssetList.NoUploadedAssets')} + {props.t('AssetList.NoUploadedAssets')}

); } return null; - } - - render() { - const { assetList, t } = this.props; - return ( -
- - {this.getAssetsTitle()} - - {this.renderLoader()} - {this.renderEmptyTable()} - {this.hasAssets() && ( - - - - - - - - - - - {assetList.map((asset) => ( - - ))} - -
{t('AssetList.HeaderName')}{t('AssetList.HeaderSize')}{t('AssetList.HeaderSketch')}
- )} -
- ); - } + }; + + return ( +
+ + {getAssetsTitle()} + + {renderLoader()} + {renderEmptyTable()} + {hasAssets() && ( + + + + + + + + + + + {props.assetList.map((asset) => ( + + ))} + +
{props.t('AssetList.HeaderName')}{props.t('AssetList.HeaderSize')}{props.t('AssetList.HeaderSketch')}
+ )} +
+ ); } AssetList.propTypes = {