mirror of
https://github.com/fazo96/ipfs-boards
synced 2025-01-26 15:04:19 +01:00
post editor now correctly sets previous version
This commit is contained in:
parent
519417b6ec
commit
aecf89339c
@ -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) {
|
BoardsAPI.prototype.createProfile = function (profile, done) {
|
||||||
console.log('Generating profile:', profile)
|
console.log('Generating profile:', profile)
|
||||||
try {
|
try {
|
||||||
|
@ -22,19 +22,23 @@ module.exports = function (boardsAPI) {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
componentWillReceiveProps (props) {
|
||||||
|
if (this.props.params.posthash !== props.params.posthash) {
|
||||||
|
boardsAPI.use(this.init)
|
||||||
|
}
|
||||||
|
},
|
||||||
init (boards) {
|
init (boards) {
|
||||||
if (this.state.init) return
|
this.setState({ api: boards, userid: boards.getMyID(), downloaded: false, title: undefined, text: undefined })
|
||||||
this.setState({ api: boards, userid: boards.getMyID(), init: true })
|
|
||||||
if (this.props.params.posthash) this.downloadPost(boards)
|
if (this.props.params.posthash) this.downloadPost(boards)
|
||||||
},
|
},
|
||||||
downloadPost (boards) {
|
downloadPost (boards) {
|
||||||
this.setState({ loading: true })
|
this.setState({ loading: true })
|
||||||
boards.downloadPost(this.props.params.posthash, (err, hash, date, post) => {
|
boards.downloadPost(this.props.params.posthash, (err, hash, date, post) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
this.setState({ error: err, loading: false })
|
this.setState({ error: err, loading: false, downloaded: false })
|
||||||
} else {
|
} else {
|
||||||
console.log(post)
|
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) {
|
if (this.state.title && this.state.title.length > 0) {
|
||||||
post.title = this.state.title
|
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 => {
|
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 })
|
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)
|
||||||
|
}
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user