import React, { PropTypes } from 'react' import api from 'boost/api' import linkState from 'boost/linkState' import FolderMark from 'boost/components/FolderMark' const IDLE = 'IDLE' const EDIT = 'EDIT' const DELETE = 'DELETE' export default class FolderRow extends React.Component { constructor (props) { super(props) this.state = { mode: IDLE, name: props.folder.name, public: props.folder.public } } handleCancelButtonClick (e) { this.setState({ mode: IDLE, name: this.props.folder.name, public: this.props.folder.public }) } handleEditButtonClick (e) { this.setState({mode: EDIT}) } handleDeleteButtonClick (e) { this.setState({mode: DELETE}) } handleFolderPublicChange (e) { this.setState({public: e.target.value}) } handleSaveButtonClick (e) { let input = { name: this.state.name, public: !!parseInt(this.state.public, 10) } api.updateFolder(this.props.folder.id, input) .then(res => { console.log(res.body) this.setState({mode: IDLE}) }) .catch(err => { if (err.status != null) throw err else console.error(err) }) } handleDeleteConfirmButtonClick (e) { api.destroyFolder(this.props.folder.id) .then(res => { console.log(res.body) }) .catch(err => { if (err.status != null) throw err else console.error(err) }) } render () { let folder = this.props.folder switch (this.state.mode) { case EDIT: return (
) case DELETE: return (
Are you sure to delete {folder.name} folder?
) case IDLE: default: return (
{folder.name}
{folder.public ? 'Public' : 'Private'}
) } } } FolderRow.propTypes = { folder: PropTypes.shape() } FolderRow.prototype.linkState = linkState