2019-08-11 09:08:17 +00:00
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import React from 'react';
|
|
|
|
import { connect } from 'react-redux';
|
|
|
|
import { bindActionCreators } from 'redux';
|
2019-09-17 19:32:54 +00:00
|
|
|
import { browserHistory, Link } from 'react-router';
|
2019-08-11 09:08:17 +00:00
|
|
|
import { Helmet } from 'react-helmet';
|
|
|
|
import { updateSettings, initiateVerification, createApiKey, removeApiKey } from '../actions';
|
|
|
|
import NavBasic from '../../../components/NavBasic';
|
|
|
|
|
|
|
|
import AssetList from '../../IDE/components/AssetList';
|
2019-07-09 08:35:24 +00:00
|
|
|
import CollectionList from '../../IDE/components/CollectionList';
|
2019-08-11 09:08:17 +00:00
|
|
|
import SketchList from '../../IDE/components/SketchList';
|
|
|
|
|
|
|
|
import DashboardTabSwitcher, { TabKey } from '../components/DashboardTabSwitcher';
|
|
|
|
|
|
|
|
class DashboardView extends React.Component {
|
|
|
|
static defaultProps = {
|
|
|
|
user: null,
|
|
|
|
};
|
|
|
|
|
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
this.closeAccountPage = this.closeAccountPage.bind(this);
|
|
|
|
this.gotoHomePage = this.gotoHomePage.bind(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
componentDidMount() {
|
|
|
|
document.body.className = this.props.theme;
|
|
|
|
}
|
|
|
|
|
|
|
|
closeAccountPage() {
|
|
|
|
browserHistory.push(this.props.previousPath);
|
|
|
|
}
|
|
|
|
|
|
|
|
gotoHomePage() {
|
|
|
|
browserHistory.push('/');
|
|
|
|
}
|
|
|
|
|
2019-07-09 08:35:24 +00:00
|
|
|
selectedTabKey() {
|
2019-08-11 09:08:17 +00:00
|
|
|
const path = this.props.location.pathname;
|
|
|
|
|
|
|
|
if (/assets/.test(path)) {
|
|
|
|
return TabKey.assets;
|
2019-07-09 08:35:24 +00:00
|
|
|
} else if (/collections/.test(path)) {
|
|
|
|
return TabKey.collections;
|
2019-08-11 09:08:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return TabKey.sketches;
|
|
|
|
}
|
|
|
|
|
|
|
|
ownerName() {
|
|
|
|
if (this.props.params.username) {
|
|
|
|
return this.props.params.username;
|
|
|
|
}
|
|
|
|
|
|
|
|
return this.props.user.username;
|
|
|
|
}
|
|
|
|
|
|
|
|
isOwner() {
|
|
|
|
return this.props.user.username === this.props.params.username;
|
|
|
|
}
|
|
|
|
|
2019-09-17 19:32:54 +00:00
|
|
|
renderActionButton(tabKey, username) {
|
|
|
|
if (!this.isOwner()) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (tabKey) {
|
|
|
|
case TabKey.assets:
|
|
|
|
return null;
|
|
|
|
case TabKey.collections:
|
|
|
|
return <Link className="dashboard__action-button" to={`/${username}/collections/create`}>Create collection</Link>;
|
|
|
|
case TabKey.sketches:
|
|
|
|
default:
|
|
|
|
return <Link className="dashboard__action-button" to="/">New sketch</Link>;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-09 08:35:24 +00:00
|
|
|
renderContent(tabKey, username) {
|
|
|
|
switch (tabKey) {
|
|
|
|
case TabKey.assets:
|
|
|
|
return <AssetList username={username} />;
|
|
|
|
case TabKey.collections:
|
|
|
|
return <CollectionList username={username} />;
|
|
|
|
case TabKey.sketches:
|
|
|
|
default:
|
|
|
|
return <SketchList username={username} />;
|
|
|
|
}
|
2019-08-11 09:08:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
2019-07-09 08:35:24 +00:00
|
|
|
const currentTab = this.selectedTabKey();
|
2019-08-11 09:08:17 +00:00
|
|
|
const isOwner = this.isOwner();
|
|
|
|
const { username } = this.props.params;
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div className="dashboard">
|
|
|
|
<Helmet>
|
|
|
|
<title>p5.js Web Editor | Account</title>
|
|
|
|
</Helmet>
|
|
|
|
|
|
|
|
<NavBasic onBack={this.closeAccountPage} />
|
|
|
|
|
|
|
|
<section className="dashboard-header">
|
|
|
|
<div className="dashboard-header__header">
|
|
|
|
<h2 className="dashboard-header__header__title">{this.ownerName()}</h2>
|
|
|
|
|
2019-09-17 19:32:54 +00:00
|
|
|
<div className="dashboard-header__actions">
|
|
|
|
<DashboardTabSwitcher currentTab={currentTab} isOwner={isOwner} username={username} />
|
|
|
|
{this.renderActionButton(currentTab, username)}
|
|
|
|
</div>
|
|
|
|
|
2019-08-11 09:08:17 +00:00
|
|
|
</div>
|
2019-09-08 14:43:16 +00:00
|
|
|
|
2019-08-11 09:08:17 +00:00
|
|
|
<div className="dashboard-content">
|
2019-07-09 08:35:24 +00:00
|
|
|
{this.renderContent(currentTab, username)}
|
2019-08-11 09:08:17 +00:00
|
|
|
</div>
|
|
|
|
</section>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function mapStateToProps(state) {
|
|
|
|
return {
|
|
|
|
previousPath: state.ide.previousPath,
|
|
|
|
user: state.user,
|
|
|
|
theme: state.preferences.theme
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
function mapDispatchToProps(dispatch) {
|
|
|
|
return bindActionCreators({
|
|
|
|
updateSettings, initiateVerification, createApiKey, removeApiKey
|
|
|
|
}, dispatch);
|
|
|
|
}
|
|
|
|
|
|
|
|
DashboardView.propTypes = {
|
|
|
|
location: PropTypes.shape({
|
|
|
|
pathname: PropTypes.string.isRequired,
|
|
|
|
}).isRequired,
|
|
|
|
params: PropTypes.shape({
|
|
|
|
username: PropTypes.string.isRequired,
|
|
|
|
}).isRequired,
|
|
|
|
previousPath: PropTypes.string.isRequired,
|
|
|
|
theme: PropTypes.string.isRequired,
|
|
|
|
user: PropTypes.shape({
|
|
|
|
username: PropTypes.string.isRequired,
|
|
|
|
}),
|
|
|
|
};
|
|
|
|
|
|
|
|
export default connect(mapStateToProps, mapDispatchToProps)(DashboardView);
|