2016-08-15 21:06:12 +00:00
|
|
|
import React, { PropTypes } from 'react';
|
|
|
|
import { connect } from 'react-redux';
|
|
|
|
import { bindActionCreators } from 'redux';
|
|
|
|
import moment from 'moment';
|
|
|
|
import { Link } from 'react-router';
|
|
|
|
import * as SketchActions from '../actions/projects';
|
|
|
|
import * as ProjectActions from '../actions/project';
|
|
|
|
import InlineSVG from 'react-inlinesvg';
|
|
|
|
const exitUrl = require('../../../images/exit.svg');
|
2016-10-12 18:24:53 +00:00
|
|
|
const trashCan = require('../../../images/trash-can.svg');
|
2016-08-15 21:06:12 +00:00
|
|
|
|
|
|
|
class SketchList extends React.Component {
|
|
|
|
componentDidMount() {
|
2016-08-17 19:53:25 +00:00
|
|
|
this.props.getProjects(this.props.username);
|
2016-08-24 17:30:50 +00:00
|
|
|
document.getElementById('sketchlist').focus();
|
2016-08-15 21:06:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
return (
|
2016-08-24 17:30:50 +00:00
|
|
|
<section className="sketch-list" aria-label="project list" tabIndex="0" role="main" id="sketchlist">
|
2016-08-15 21:06:12 +00:00
|
|
|
<header className="sketch-list__header">
|
|
|
|
<h2>Sketches</h2>
|
2016-08-24 17:30:50 +00:00
|
|
|
<button className="sketch-list__exit-button" onClick={this.props.closeSketchList}>
|
2016-08-15 21:06:12 +00:00
|
|
|
<InlineSVG src={exitUrl} alt="Close Sketch List Overlay" />
|
|
|
|
</button>
|
|
|
|
</header>
|
|
|
|
<div className="sketches-table-container">
|
|
|
|
<table className="sketches-table" summary="table containing all saved projects">
|
|
|
|
<thead>
|
|
|
|
<tr>
|
2016-10-12 18:24:53 +00:00
|
|
|
<th className="sketch-list__trash-column" scope="col"></th>
|
2016-08-15 21:06:12 +00:00
|
|
|
<th scope="col">Name</th>
|
|
|
|
<th scope="col">Created</th>
|
|
|
|
<th scope="col">Last Updated</th>
|
|
|
|
</tr>
|
|
|
|
</thead>
|
|
|
|
<tbody>
|
|
|
|
{this.props.sketches.map(sketch =>
|
2016-10-12 18:24:53 +00:00
|
|
|
<tr className="sketches-table__row visibility-toggle" key={sketch.id}>
|
|
|
|
<td>
|
|
|
|
<button
|
|
|
|
className="sketch-list__trash-button"
|
|
|
|
onClick={() => {
|
|
|
|
if (window.confirm(`Are you sure you want to delete "${sketch.name}"?`)) {
|
|
|
|
this.props.deleteProject(sketch.id);
|
|
|
|
}
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<InlineSVG src={trashCan} alt="Delete Project" />
|
|
|
|
</button>
|
|
|
|
</td>
|
2016-08-15 21:06:12 +00:00
|
|
|
<td scope="row"><Link to={`/projects/${sketch._id}`}>{sketch.name}</Link></td>
|
2016-08-15 21:14:55 +00:00
|
|
|
<td>{moment(sketch.createdAt).format('MMM D, YYYY h:mm:ss A')}</td>
|
|
|
|
<td>{moment(sketch.updatedAt).format('MMM D, YYYY h:mm:ss A')}</td>
|
2016-08-15 21:06:12 +00:00
|
|
|
</tr>
|
|
|
|
)}
|
|
|
|
</tbody>
|
|
|
|
</table>
|
|
|
|
</div>
|
2016-08-24 17:30:50 +00:00
|
|
|
</section>
|
2016-08-15 21:06:12 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
SketchList.propTypes = {
|
|
|
|
user: PropTypes.object.isRequired,
|
|
|
|
getProjects: PropTypes.func.isRequired,
|
|
|
|
sketches: PropTypes.array.isRequired,
|
2016-08-17 19:53:25 +00:00
|
|
|
closeSketchList: PropTypes.func.isRequired,
|
2016-10-12 18:24:53 +00:00
|
|
|
username: PropTypes.string,
|
|
|
|
deleteProject: PropTypes.func.isRequired
|
2016-08-15 21:06:12 +00: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)(SketchList);
|