Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Porter97/91d7ae1186ac84e3e0d0ab227831efe4 to your computer and use it in GitHub Desktop.
Save Porter97/91d7ae1186ac84e3e0d0ab227831efe4 to your computer and use it in GitHub Desktop.
import React from 'react';
import agent from '../../agent'
import { connect } from 'react-redux';
import CollectionMeta from './CollectionMeta'
const mapStateToProps = state => ({
...state.collection,
currentUser: state.common.currentUser
});
const mapDispatchToProps = dispatch => ({
onLoad: payload =>
dispatch({ type: 'COLLECTION_PAGE_LOADED', payload }),
onUnload: () =>
dispatch({ type: 'COLLECTION_PAGE_UNLOADED' })
});
class Collection extends React.Component {
componentWillMount() {
this.props.onLoad(
agent.Collections.get(this.props.match.params.id)
)
}
componentWillUnmount() {
this.props.onUnload();
}
render() {
if (!this.props.collection) {
return (
<NotFound />
);
}
const canModify = this.props.currentUser &&
this.props.currentUser.username === this.props.collection.author.username;
return (
<div className="collection-page">
<div className="banner">
<div className="container">
<h1>{this.props.collection.name}</h1>
<div>{this.props.collection.description}</div>
<CollectionMeta
collection={this.props.collection}
canModify={canModify} />
</div>
</div>
<hr />
</div>
);
}
}
export default connect(mapStateToProps, mapDispatchToProps)(Collection);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment