mirror of
https://github.com/fazo96/ipfs-boards
synced 2025-03-11 21:38:38 +01:00
finished post linking
This commit is contained in:
parent
5dc37167ea
commit
002396c98d
@ -82,11 +82,15 @@ ReactDOM.render(
|
||||
<IndexRoute component={Homepage} />
|
||||
<Route path="/@:userid">
|
||||
<IndexRoute component={Profile} />
|
||||
<Route path="post">
|
||||
<Route path=":posthash" component={PostPage} />
|
||||
</Route>
|
||||
<Route path=":boardname">
|
||||
<IndexRoute component={Board} />
|
||||
<Route path=":posthash" component={PostPage} />
|
||||
</Route>
|
||||
</Route>
|
||||
<Route path="/post/:posthash" component={PostPage} />
|
||||
<Route path="/users" component={Users} />
|
||||
<Route path="/settings" component={Settings} />
|
||||
<Route path="*" component={NotFound} />
|
||||
|
@ -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 <div key={this.props.post.title} className="post">
|
||||
<div className="content">
|
||||
@ -31,8 +43,7 @@ module.exports = function(boardsAPI){
|
||||
<div className="icons">
|
||||
<UserID id={this.props.post.op}></UserID>
|
||||
<Icon name="clock-o" className="not-first"/> {this.getDate()}
|
||||
<Icon name="comments" className="not-first" />
|
||||
<Link to={this.props.link || '/post/'+this.props.post.hash }>Comments</Link>
|
||||
<Icon name="comments" className="not-first" /> <Link to={this.postLink()}>View</Link>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -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 <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">
|
||||
<Icon name="refresh" className="fa-3x center-block light fa-spin" />
|
||||
@ -48,9 +49,7 @@ module.exports = function(boardsAPI){
|
||||
render: function(){
|
||||
return (
|
||||
<div className="postList">
|
||||
{this.state.posts.map(post => {
|
||||
return <Post key={post.title+post.text} post={post} />
|
||||
})}
|
||||
{this.getPosts()}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
@ -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 <Post post={this.state.post} />
|
||||
if(this.state.api)
|
||||
return <Post post={this.state.post} board={this.props.params.boardname} />
|
||||
else return <GetIPFS />
|
||||
}
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user