mirror of
https://github.com/fazo96/ipfs-boards
synced 2025-03-12 21:48:39 +01:00
finished post linking
This commit is contained in:
parent
5dc37167ea
commit
002396c98d
@ -82,11 +82,15 @@ ReactDOM.render(
|
|||||||
<IndexRoute component={Homepage} />
|
<IndexRoute component={Homepage} />
|
||||||
<Route path="/@:userid">
|
<Route path="/@:userid">
|
||||||
<IndexRoute component={Profile} />
|
<IndexRoute component={Profile} />
|
||||||
|
<Route path="post">
|
||||||
|
<Route path=":posthash" component={PostPage} />
|
||||||
|
</Route>
|
||||||
<Route path=":boardname">
|
<Route path=":boardname">
|
||||||
<IndexRoute component={Board} />
|
<IndexRoute component={Board} />
|
||||||
<Route path=":posthash" component={PostPage} />
|
<Route path=":posthash" component={PostPage} />
|
||||||
</Route>
|
</Route>
|
||||||
</Route>
|
</Route>
|
||||||
|
<Route path="/post/:posthash" component={PostPage} />
|
||||||
<Route path="/users" component={Users} />
|
<Route path="/users" component={Users} />
|
||||||
<Route path="/settings" component={Settings} />
|
<Route path="/settings" component={Settings} />
|
||||||
<Route path="*" component={NotFound} />
|
<Route path="*" component={NotFound} />
|
||||||
|
@ -23,6 +23,18 @@ module.exports = function(boardsAPI){
|
|||||||
if(this.isMounted()) this.setState({ moment: require('moment') })
|
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(){
|
render: function(){
|
||||||
return <div key={this.props.post.title} className="post">
|
return <div key={this.props.post.title} className="post">
|
||||||
<div className="content">
|
<div className="content">
|
||||||
@ -31,8 +43,7 @@ module.exports = function(boardsAPI){
|
|||||||
<div className="icons">
|
<div className="icons">
|
||||||
<UserID id={this.props.post.op}></UserID>
|
<UserID id={this.props.post.op}></UserID>
|
||||||
<Icon name="clock-o" className="not-first"/> {this.getDate()}
|
<Icon name="clock-o" className="not-first"/> {this.getDate()}
|
||||||
<Icon name="comments" className="not-first" />
|
<Icon name="comments" className="not-first" /> <Link to={this.postLink()}>View</Link>
|
||||||
<Link to={this.props.link || '/post/'+this.props.post.hash }>Comments</Link>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
var React = require('react')
|
var React = require('react')
|
||||||
var sortedIndex = require('lodash.sortedindex')
|
var sortedIndex = require('lodash.sortedindex')
|
||||||
|
var Icon = require('icon.jsx')
|
||||||
|
|
||||||
module.exports = function(boardsAPI){
|
module.exports = function(boardsAPI){
|
||||||
var Post = require('post.jsx')(boardsAPI)
|
var Post = require('post.jsx')(boardsAPI)
|
||||||
@ -39,7 +40,7 @@ module.exports = function(boardsAPI){
|
|||||||
getPosts: function(){
|
getPosts: function(){
|
||||||
if(this.state.posts.length > 0 || this.state.api){
|
if(this.state.posts.length > 0 || this.state.api){
|
||||||
return this.state.posts.map(post => {
|
return this.state.posts.map(post => {
|
||||||
return <Post key={post.title+post.text} post={post} />
|
return <Post key={post.hash} board={this.props.board} admin={this.props.admin} post={post} />
|
||||||
})
|
})
|
||||||
} else return <div className="center-block text-center">
|
} else return <div className="center-block text-center">
|
||||||
<Icon name="refresh" className="fa-3x center-block light fa-spin" />
|
<Icon name="refresh" className="fa-3x center-block light fa-spin" />
|
||||||
@ -48,9 +49,7 @@ module.exports = function(boardsAPI){
|
|||||||
render: function(){
|
render: function(){
|
||||||
return (
|
return (
|
||||||
<div className="postList">
|
<div className="postList">
|
||||||
{this.state.posts.map(post => {
|
{this.getPosts()}
|
||||||
return <Post key={post.title+post.text} post={post} />
|
|
||||||
})}
|
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -1,25 +1,39 @@
|
|||||||
var React = require('react')
|
var React = require('react')
|
||||||
var Post = require('post.jsx')
|
|
||||||
|
|
||||||
module.exports = function(boards){
|
module.exports = function(boardsAPI){
|
||||||
var UserID = require('userID.jsx')(boards)
|
var UserID = require('userID.jsx')(boardsAPI)
|
||||||
|
var GetIPFS = require('getipfs.jsx')(boardsAPI)
|
||||||
|
var Post = require('post.jsx')(boardsAPI)
|
||||||
return React.createClass({
|
return React.createClass({
|
||||||
getInitialState: function(){
|
getInitialState: function(){
|
||||||
return { post: { title: '...', text: '...' }, api: boards.isInit }
|
return { post: { title: '...', text: '...' }, api: false }
|
||||||
},
|
},
|
||||||
componentDidMount: function(){
|
componentDidMount: function(){
|
||||||
boards.getEventEmitter().on('init', _ => { if(this.isMounted()) this.setState({ api: true })})
|
boardsAPI.use(boards => {
|
||||||
boards.downloadPost(this.props.id,this.props.admin,this.props.board,this.props.op,(err,post) => {
|
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){
|
if(err){
|
||||||
this.setState({ post: { title: 'Error', text: err.Message || err }})
|
this.setState({ post: { title: 'Error', text: err.Message || err.Error }})
|
||||||
} else {
|
} else {
|
||||||
this.setState({ post })
|
this.setState({ post })
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
render: function(){
|
render: function(){
|
||||||
if(this.state.api || boards.isInit)
|
if(this.state.api)
|
||||||
return <Post post={this.state.post} />
|
return <Post post={this.state.post} board={this.props.params.boardname} />
|
||||||
else return <GetIPFS />
|
else return <GetIPFS />
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user