p5.js-web-editor/client/modules/Sketch/pages/SketchListView.js

70 lines
2.1 KiB
JavaScript
Raw Normal View History

2016-07-01 17:30:40 +02:00
import React, { PropTypes } from 'react';
import { connect } from 'react-redux';
import { bindActionCreators } from 'redux';
2016-07-05 22:04:14 +02:00
import moment from 'moment';
import { Link } from 'react-router';
2016-07-01 17:30:40 +02:00
import Nav from '../../../components/Nav';
import * as SketchActions from '../actions';
import * as ProjectActions from '../../IDE/actions/project';
class SketchListView extends React.Component {
componentDidMount() {
this.props.getProjects();
}
render() {
return (
<div className="sketch-list">
<Nav
user={this.props.user}
createProject={this.props.createProject}
saveProject={this.props.saveProject}
2016-08-04 01:03:01 +02:00
exportProjectAsZip={this.props.exportProjectAsZip}
cloneProject={this.props.cloneProject}
2016-07-01 17:30:40 +02:00
/>
2016-07-12 20:00:04 +02:00
<table className="sketches-table" summary="table containing all saved projects">
2016-07-05 22:04:14 +02:00
<thead>
2016-08-04 01:03:01 +02:00
<tr>
<th scope="col">Name</th>
<th scope="col">Created</th>
<th scope="col">Last Updated</th>
</tr>
2016-07-05 22:04:14 +02:00
</thead>
<tbody>
{this.props.sketches.map(sketch =>
2016-08-04 01:03:01 +02:00
<tr className="sketches-table__row" key={sketch.id}>
2016-07-12 16:16:19 +02:00
<td scope="row"><Link to={`/projects/${sketch._id}`}>{sketch.name}</Link></td>
2016-07-05 22:04:14 +02:00
<td>{moment(sketch.createdAt).format('MMM D, YYYY')}</td>
<td>{moment(sketch.updatedAt).format('MMM D, YYYY')}</td>
</tr>
)}
</tbody>
</table>
2016-07-01 17:30:40 +02:00
</div>
);
}
}
SketchListView.propTypes = {
user: PropTypes.object.isRequired,
createProject: PropTypes.func.isRequired,
saveProject: PropTypes.func.isRequired,
getProjects: PropTypes.func.isRequired,
2016-08-04 01:03:01 +02:00
sketches: PropTypes.array.isRequired,
exportProjectAsZip: PropTypes.func.isRequired,
cloneProject: PropTypes.func.isRequired
2016-07-01 17:30:40 +02:00
};
function mapStateToProps(state) {
return {
user: state.user,
sketches: state.sketches
};
}
function mapDispatchToProps(dispatch) {
return bindActionCreators(Object.assign({}, SketchActions, ProjectActions), dispatch);
}
export default connect(mapStateToProps, mapDispatchToProps)(SketchListView);