diff --git a/webapp/components/comment.jsx b/webapp/components/comment.jsx index 2cb6c5c..2e4f193 100644 --- a/webapp/components/comment.jsx +++ b/webapp/components/comment.jsx @@ -6,32 +6,32 @@ var Link = require('react-router').Link var UserID = require('userID.jsx') var Comment = React.createClass({ - getInitialState: function () { + getInitialState () { return { moment: false } }, - componentDidMount: function () { + componentDidMount () { require.ensure(['moment'], _ => { if (this.isMounted()) this.setState({ moment: require('moment') }) }) }, - getPermalink: function () { + getPermalink () { if (this.props.adminID && this.props.board && this.props.post && this.props.comment.hash) { return
Permalink
} }, - getParentlink: function () { + getParentlink () { if (this.props.showParent && this.props.comment.parent && this.props.comment.parent !== this.props.post) { return
Parent
} }, - getComments: function () { + getComments () { return }, - render: function () { + render () { if (this.props.comment) { return

@@ -49,10 +49,10 @@ var Comment = React.createClass({ }) var Comments = React.createClass({ - getInitialState: function () { + getInitialState () { return { comments: [] } }, - componentDidMount: function () { + componentDidMount () { var boards = this.props.api if (boards) { boards.getEventEmitter().on('comment for ' + this.props.parent, cmnt => { @@ -68,13 +68,13 @@ var Comments = React.createClass({ }) } }, - getComments: function () { + getComments () { if (this.state.comments.length > 0) { return this.state.comments.map(cmnt => ()) } else return
}, - render: function () { + render () { return
{this.getComments()}
} }) diff --git a/webapp/components/post.jsx b/webapp/components/post.jsx index cd8fe11..70e0514 100644 --- a/webapp/components/post.jsx +++ b/webapp/components/post.jsx @@ -4,14 +4,19 @@ var Icon = require('icon.jsx') var Link = require('react-router').Link var Clock = require('clock.jsx') var UserID = require('userID.jsx') -var { Error, Loading } = require('status-components.jsx') +var { Error } = require('status-components.jsx') module.exports = React.createClass({ getInitialState () { return { loading: true } }, componentDidMount () { - this.init(this.props) + if (this.props.api) { + this.props.api.getEventEmitter().on('init', err => { + if (!err) this.init(this.props) + }) + if (this.props.api.isInit) this.init(this.props) + } }, componentWillReceiveProps (props) { this.init(props) @@ -52,7 +57,12 @@ module.exports = React.createClass({ if (this.state.error) { return } else if (this.state.loading) { - return + return
+
+ +
+
Downloading Post
+
} else { return
{ this.state.post.title diff --git a/webapp/components/postlist.jsx b/webapp/components/postlist.jsx index 5d75e61..604f6aa 100644 --- a/webapp/components/postlist.jsx +++ b/webapp/components/postlist.jsx @@ -4,14 +4,20 @@ var Icon = require('icon.jsx') var Post = require('post.jsx') module.exports = React.createClass({ - getInitialState: function () { + getInitialState () { return { posts: [], api: false } }, - sortFn: function (a, b) { + sortFn (a, b) { return (b.date || 0) - (a.date || 0) }, - init: function (boards) { + componentWillReceiveProps (props) { + if (props.api) { + this.init(props.api, props) + } + }, + init (boards, props) { if (this.state.init) return + props = props || this.props this.setState({ api: true }) var onPost = (hash, date, post) => { if (!this.isMounted()) return true @@ -27,11 +33,11 @@ module.exports = React.createClass({ }*/ this.setState({ posts }) } - boards.getEventEmitter().on('post in ' + this.props.board + (this.props.admin ? '@' + this.props.admin : ''), onPost) - boards.getPostsInBoard(this.props.admin, this.props.board) + boards.getEventEmitter().on('post in ' + props.board + (props.admin ? '@' + props.admin : ''), onPost) + boards.getPostsInBoard(props.admin, props.board) this.setState({ init: true }) }, - componentDidMount: function () { + componentDidMount () { var boards = this.props.api if (boards) { if (boards.isInit) { @@ -43,7 +49,7 @@ module.exports = React.createClass({ } } }, - getPosts: function () { + getPosts () { if (this.state.posts.length > 0 || this.state.api) { return this.state.posts.map(hash => { return @@ -54,7 +60,7 @@ module.exports = React.createClass({
} }, - render: function () { + render () { return (
{this.getPosts()} diff --git a/webapp/components/status-components.jsx b/webapp/components/status-components.jsx index 4406265..1c71c7a 100644 --- a/webapp/components/status-components.jsx +++ b/webapp/components/status-components.jsx @@ -16,24 +16,13 @@ var Error = React.createClass({ var Loading = React.createClass({ render () { - // TODO: merge these (duplicated code) and use css to get desired style - if (this.props.small) { - return
-
- -
{this.props.title}
- { this.props.children } -
+ return
+
+ +

{this.props.title}

+ { this.props.children }
- } else { - return
-
- -

{this.props.title}

- { this.props.children } -
-
- } +
} }) diff --git a/webapp/components/userID.jsx b/webapp/components/userID.jsx index 99e430f..d16a065 100644 --- a/webapp/components/userID.jsx +++ b/webapp/components/userID.jsx @@ -3,22 +3,28 @@ var Icon = require('icon.jsx') var Link = require('react-router').Link module.exports = React.createClass({ - getInitialState: function () { + getInitialState () { return { } }, - componentDidMount: function () { - var boards = this.props.api + componentWillReceiveProps (props) { + this.init(props) + }, + componentDidMount () { + this.init() + }, + init (props) { + props = props || this.props + var boards = props.api if (boards) { + boards.getEventEmitter().on('init', err => { + if (!err && this.isMounted()) this.getProfile(boards) + }) if (boards.isInit) { this.getProfile(boards) } - boards.getEventEmitter().on('init', err => { - if (!err && this.isMounted()) this.getProfile(boards) - else console.log('ERR INIT', err) - }) } }, - getProfile: function (boards) { + getProfile (boards) { if (this.props.id === undefined) return boards.getProfile(this.props.id, (err, res) => { if (!this.isMounted()) return true @@ -29,14 +35,14 @@ module.exports = React.createClass({ } }) }, - getContent: function () { + getContent () { if (this.state.name) { return () } else { return '@' } }, - render: function () { + render () { if (this.props.id === undefined || this.props.id === 'undefined') { return
Unknown User diff --git a/webapp/pages/board.jsx b/webapp/pages/board.jsx index 2dc9c44..6b36f1f 100644 --- a/webapp/pages/board.jsx +++ b/webapp/pages/board.jsx @@ -14,13 +14,6 @@ module.exports = function (boardsAPI) { }, componentDidMount () { boardsAPI.use(boards => { - /* - When a component inside the component being rendered by the router also needs - access to the boards api, it appears unitialized and never initializes to it - for no apparent reason. Calling init twice (one automgically and one - when the root component mounts) works as a cheap, horrible workaround - */ - boards.init() if (!this.isMounted()) return var ee = boards.getEventEmitter() ee.on('init', err => { diff --git a/webapp/pages/postpage.jsx b/webapp/pages/postpage.jsx index cb03de6..f23c569 100644 --- a/webapp/pages/postpage.jsx +++ b/webapp/pages/postpage.jsx @@ -12,27 +12,15 @@ module.exports = function (boardsAPI) { }, componentDidMount: function () { boardsAPI.use(boards => { - boards.getEventEmitter().on('init', err => { - if (!err && this.isMounted()) { - this.init(boards) - } - }) - if (this.isMounted() && boards.isInit) { - this.init(boards) - } - boards.init() + this.setState({ api: boards }) }) }, - init: function (boards) { - if (this.state.init) return - this.setState({ api: boards }) - }, getContext: function () { if (this.props.params.userid) { if (this.props.params.boardname) { - return
Posted by in #{this.props.params.boardname}
+ return
Posted by in #{this.props.params.boardname}
} else { - return
Posted by
+ return
Posted by
} } else return
You are viewing a single post
},