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';
|
2020-04-19 20:45:09 +00:00
|
|
|
import { browserHistory } from 'react-router';
|
2019-08-11 09:08:17 +00:00
|
|
|
import { updateSettings, initiateVerification, createApiKey, removeApiKey } from '../actions';
|
2020-04-19 20:45:09 +00:00
|
|
|
|
|
|
|
import Button from '../../../common/Button';
|
|
|
|
|
2019-09-11 18:11:20 +00:00
|
|
|
import Nav from '../../../components/Nav';
|
2019-10-02 15:01:52 +00:00
|
|
|
import Overlay from '../../App/components/Overlay';
|
2019-08-11 09:08:17 +00:00
|
|
|
|
|
|
|
import AssetList from '../../IDE/components/AssetList';
|
2019-11-04 19:30:24 +00:00
|
|
|
import AssetSize from '../../IDE/components/AssetSize';
|
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';
|
2019-11-10 20:39:22 +00:00
|
|
|
import { CollectionSearchbar, SketchSearchbar } from '../../IDE/components/Searchbar';
|
2019-08-11 09:08:17 +00:00
|
|
|
|
2019-10-02 15:01:52 +00:00
|
|
|
import CollectionCreate from '../components/CollectionCreate';
|
2019-08-11 09:08:17 +00:00
|
|
|
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-10-02 15:01:52 +00:00
|
|
|
isCollectionCreate() {
|
|
|
|
const path = this.props.location.pathname;
|
|
|
|
return /collections\/create$/.test(path);
|
|
|
|
}
|
|
|
|
|
|
|
|
returnToDashboard = () => {
|
|
|
|
browserHistory.push(`/${this.ownerName()}/collections`);
|
|
|
|
}
|
|
|
|
|
2019-09-17 19:32:54 +00:00
|
|
|
renderActionButton(tabKey, username) {
|
|
|
|
switch (tabKey) {
|
|
|
|
case TabKey.assets:
|
2019-11-04 19:30:24 +00:00
|
|
|
return this.isOwner() && <AssetSize />;
|
2019-09-17 19:32:54 +00:00
|
|
|
case TabKey.collections:
|
2019-11-10 20:39:22 +00:00
|
|
|
return this.isOwner() && (
|
|
|
|
<React.Fragment>
|
2020-04-19 20:45:09 +00:00
|
|
|
<Button to={`/${username}/collections/create`}>
|
2019-11-10 20:39:22 +00:00
|
|
|
Create collection
|
2020-04-19 20:45:09 +00:00
|
|
|
</Button>
|
2019-11-14 21:01:33 +00:00
|
|
|
<CollectionSearchbar />
|
2019-11-10 20:39:22 +00:00
|
|
|
</React.Fragment>);
|
2019-09-17 19:32:54 +00:00
|
|
|
case TabKey.sketches:
|
|
|
|
default:
|
2019-10-02 15:17:52 +00:00
|
|
|
return (
|
|
|
|
<React.Fragment>
|
2020-04-19 20:45:09 +00:00
|
|
|
{this.isOwner() && <Button to="/">New sketch</Button>}
|
2019-11-14 21:01:33 +00:00
|
|
|
<SketchSearchbar />
|
2019-10-02 15:17:52 +00:00
|
|
|
</React.Fragment>
|
|
|
|
);
|
2019-09-17 19:32:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-09 08:35:24 +00:00
|
|
|
renderContent(tabKey, username) {
|
|
|
|
switch (tabKey) {
|
|
|
|
case TabKey.assets:
|
2020-05-03 20:51:01 +00:00
|
|
|
return <AssetList key={username} username={username} />;
|
2019-07-09 08:35:24 +00:00
|
|
|
case TabKey.collections:
|
2020-05-03 20:51:01 +00:00
|
|
|
return <CollectionList key={username} username={username} />;
|
2019-07-09 08:35:24 +00:00
|
|
|
case TabKey.sketches:
|
|
|
|
default:
|
2020-05-03 20:51:01 +00:00
|
|
|
return <SketchList key={username} username={username} />;
|
2019-07-09 08:35:24 +00:00
|
|
|
}
|
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;
|
2019-11-04 19:30:24 +00:00
|
|
|
const actions = this.renderActionButton(currentTab, username);
|
2019-08-11 09:08:17 +00:00
|
|
|
|
|
|
|
return (
|
|
|
|
<div className="dashboard">
|
2019-09-11 18:11:20 +00:00
|
|
|
<Nav layout="dashboard" />
|
2019-08-11 09:08:17 +00:00
|
|
|
|
2020-05-19 19:34:00 +00:00
|
|
|
<main className="dashboard-header">
|
2019-08-11 09:08:17 +00:00
|
|
|
<div className="dashboard-header__header">
|
|
|
|
<h2 className="dashboard-header__header__title">{this.ownerName()}</h2>
|
2019-10-02 15:17:52 +00:00
|
|
|
<div className="dashboard-header__nav">
|
2019-09-17 19:32:54 +00:00
|
|
|
<DashboardTabSwitcher currentTab={currentTab} isOwner={isOwner} username={username} />
|
2019-11-04 19:30:24 +00:00
|
|
|
{actions &&
|
|
|
|
<div className="dashboard-header__actions">
|
|
|
|
{actions}
|
|
|
|
</div>
|
|
|
|
}
|
2019-09-17 19:32:54 +00:00
|
|
|
</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>
|
2020-05-19 19:34:00 +00:00
|
|
|
</main>
|
2019-10-02 15:01:52 +00:00
|
|
|
{this.isCollectionCreate() &&
|
|
|
|
<Overlay
|
|
|
|
title="Create collection"
|
|
|
|
closeOverlay={this.returnToDashboard}
|
|
|
|
>
|
|
|
|
<CollectionCreate />
|
|
|
|
</Overlay>
|
|
|
|
}
|
2019-08-11 09:08:17 +00:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function mapStateToProps(state) {
|
|
|
|
return {
|
|
|
|
previousPath: state.ide.previousPath,
|
|
|
|
user: state.user,
|
2019-11-04 19:30:24 +00:00
|
|
|
theme: state.preferences.theme,
|
2019-08-11 09:08:17 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
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({
|
2020-02-04 23:40:54 +00:00
|
|
|
username: PropTypes.string,
|
2019-08-11 09:08:17 +00:00
|
|
|
}),
|
|
|
|
};
|
|
|
|
|
|
|
|
export default connect(mapStateToProps, mapDispatchToProps)(DashboardView);
|