var React = require('react') var moment = require('moment') var _ = require('lodash') var CodeEditor = require('./CodeEditor') var MarkdownPreview = require('./MarkdownPreview') var ModeIcon = require('./ModeIcon') var Select = require('react-select') var Modal = require('../Mixins/Modal') var ForceUpdate = require('../Mixins/ForceUpdate') var LinkedState = require('../Mixins/LinkedState') var aceModes = require('../../../modules/ace-modes') var modeOptions = aceModes.map(function (mode) { return { label: mode, value: mode } }) module.exports = React.createClass({ mixins: [ForceUpdate(60000), Modal, LinkedState], propTypes: { currentArticle: React.PropTypes.object, showOnlyWithTag: React.PropTypes.func, planet: React.PropTypes.object, switchDetailMode: React.PropTypes.func, user: React.PropTypes.shape({ id: React.PropTypes.number, name: React.PropTypes.string, Folders: React.PropTypes.array }), article: React.PropTypes.object, saveCurrentArticle: React.PropTypes.func, detailMode: React.PropTypes.string }, getInitialState: function () { var article = this.props.currentArticle != null ? { id: this.props.currentArticle.id, title: this.props.currentArticle.title, content: this.props.currentArticle.CurrentRevision.title, tags: this.props.currentArticle.Tags.map(function (tag) { return tag.name }), mode: this.props.currentArticle.mode, status: this.props.currentArticle.status } : null // console.log('init staet') // console.log(article) return { isEditModalOpen: false, article: article } }, componentWillReceiveProps: function (nextProps) { if (nextProps.detailMode === 'edit') { var article = { id: nextProps.currentArticle.id, title: nextProps.currentArticle.title, content: nextProps.currentArticle.CurrentRevision.content, tags: nextProps.currentArticle.Tags.map(function (tag) { return tag.name }), mode: nextProps.currentArticle.mode, FolderId: nextProps.currentArticle.FolderId, status: nextProps.currentArticle.status } this.setState({article: article}) } }, openDeleteModal: function () { if (this.props.article == null) return }, handleFolderIdChange: function (FolderId) { this.state.article.FolderId = FolderId this.setState({article: this.state.article}) }, handleTagsChange: function (tag, tags) { tags = _.uniq(tags, function (tag) { return tag.value }) this.state.article.tags = tags.map(function (tag) { return tag.value }) this.setState({article: this.state.article}) }, handleModeChange: function (mode) { this.state.article.mode = mode this.setState({article: this.state.article}) }, handleContentChange: function (e, value) { var article = this.state.article article.content = value this.setState({article: article}) }, saveArticle: function () { if (this.state.article.mode === '') { return this.refs.mode.focus() } if (this.state.article.FolderId === '') { return this.refs.folder.focus() } this.props.saveCurrentArticle(this.state.article) }, render: function () { if (this.props.currentArticle == null) { return (