var React = require('react')
var Markdown = require('markdown.jsx')
var Icon = require('icon.jsx')
var Clock = require('clock.jsx')
var Link = require('react-router').Link
var UserID = require('userID.jsx')
var { Error, Success } = require('status-components.jsx')
var CommentEditor = React.createClass({
getInitialState () {
return { }
},
componentDidMount () {
this.init(this.props)
},
componentWillReceiveProps (props) {
this.init(props)
},
init (props) {
this.setState({ api: props.api })
},
handleChange (event) {
var obj = {}
obj[event.target.id] = event.target.value
this.setState(obj)
},
save () {
var boards = this.props.api
var comment = { text: this.state.text }
this.setState({ loading: true })
boards.createComment(comment, this.props.parent, (err, hash) => {
if (err) {
this.setState({ loading: false, error: err })
} else {
this.setState({ loading: false, success: true, hash })
}
})
},
render () {
if (this.state.error) {
return
} else if (this.state.loading) {
return
Publishing Comment
} else if (this.state.success) {
var url = '/@' + this.props.adminID + '/' + this.props.board + '/' + (this.props.post || this.props.parent) + '/' + this.state.hash
return
View
} else {
return
Note: this version of the app doesn't check wether you are allowed to post on this board, so there are no guarantees that your post will be visible.
}
}
})
var Comment = React.createClass({
getInitialState () {
return { moment: false }
},
componentDidMount () {
require.ensure(['moment'], _ => {
if (this.isMounted()) this.setState({ moment: require('moment') })
})
},
getPermalink () {
if (this.props.adminID && this.props.board && this.props.post && this.props.comment.hash) {
return
Permalink
}
},
getParentlink () {
if (this.props.showParent && this.props.comment.parent) {
return
Parent
}
},
getComments () {
return
},
toggleReply () {
this.setState({ reply: !this.state.reply })
},
render () {
if (this.props.comment) {
return
{this.getPermalink()}
{ this.props.allowReply
?
Reply
:
}
{this.getParentlink()}
{ this.state.reply
?
:
}
{this.getComments()}
} else {
return
Invalid Comment
}
}
})
var Comments = React.createClass({
getInitialState () {
return { comments: [] }
},
componentDidMount () {
if (this.props.api) this.init(this.props.api)
},
componentWillReceiveProps (props) {
if (props.api !== this.props.api) this.init(props.api)
},
init (boards) {
boards.getEventEmitter().on('comment for ' + this.props.parent, cmnt => {
if (this.isMounted()) this.setState({ comments: this.state.comments.concat(cmnt) })
})
boards.getEventEmitter().on('init', (err, limited) => {
if (!this.isMounted()) return
if (!err) {
boards.getCommentsFor(this.props.parent, this.props.board, this.props.adminID)
}
if (limited) this.setState({ limited })
})
if (boards.isInit) {
boards.getCommentsFor(this.props.parent, this.props.board, this.props.adminID)
}
if (boards.limited) this.setState({ limited: true })
},
getComments () {
if (this.state.comments.length > 0) {
return this.state.comments.map(cmnt => ())
} else return
},
render () {
if (this.state.limited) {
return
Comments can't be displayed in limited mode
} else {
return {this.getComments()}
}
}
})
module.exports = { Comment, Comments, CommentEditor }