From aecf89339c8a2eb9c82635a89b1406c44f129885 Mon Sep 17 00:00:00 2001 From: Enrico Fasoli Date: Wed, 23 Dec 2015 17:27:25 +0100 Subject: [PATCH] post editor now correctly sets previous version --- lib/boards-api.js | 11 +++++++++++ webapp/pages/post-editor.jsx | 23 +++++++++++++++++------ 2 files changed, 28 insertions(+), 6 deletions(-) diff --git a/lib/boards-api.js b/lib/boards-api.js index eebb290..bcbea7c 100644 --- a/lib/boards-api.js +++ b/lib/boards-api.js @@ -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 { diff --git a/webapp/pages/post-editor.jsx b/webapp/pages/post-editor.jsx index 2e0fdf6..53285d8 100644 --- a/webapp/pages/post-editor.jsx +++ b/webapp/pages/post-editor.jsx @@ -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) + } }) }) },