diff --git a/client/modules/User/pages/DashboardView.jsx b/client/modules/User/pages/DashboardView.jsx index 3de9e7f956..510339b980 100644 --- a/client/modules/User/pages/DashboardView.jsx +++ b/client/modules/User/pages/DashboardView.jsx @@ -1,10 +1,9 @@ -import PropTypes from 'prop-types'; -import React from 'react'; +import React, { useState } from 'react'; import { connect } from 'react-redux'; import MediaQuery from 'react-responsive'; import { withTranslation } from 'react-i18next'; +import PropTypes from 'prop-types'; -import browserHistory from '../../../browserHistory'; import Button from '../../../common/Button'; import Nav from '../../IDE/components/Header/Nav'; import Overlay from '../../App/components/Overlay'; @@ -24,36 +23,15 @@ import DashboardTabSwitcherPublic, { TabKey } from '../components/DashboardTabSwitcher'; -class DashboardView extends React.Component { - static defaultProps = { - user: null - }; - - constructor(props) { - super(props); - this.closeAccountPage = this.closeAccountPage.bind(this); - this.createNewSketch = this.createNewSketch.bind(this); - this.gotoHomePage = this.gotoHomePage.bind(this); - this.toggleCollectionCreate = this.toggleCollectionCreate.bind(this); - this.state = { - collectionCreateVisible: false - }; - } +function DashboardView(props) { + const [collectionCreateVisible, setCollectionCreateVisible] = useState(false); - closeAccountPage() { - browserHistory.push(this.props.previousPath); - } - - createNewSketch() { - this.props.newProject(); - } - - gotoHomePage() { - browserHistory.push('/'); - } + const createNewSketch = () => { + props.newProject(); + }; - selectedTabKey() { - const path = this.props.location.pathname; + const selectedTabKey = () => { + const path = props.location.pathname; if (/assets/.test(path)) { return TabKey.assets; @@ -62,57 +40,53 @@ class DashboardView extends React.Component { } return TabKey.sketches; - } + }; - ownerName() { - if (this.props.params.username) { - return this.props.params.username; + const ownerName = () => { + if (props.params.username) { + return props.params.username; } - return this.props.user.username; - } + return props.user.username; + }; - isOwner() { - return this.props.user.username === this.props.params.username; - } + const isOwner = () => props.user.username === props.params.username; - toggleCollectionCreate() { - this.setState((prevState) => ({ - collectionCreateVisible: !prevState.collectionCreateVisible - })); - } + const toggleCollectionCreate = () => { + setCollectionCreateVisible((prevState) => !prevState); + }; - renderActionButton(tabKey, username, t) { + const renderActionButton = (tabKey, username, t) => { switch (tabKey) { case TabKey.assets: - return this.isOwner() && ; + return isOwner() && ; case TabKey.collections: return ( - this.isOwner() && ( - - - + ) ); case TabKey.sketches: default: return ( - - {this.isOwner() && ( - )} - + ); } - } + }; - renderContent(tabKey, username, mobile) { + const renderContent = (tabKey, username, mobile) => { switch (tabKey) { case TabKey.assets: return ; @@ -126,52 +100,48 @@ class DashboardView extends React.Component { ); } - } - - render() { - const currentTab = this.selectedTabKey(); - const isOwner = this.isOwner(); - const { username } = this.props.params; - const actions = this.renderActionButton(currentTab, username, this.props.t); - - return ( - -