diff --git a/client/modules/IDE/components/SketchList.jsx b/client/modules/IDE/components/SketchList.jsx
index bce30da1dc..0dc02bd2db 100644
--- a/client/modules/IDE/components/SketchList.jsx
+++ b/client/modules/IDE/components/SketchList.jsx
@@ -1,5 +1,5 @@
+import React, { useState, useRef } from 'react';
import PropTypes from 'prop-types';
-import React from 'react';
import { Helmet } from 'react-helmet';
import { withTranslation } from 'react-i18next';
import { connect } from 'react-redux';
@@ -30,121 +30,108 @@ const ROOT_URL = getConfig('API_URL');
const formatDateCell = (date, mobile = false) =>
dates.format(date, { showTime: !mobile });
-class SketchListRowBase extends React.Component {
- constructor(props) {
- super(props);
- this.state = {
- optionsOpen: false,
- renameOpen: false,
- renameValue: props.sketch.name,
- isFocused: false
- };
- this.renameInput = React.createRef();
- }
-
- onFocusComponent = () => {
- this.setState({ isFocused: true });
+const SketchListRowBase = ({
+ sketch,
+ username,
+ mobile,
+ user,
+ changeProjectName,
+ cloneProject,
+ showShareModal,
+ deleteProject,
+ onAddToCollection,
+ handleRowClick,
+ t
+}) => {
+ const [optionsOpen, setOptionsOpen] = useState(false);
+ const [renameOpen, setRenameOpen] = useState(false);
+ const [renameValue, setRenameValue] = useState(sketch.name);
+ const [isFocused, setIsFocused] = useState(false);
+ const renameInput = useRef(null);
+
+ const closeAll = () => {
+ setRenameOpen(false);
+ setOptionsOpen(false);
};
- onBlurComponent = () => {
- this.setState({ isFocused: false });
+ const updateName = () => {
+ const isValid = renameValue.trim().length !== 0;
+ if (isValid) {
+ changeProjectName(sketch.id, renameValue.trim());
+ }
+ };
+
+ const onFocusComponent = () => {
+ setIsFocused(true);
+ };
+
+ const onBlurComponent = () => {
+ setIsFocused(false);
setTimeout(() => {
- if (!this.state.isFocused) {
- this.closeAll();
+ if (!isFocused) {
+ closeAll();
}
}, 200);
};
- openOptions = () => {
- this.setState({
- optionsOpen: true
- });
+ const openOptions = () => {
+ setOptionsOpen(true);
};
- closeOptions = () => {
- this.setState({
- optionsOpen: false
- });
+ const closeOptions = () => {
+ setOptionsOpen(false);
};
- toggleOptions = () => {
- if (this.state.optionsOpen) {
- this.closeOptions();
+ const toggleOptions = () => {
+ if (optionsOpen) {
+ closeOptions();
} else {
- this.openOptions();
+ openOptions();
}
};
- openRename = () => {
- this.setState(
- {
- renameOpen: true,
- renameValue: this.props.sketch.name
- },
- () => this.renameInput.current.focus()
- );
+ const openRename = () => {
+ setRenameOpen(true);
+ setRenameValue(sketch.name);
+ renameInput.current.focus();
};
- closeRename = () => {
- this.setState({
- renameOpen: false
- });
+ const closeRename = () => {
+ setRenameOpen(false);
};
- closeAll = () => {
- this.setState({
- renameOpen: false,
- optionsOpen: false
- });
- };
-
- handleRenameChange = (e) => {
- this.setState({
- renameValue: e.target.value
- });
+ const handleRenameChange = (e) => {
+ setRenameValue(e.target.value);
};
- handleRenameEnter = (e) => {
+ const handleRenameEnter = (e) => {
if (e.key === 'Enter') {
- this.updateName();
- this.closeAll();
+ updateName();
+ closeAll();
}
};
- handleRenameBlur = () => {
- this.updateName();
- this.closeAll();
+ const handleRenameBlur = () => {
+ updateName();
+ closeAll();
};
- updateName = () => {
- const isValid = this.state.renameValue.trim().length !== 0;
- if (isValid) {
- this.props.changeProjectName(
- this.props.sketch.id,
- this.state.renameValue.trim()
- );
- }
+ const resetSketchName = () => {
+ setRenameValue(sketch.name);
+ setRenameOpen(false);
};
- resetSketchName = () => {
- this.setState({
- renameValue: this.props.sketch.name,
- renameOpen: false
- });
+ const handleDropdownOpen = () => {
+ closeAll();
+ openOptions();
};
- handleDropdownOpen = () => {
- this.closeAll();
- this.openOptions();
+ const handleRenameOpen = () => {
+ closeAll();
+ openRename();
};
- handleRenameOpen = () => {
- this.closeAll();
- this.openRename();
- };
-
- handleSketchDownload = () => {
- const { sketch } = this.props;
+ const handleSketchDownload = () => {
const downloadLink = document.createElement('a');
downloadLink.href = `${ROOT_URL}/projects/${sketch.id}/zip`;
downloadLink.download = `${sketch.name}.zip`;
@@ -153,53 +140,48 @@ class SketchListRowBase extends React.Component {
document.body.removeChild(downloadLink);
};
- handleSketchDuplicate = () => {
- this.closeAll();
- this.props.cloneProject(this.props.sketch);
+ const handleSketchDuplicate = () => {
+ closeAll();
+ cloneProject(sketch);
};
- handleSketchShare = () => {
- this.closeAll();
- this.props.showShareModal(
- this.props.sketch.id,
- this.props.sketch.name,
- this.props.username
- );
+ const handleSketchShare = () => {
+ closeAll();
+ showShareModal(sketch.id, sketch.name, username);
};
- handleSketchDelete = () => {
- this.closeAll();
+ const handleSketchDelete = () => {
+ closeAll();
if (
window.confirm(
- this.props.t('Common.DeleteConfirmation', {
- name: this.props.sketch.name
+ t('Common.DeleteConfirmation', {
+ name: sketch.name
})
)
) {
- this.props.deleteProject(this.props.sketch.id);
+ deleteProject(sketch.id);
}
};
- renderViewButton = (sketchURL) => (
+ const renderViewButton = (sketchURL) => (
- {this.props.t('SketchList.View')}
+ {t('SketchList.View')}
|
);
- renderDropdown = () => {
- const { optionsOpen } = this.state;
- const userIsOwner = this.props.user.username === this.props.username;
+ const renderDropdown = () => {
+ const userIsOwner = user.username === username;
return (
|