2019-07-09 16:24:09 +00:00
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import React from 'react';
|
|
|
|
import { connect } from 'react-redux';
|
2019-09-25 17:20:49 +00:00
|
|
|
import Nav from '../../../components/Nav';
|
2019-07-09 16:24:09 +00:00
|
|
|
|
|
|
|
import CollectionCreate from '../components/CollectionCreate';
|
2019-09-08 16:54:49 +00:00
|
|
|
import Collection from '../components/Collection';
|
2019-07-09 16:24:09 +00:00
|
|
|
|
|
|
|
class CollectionView extends React.Component {
|
|
|
|
static defaultProps = {
|
|
|
|
user: null,
|
|
|
|
};
|
|
|
|
|
|
|
|
componentDidMount() {
|
|
|
|
document.body.className = this.props.theme;
|
|
|
|
}
|
|
|
|
|
|
|
|
ownerName() {
|
|
|
|
if (this.props.params.username) {
|
|
|
|
return this.props.params.username;
|
|
|
|
}
|
|
|
|
|
|
|
|
return this.props.user.username;
|
|
|
|
}
|
|
|
|
|
|
|
|
pageTitle() {
|
|
|
|
if (this.isCreatePage()) {
|
|
|
|
return 'Create collection';
|
|
|
|
}
|
|
|
|
|
|
|
|
return 'collection';
|
|
|
|
}
|
|
|
|
|
|
|
|
isOwner() {
|
|
|
|
return this.props.user.username === this.props.params.username;
|
|
|
|
}
|
|
|
|
|
|
|
|
isCreatePage() {
|
|
|
|
const path = this.props.location.pathname;
|
|
|
|
return /create$/.test(path);
|
|
|
|
}
|
|
|
|
|
|
|
|
renderContent() {
|
|
|
|
if (this.isCreatePage() && this.isOwner()) {
|
|
|
|
return <CollectionCreate />;
|
|
|
|
}
|
|
|
|
|
2019-09-08 16:54:49 +00:00
|
|
|
return (
|
|
|
|
<Collection
|
|
|
|
collectionId={this.props.params.collection_id}
|
|
|
|
username={this.props.params.username}
|
|
|
|
/>
|
|
|
|
);
|
2019-07-09 16:24:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
return (
|
|
|
|
<div className="dashboard">
|
2020-01-15 17:10:51 +00:00
|
|
|
<Nav layout="dashboard" />
|
2019-07-09 16:24:09 +00:00
|
|
|
|
2019-09-08 16:54:49 +00:00
|
|
|
{this.renderContent()}
|
2019-07-09 16:24:09 +00:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function mapStateToProps(state) {
|
|
|
|
return {
|
|
|
|
user: state.user,
|
|
|
|
theme: state.preferences.theme
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
function mapDispatchToProps(dispatch) {
|
2020-04-10 17:58:55 +00:00
|
|
|
return {};
|
2019-07-09 16:24:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
CollectionView.propTypes = {
|
|
|
|
location: PropTypes.shape({
|
|
|
|
pathname: PropTypes.string.isRequired,
|
|
|
|
}).isRequired,
|
|
|
|
params: PropTypes.shape({
|
2019-09-08 16:54:49 +00:00
|
|
|
collection_id: PropTypes.string.isRequired,
|
2019-07-09 16:24:09 +00:00
|
|
|
username: PropTypes.string.isRequired,
|
|
|
|
}).isRequired,
|
|
|
|
theme: PropTypes.string.isRequired,
|
|
|
|
user: PropTypes.shape({
|
2020-04-10 17:58:55 +00:00
|
|
|
username: PropTypes.string,
|
2019-07-09 16:24:09 +00:00
|
|
|
}),
|
|
|
|
};
|
|
|
|
|
|
|
|
export default connect(mapStateToProps, mapDispatchToProps)(CollectionView);
|