From 002396c98df0a2d8bd34e69c8bba587d115b8aae Mon Sep 17 00:00:00 2001 From: Enrico Fasoli Date: Mon, 23 Nov 2015 13:00:49 +0100 Subject: [PATCH] finished post linking --- webapp/app.jsx | 4 ++++ webapp/components/post.jsx | 15 +++++++++++++-- webapp/components/postlist.jsx | 7 +++---- webapp/components/postpage.jsx | 32 +++++++++++++++++++++++--------- 4 files changed, 43 insertions(+), 15 deletions(-) diff --git a/webapp/app.jsx b/webapp/app.jsx index 8f89b23..c2f4a65 100644 --- a/webapp/app.jsx +++ b/webapp/app.jsx @@ -82,11 +82,15 @@ ReactDOM.render( + + + + diff --git a/webapp/components/post.jsx b/webapp/components/post.jsx index 0a63a06..f53cb62 100644 --- a/webapp/components/post.jsx +++ b/webapp/components/post.jsx @@ -23,6 +23,18 @@ module.exports = function(boardsAPI){ if(this.isMounted()) this.setState({ moment: require('moment') }) }) }, + postLink: function(){ + console.log('op',this.props.post.op,'board',this.props.board) + 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 + } + } else { + return '/post/'+this.props.post.hash + } + }, render: function(){ return
@@ -31,8 +43,7 @@ module.exports = function(boardsAPI){
{this.getDate()} - - Comments + View
diff --git a/webapp/components/postlist.jsx b/webapp/components/postlist.jsx index a2a6ca2..a900b72 100644 --- a/webapp/components/postlist.jsx +++ b/webapp/components/postlist.jsx @@ -1,5 +1,6 @@ var React = require('react') var sortedIndex = require('lodash.sortedindex') +var Icon = require('icon.jsx') module.exports = function(boardsAPI){ var Post = require('post.jsx')(boardsAPI) @@ -39,7 +40,7 @@ module.exports = function(boardsAPI){ getPosts: function(){ if(this.state.posts.length > 0 || this.state.api){ return this.state.posts.map(post => { - return + return }) } else return
@@ -48,9 +49,7 @@ module.exports = function(boardsAPI){ render: function(){ return (
- {this.state.posts.map(post => { - return - })} + {this.getPosts()}
) } diff --git a/webapp/components/postpage.jsx b/webapp/components/postpage.jsx index b9531c0..f93f985 100644 --- a/webapp/components/postpage.jsx +++ b/webapp/components/postpage.jsx @@ -1,25 +1,39 @@ var React = require('react') -var Post = require('post.jsx') -module.exports = function(boards){ - var UserID = require('userID.jsx')(boards) +module.exports = function(boardsAPI){ + var UserID = require('userID.jsx')(boardsAPI) + var GetIPFS = require('getipfs.jsx')(boardsAPI) + var Post = require('post.jsx')(boardsAPI) return React.createClass({ getInitialState: function(){ - return { post: { title: '...', text: '...' }, api: boards.isInit } + return { post: { title: '...', text: '...' }, api: false } }, componentDidMount: function(){ - boards.getEventEmitter().on('init', _ => { if(this.isMounted()) this.setState({ api: true })}) - boards.downloadPost(this.props.id,this.props.admin,this.props.board,this.props.op,(err,post) => { + boardsAPI.use(boards => { + boards.getEventEmitter().on('init', err => { + if(!err && this.isMounted()){ + this.init(boards) + } + }) + if(this.isMounted() && boards.isInit){ + this.init(boards) + } + }) + }, + init: function(boards){ + if(this.state.init) return + this.setState({ api: true }) + boards.downloadPost(this.props.params.posthash,this.props.params.userid,this.props.params.boardname,this.props.params.userid,(err,post) => { if(err){ - this.setState({ post: { title: 'Error', text: err.Message || err }}) + this.setState({ post: { title: 'Error', text: err.Message || err.Error }}) } else { this.setState({ post }) } }) }, render: function(){ - if(this.state.api || boards.isInit) - return + if(this.state.api) + return else return } })