1
0
mirror of https://github.com/fazo96/ipfs-boards synced 2025-01-24 14:44:19 +01:00

post editor now correctly sets previous version

This commit is contained in:
Enrico Fasoli 2015-12-23 17:27:25 +01:00
parent 519417b6ec
commit aecf89339c
2 changed files with 28 additions and 6 deletions

View File

@ -85,6 +85,17 @@ function BoardsAPI (ipfs) {
}
}
BoardsAPI.prototype.restoreProfileFromMFS = function (done) {
this.ipfs.files.stat('/ipfs-boards-profile', (err, res) => {
if (err) return done(err)
this.ipfs.name.publish(res.Hash, done)
})
}
BoardsAPI.prototype.restoreProfileFromIPFS = function (hash, done) {
this.ipfs.name.publish(hash, done)
}
BoardsAPI.prototype.createProfile = function (profile, done) {
console.log('Generating profile:', profile)
try {

View File

@ -22,19 +22,23 @@ module.exports = function (boardsAPI) {
}
})
},
componentWillReceiveProps (props) {
if (this.props.params.posthash !== props.params.posthash) {
boardsAPI.use(this.init)
}
},
init (boards) {
if (this.state.init) return
this.setState({ api: boards, userid: boards.getMyID(), init: true })
this.setState({ api: boards, userid: boards.getMyID(), downloaded: false, title: undefined, text: undefined })
if (this.props.params.posthash) this.downloadPost(boards)
},
downloadPost (boards) {
this.setState({ loading: true })
boards.downloadPost(this.props.params.posthash, (err, hash, date, post) => {
if (err) {
this.setState({ error: err, loading: false })
this.setState({ error: err, loading: false, downloaded: false })
} else {
console.log(post)
this.setState({ loading: false, title: post.title, text: post.text })
this.setState({ loading: false, title: post.title, text: post.text, downloaded: true })
}
})
},
@ -57,10 +61,17 @@ module.exports = function (boardsAPI) {
if (this.state.title && this.state.title.length > 0) {
post.title = this.state.title
}
if (this.props.params.posthash) {
// TODO: maybe check if downloaded? But then what if the user skipped the prev version download?
post.previous = this.props.params.posthash
}
boardsAPI.use(boards => {
boards.createPost(post, this.props.params.boardname, err => {
boards.createPost(post, this.props.params.boardname, (err, hash) => {
this.setState({ error: err, updating: false })
// Should redirect to new post hash
if (!err) {
var url = '/edit/board/' + this.props.params.boardname + '/post/' + hash
this.props.history.push(url)
}
})
})
},