diff --git a/webapp/components/comment.jsx b/webapp/components/comment.jsx index d6db7a1..51a4ff5 100644 --- a/webapp/components/comment.jsx +++ b/webapp/components/comment.jsx @@ -41,7 +41,7 @@ var Comment = React.createClass({ {this.getParentlink()} -
+
{this.getComments()} } else { return

Invalid Comment
} diff --git a/webapp/components/post.jsx b/webapp/components/post.jsx index 58849c7..fde886c 100644 --- a/webapp/components/post.jsx +++ b/webapp/components/post.jsx @@ -3,41 +3,39 @@ var Markdown = require('markdown.jsx') var Icon = require('icon.jsx') var Link = require('react-router').Link var Clock = require('clock.jsx') +var UserID = require('userID.jsx') -module.exports = function(){ - var UserID = require('userID.jsx')() - return React.createClass({ - getInitialState: function(){ - return { moment: false } - }, - componentDidMount: function(){ - require.ensure(['moment'],_ => { - if(this.isMounted()) this.setState({ moment: require('moment') }) - }) - }, - postLink: function(){ - if(this.props.post.op){ - if(this.props.board){ - return '/@'+this.props.post.op+'/'+this.props.board+'/'+this.props.post.hash - } else { - return '/@'+this.props.post.op+'/post/'+this.props.post.hash - } +module.exports = React.createClass({ + getInitialState: function(){ + return { moment: false } + }, + componentDidMount: function(){ + require.ensure(['moment'],_ => { + if(this.isMounted()) this.setState({ moment: require('moment') }) + }) + }, + postLink: function(){ + if(this.props.post.op){ + if(this.props.board){ + return '/@'+this.props.post.op+'/'+this.props.board+'/'+this.props.post.hash } else { - return '/post/'+this.props.post.hash + return '/@'+this.props.post.op+'/post/'+this.props.post.hash } - }, - render: function(){ - return
-
-
{this.props.post.title}

-
-
- - - View -
+ } else { + return '/post/'+this.props.post.hash + } + }, + render: function(){ + return
+
+
{this.props.post.title}

+
+
+ + + View
- } - }) -} +
+ } +}) diff --git a/webapp/components/postlist.jsx b/webapp/components/postlist.jsx index 31fd63f..590e472 100644 --- a/webapp/components/postlist.jsx +++ b/webapp/components/postlist.jsx @@ -1,58 +1,56 @@ var React = require('react') var sortedIndex = require('lodash.sortedindex') var Icon = require('icon.jsx') +var Post = require('post.jsx') -module.exports = function(){ - var Post = require('post.jsx')() - return React.createClass({ - getInitialState: function(){ - return { posts: [], api: false } - }, - sortFn: function(a,b){ - return (b.date || 0) - (a.date || 0) - }, - init: function(boards){ - this.setState({ api: true }) - boards.getPostsInBoard(this.props.admin,this.props.board) - .on('post in '+this.props.board+(this.props.admin?'@'+this.props.admin:''),(post,hash) => { - if(!this.isMounted()) return true - var now = (new Date()).getTime() - var posts = this.state.posts - if(post.date === undefined || post.date <= 0){ - posts.push(post) - } else if(post.date <= now){ - var i = sortedIndex(posts,post,(p) => now-p.date || now) - posts.splice(i,0,post) - } else { - console.log('Post discarded cause date in the future:',post) - } - this.setState({ posts }) - }) - }, - componentDidMount: function(){ - var boards = this.props.api - if(boards){ - if(boards.isInit) this.init(boards) - else boards.getEventEmitter().on('init',err => { - if(!err && this.isMounted()) this.init(boards) - }) +module.exports = React.createClass({ + getInitialState: function(){ + return { posts: [], api: false } + }, + sortFn: function(a,b){ + return (b.date || 0) - (a.date || 0) + }, + init: function(boards){ + this.setState({ api: true }) + boards.getPostsInBoard(this.props.admin,this.props.board) + .on('post in '+this.props.board+(this.props.admin?'@'+this.props.admin:''),(post,hash) => { + if(!this.isMounted()) return true + var now = (new Date()).getTime() + var posts = this.state.posts + if(post.date === undefined || post.date <= 0){ + posts.push(post) + } else if(post.date <= now){ + var i = sortedIndex(posts,post,(p) => now-p.date || now) + posts.splice(i,0,post) + } else { + console.log('Post discarded cause date in the future:',post) } - }, - getPosts: function(){ - if(this.state.posts.length > 0 || this.state.api){ - return this.state.posts.map(post => { - return - }) - } else return
- -
- }, - render: function(){ - return ( -
- {this.getPosts()} -
- ) + this.setState({ posts }) + }) + }, + componentDidMount: function(){ + var boards = this.props.api + if(boards){ + if(boards.isInit) this.init(boards) + else boards.getEventEmitter().on('init',err => { + if(!err && this.isMounted()) this.init(boards) + }) } - }) -} + }, + getPosts: function(){ + if(this.state.posts.length > 0 || this.state.api){ + return this.state.posts.map(post => { + return + }) + } else return
+ +
+ }, + render: function(){ + return ( +
+ {this.getPosts()} +
+ ) + } +}) diff --git a/webapp/components/userID.jsx b/webapp/components/userID.jsx index fc84d78..b8ef4ff 100644 --- a/webapp/components/userID.jsx +++ b/webapp/components/userID.jsx @@ -2,52 +2,50 @@ var React = require('react') var Icon = require('icon.jsx') var Link = require('react-router').Link -module.exports = function(){ - return React.createClass({ - getInitialState: function(){ - return { } - }, - componentDidMount: function(){ - var boards = this.props.api - if(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) - }) +module.exports = React.createClass({ + getInitialState: function(){ + return { } + }, + componentDidMount: function(){ + var boards = this.props.api + if(boards){ + if(boards.isInit){ + this.getProfile(boards) } - }, - getProfile: function(boards){ - if(this.props.id === undefined) return - boards.getProfile(this.props.id, (err,res) => { - if(!this.isMounted()) return true - if(err){ - console.log('Error while resolving user badge:',err) - } else { - this.setState({ name: res.name || 'Unknown Name' }) - } + boards.getEventEmitter().on('init',err => { + if(!err && this.isMounted()) this.getProfile(boards) + else console.log('ERR INIT',err) }) - }, - getContent: function(){ - if(this.state.name){ - return () - } else { - return '@' - } - }, - render: function(){ - if(this.props.id === undefined || this.props.id === 'undefined') - return
- Unknown User -
- else - return (
- - {this.getContent()}{this.state.name || this.props.id} - -
) } - }) -} + }, + getProfile: function(boards){ + if(this.props.id === undefined) return + boards.getProfile(this.props.id, (err,res) => { + if(!this.isMounted()) return true + if(err){ + console.log('Error while resolving user badge:',err) + } else { + this.setState({ name: res.name || 'Unknown Name' }) + } + }) + }, + getContent: function(){ + if(this.state.name){ + return () + } else { + return '@' + } + }, + render: function(){ + if(this.props.id === undefined || this.props.id === 'undefined') + return
+ Unknown User +
+ else + return (
+ + {this.getContent()}{this.state.name || this.props.id} + +
) + } +}) diff --git a/webapp/pages/board.jsx b/webapp/pages/board.jsx index 0c6f787..d0f78ee 100644 --- a/webapp/pages/board.jsx +++ b/webapp/pages/board.jsx @@ -2,11 +2,11 @@ var React = require('react') var Markdown = require('markdown.jsx') var Link = require('react-router').Link var Icon = require('icon.jsx') +var UserID = require('userID.jsx') +var PostList = require('postlist.jsx') +var GetIPFS = require('getipfs.jsx') module.exports = function(boardsAPI){ - var UserID = require('userID.jsx')() - var PostList = require('postlist.jsx')() - var GetIPFS = require('getipfs.jsx')() return React.createClass({ getInitialState: function(){ return { name: this.props.params.boardname, api: false } diff --git a/webapp/pages/commentpage.jsx b/webapp/pages/commentpage.jsx index 347a5d1..517e094 100644 --- a/webapp/pages/commentpage.jsx +++ b/webapp/pages/commentpage.jsx @@ -1,13 +1,12 @@ var React = require('react') var Link = require('react-router').Link var Icon = require('icon.jsx') +var UserID = require('userID.jsx') +var GetIPFS = require('getipfs.jsx') +var Post = require('post.jsx') +var Comment = require('comment.jsx').Comment module.exports = function(boardsAPI){ - var UserID = require('userID.jsx')() - var GetIPFS = require('getipfs.jsx')() - var Post = require('post.jsx')() - var Comment = require('comment.jsx').Comment - return React.createClass({ getInitialState: function(){ return { parent: false, api: false } @@ -25,6 +24,11 @@ module.exports = function(boardsAPI){ } }) }, + componentWillReceiveProps: function(nextProps) { + if(nextProps.params.commenthash !== this.props.params.commenthash){ + location.reload() // cheap hack, should swap with something more efficient + } + }, init: function(boards){ if(this.state.init) return this.setState({ api: true, boards: boards }) diff --git a/webapp/pages/getipfs.jsx b/webapp/pages/getipfs.jsx index 8993bcc..588a29f 100644 --- a/webapp/pages/getipfs.jsx +++ b/webapp/pages/getipfs.jsx @@ -2,65 +2,63 @@ var React = require('react') var Link = require('react-router').Link var Icon = require('icon.jsx') -module.exports = function(){ - return React.createClass({ - getInitialState: function(){ - return { connected: false, error: false, long: false } - }, - componentDidMount: function(){ - var boards = this.props.api - if(boards){ - if(!this.isMounted()) return - if(boards.isInit){ - this.setState({ connected: true }) - } else { - setTimeout(_ => { - if(this.isMounted()) this.setState({ long: true }) - }, 5000) - boards.getEventEmitter().on('init', err => { - if(!this.isMounted()) return - if(err){ - this.setState({ error: true }) - } else { - this.setState({ connected: true }) - } - }) - } - } - }, - render: function(){ - var opt = require('options.jsx').get() - if(this.state.error){ - return ( -
-

Connection to IPFS not available

-

Sorry, but at the moment an external application is needed to try the Prototype

-

You don't have an IPFS node running at {opt.addr}:{opt.port} or it is not reachable. - The IPFS Boards prototype requires a full IPFS node. Please start one by following the - go-ipfs documentation.

-
Do you have a running node but the app won't work?
-

It's probably one of these issues:

-
    -
  • Your node is not located at {opt.addr}:{opt.port}. Go to the Settings Page to configure the connection.
  • -
  • You edited your settings and saved them but didn't reload the page
  • -
  • Your IPFS node doesn't allow requests from the domain you're running the app from (CORS issue). See here for the fix.
  • -
  • You're downloading the app via `https`: at the moment, connecting to IPFS only works if you donwload the app via plain HTTP. If you're using `ipfs.io` please consider accessing the app via a local gateway like `localhost:8080`
  • -
  • Some other networking or browser security issue is preventing the App from talking to your node.
  • -
-

Still can't fix it? File a issue on GitHub, we'll be happy to help!

-
- )} else if(this.state.connected){ - return
-

-
You're connected!
-
+module.exports = React.createClass({ + getInitialState: function(){ + return { connected: false, error: false, long: false } + }, + componentDidMount: function(){ + var boards = this.props.api + if(boards){ + if(!this.isMounted()) return + if(boards.isInit){ + this.setState({ connected: true }) } else { - return
- -

Connecting to IPFS

- {this.state.long?(

It's taking long... there's probably something wrong

):

} -
+ setTimeout(_ => { + if(this.isMounted()) this.setState({ long: true }) + }, 5000) + boards.getEventEmitter().on('init', err => { + if(!this.isMounted()) return + if(err){ + this.setState({ error: true }) + } else { + this.setState({ connected: true }) + } + }) } } - }) -} + }, + render: function(){ + var opt = require('options.jsx').get() + if(this.state.error){ + return ( +
+

Connection to IPFS not available

+

Sorry, but at the moment an external application is needed to try the Prototype

+

You don't have an IPFS node running at {opt.addr}:{opt.port} or it is not reachable. + The IPFS Boards prototype requires a full IPFS node. Please start one by following the + go-ipfs documentation.

+
Do you have a running node but the app won't work?
+

It's probably one of these issues:

+
    +
  • Your node is not located at {opt.addr}:{opt.port}. Go to the Settings Page to configure the connection.
  • +
  • You edited your settings and saved them but didn't reload the page
  • +
  • Your IPFS node doesn't allow requests from the domain you're running the app from (CORS issue). See here for the fix.
  • +
  • You're downloading the app via `https`: at the moment, connecting to IPFS only works if you donwload the app via plain HTTP. If you're using `ipfs.io` please consider accessing the app via a local gateway like `localhost:8080`
  • +
  • Some other networking or browser security issue is preventing the App from talking to your node.
  • +
+

Still can't fix it? File a issue on GitHub, we'll be happy to help!

+
+ )} else if(this.state.connected){ + return
+

+
You're connected!
+
+ } else { + return
+ +

Connecting to IPFS

+ {this.state.long?(

It's taking long... there's probably something wrong

):

} +
+ } + } +}) diff --git a/webapp/pages/postpage.jsx b/webapp/pages/postpage.jsx index 8575417..2133f1c 100644 --- a/webapp/pages/postpage.jsx +++ b/webapp/pages/postpage.jsx @@ -1,12 +1,11 @@ var React = require('react') var Link = require('react-router').Link +var UserID = require('userID.jsx') +var GetIPFS = require('getipfs.jsx') +var Post = require('post.jsx') +var Comments = require('comment.jsx').Comments module.exports = function(boardsAPI){ - var UserID = require('userID.jsx')() - var GetIPFS = require('getipfs.jsx')() - var Post = require('post.jsx')() - var Comments = require('comment.jsx').Comments - return React.createClass({ getInitialState: function(){ return { post: { title: '...', text: '...' }, api: false } diff --git a/webapp/pages/profile.jsx b/webapp/pages/profile.jsx index b8084fe..a8ad67d 100644 --- a/webapp/pages/profile.jsx +++ b/webapp/pages/profile.jsx @@ -2,9 +2,9 @@ var React = require('react') var Markdown = require('markdown.jsx') var Link = require('react-router').Link var Icon = require('icon.jsx') +var GetIPFS = require('getipfs.jsx') module.exports = function(boardsAPI){ - var GetIPFS = require('getipfs.jsx')(boardsAPI) return React.createClass({ getInitialState: function(){ return { name: '...', boards: [], api: false } diff --git a/webapp/pages/users.jsx b/webapp/pages/users.jsx index 46bd53e..5ec4e24 100644 --- a/webapp/pages/users.jsx +++ b/webapp/pages/users.jsx @@ -1,9 +1,9 @@ var React = require('react') var Icon = require('icon.jsx') +var GetIPFS = require('getipfs.jsx') +var UserID = require('userID.jsx') module.exports = function(boardsAPI){ - var GetIPFS = require('getipfs.jsx')() - var UserID = require('userID.jsx')() return React.createClass({ getInitialState: function(){ return { users: [], api: false }