diff --git a/lib/boards-api.js b/lib/boards-api.js
index 8da1408..e3f165c 100644
--- a/lib/boards-api.js
+++ b/lib/boards-api.js
@@ -207,6 +207,56 @@ BoardsAPI.prototype.createPost = function (post, board, done) {
], done)
}
+BoardsAPI.prototype.delete = function (opts, done) {
+ var url = '/ipfs-boards-profile/'
+ console.log('Deleting', opts)
+ if (opts.what === 'post') url += 'posts/' + opts.board + '/'
+ if (opts.what === 'comment') url += 'comments/' + opts.parent + '/'
+ if (opts.what === 'comment' || opts.what === 'post') {
+ this.ipfs.files.ls(url, (err, res) => {
+ if (err) return done(err)
+ if (!res || !res.Entries) return done('invalid response')
+ var list = res.Entries
+ for (var item in list) {
+ if (list[item].Hash === opts.hash) {
+ url = url + list[item].Name
+ return this.ipfs.files.rm(url, {}, err => {
+ if (err) return done(err)
+ this.ipfs.files.stat('/', (err, res) => {
+ if (err) return done(err)
+ console.log('Publishing profile...')
+ this.ipfs.name.publish(res.Hash, done)
+ })
+ })
+ }
+ }
+ return done('post does not exist or was already deleted')
+ })
+ } else if (opts.what === 'board' || opts.what === 'profile') {
+ if (opts.what === 'board') {
+ url += 'boards/' + opts.board
+ }
+ this.ipfs.files.rm(url, { r: true }, err => {
+ if (err) return done(err)
+ this.ipfs.files.stat('/', (err, res) => {
+ if (err) return done(err)
+ console.log('Publishing profile...')
+ this.ipfs.name.publish(res.Hash, done)
+ })
+ })
+ } else {
+ done('what?')
+ }
+}
+
+BoardsAPI.prototype.deletePost = function (hash, board, done) {
+ this.delete({ what: 'post', hash, board }, done)
+}
+
+BoardsAPI.prototype.deleteComment = function (hash, parent, done) {
+ this.delete({ what: 'comment', hash, parent }, done)
+}
+
BoardsAPI.prototype.backupCache = function () {
if (window && window.localStorage !== undefined) {
// Use localStorage to store the IPNS cache
@@ -434,7 +484,6 @@ BoardsAPI.prototype.downloadPost = function (hash, adminID, board, op, done) {
done = op
op = undefined
}
- console.log('Downloading post', hash)
this.ipfs.cat(hash, (err2, r) => {
if (err2) {
this.ee.emit('error', err2)
@@ -442,8 +491,10 @@ BoardsAPI.prototype.downloadPost = function (hash, adminID, board, op, done) {
if (done && done.apply) done(err2)
} else {
replyAsObj(r, true, (err, post) => {
- if (err) return
- // TODO: add JSON parsing error handling
+ if (err) {
+ if (done && done.apply) return done(err)
+ return
+ }
post.hash = hash
if (op) post.op = op // Inject op
if (board) {
diff --git a/webapp/components/navbar.jsx b/webapp/components/navbar.jsx
index ad13288..97792e6 100644
--- a/webapp/components/navbar.jsx
+++ b/webapp/components/navbar.jsx
@@ -9,13 +9,13 @@ module.exports = function (boardsAPI) {
},
componentDidMount () {
boardsAPI.use(boards => {
- if (boards.isInit) this.setState({ api: true })
+ if (boards.isInit) this.setState({ api: true, userid: boards.getMyID() })
boards.getEventEmitter().on('init', err => {
if (!this.isMounted()) return
if (err) {
this.setState({ loading: false, api: false })
} else {
- this.setState({ api: true })
+ this.setState({ api: true, userid: boards.getMyID() })
}
})
})
@@ -23,7 +23,7 @@ module.exports = function (boardsAPI) {
extraButtons: function () {
if (this.state.api) {
return
-
+
} else if (this.state.loading) {
diff --git a/webapp/components/post.jsx b/webapp/components/post.jsx
index 0a02da3..cd8fe11 100644
--- a/webapp/components/post.jsx
+++ b/webapp/components/post.jsx
@@ -19,7 +19,7 @@ module.exports = React.createClass({
init (props) {
var boards = props.api
if (!boards) return this.setState({ error: 'Could not connect to IPFS' })
- this.setState({ loading: true })
+ this.setState({ loading: true, userid: boards.getMyID() })
boards.downloadPost(props.hash, props.adminID, props.board, (err, hash, date, post) => {
this.setState({ error: err, post: post, loading: false })
})
@@ -35,6 +35,19 @@ module.exports = React.createClass({
return '/post/' + this.props.hash
}
},
+ editorLink () {
+ if (this.state.post.op === this.state.userid) {
+ var board = this.props.board || this.state.post.board
+ if (board) {
+ var url = '/edit/board/' + board + '/post/' + this.props.hash
+ return
+ Edit
+
+ } else {
+ return
+ }
+ } else return
+ },
getContent () {
if (this.state.error) {
return
@@ -51,6 +64,7 @@ module.exports = React.createClass({
View
+ {this.editorLink()}
}
diff --git a/webapp/components/status-components.jsx b/webapp/components/status-components.jsx
index cda7b65..4406265 100644
--- a/webapp/components/status-components.jsx
+++ b/webapp/components/status-components.jsx
@@ -16,13 +16,24 @@ var Error = React.createClass({
var Loading = React.createClass({
render () {
- return
-
-
-
{this.props.title}
- { this.props.children }
+ // TODO: merge these (duplicated code) and use css to get desired style
+ if (this.props.small) {
+ return
+
+
+
{this.props.title}
+ { this.props.children }
+
-
+ } else {
+ return
+
+
+
{this.props.title}
+ { this.props.children }
+
+
+ }
}
})
@@ -31,11 +42,23 @@ var Saving = React.createClass({
return
-
Publishing...
+ { this.props.title || 'Publishing' }
{ this.props.children }
}
})
-module.exports = { Error, Loading, Saving }
+var Success = React.createClass({
+ render () {
+ return
+
+
+
{ this.props.title || 'Done' }
+ { this.props.children }
+
+
+ }
+})
+
+module.exports = { Error, Loading, Saving, Success }
diff --git a/webapp/pages/post-editor.jsx b/webapp/pages/post-editor.jsx
index 78f4e6f..2196a5f 100644
--- a/webapp/pages/post-editor.jsx
+++ b/webapp/pages/post-editor.jsx
@@ -2,7 +2,7 @@ var React = require('react')
var GetIPFS = require('getipfs.jsx')
var Icon = require('icon.jsx')
var Link = require('react-router').Link
-var { Error, Loading, Saving } = require('status-components.jsx')
+var { Error, Loading, Saving, Success } = require('status-components.jsx')
module.exports = function (boardsAPI) {
return React.createClass({
@@ -29,11 +29,12 @@ module.exports = function (boardsAPI) {
},
downloadPost (boards) {
this.setState({ loading: true })
- boards.downloadPost(this.props.params.posthash, (err, p) => {
+ boards.downloadPost(this.props.params.posthash, (err, hash, date, post) => {
if (err) {
this.setState({ error: err, loading: false })
} else {
- this.setState({ loading: false, title: p.title, text: p.text })
+ console.log(post)
+ this.setState({ loading: false, title: post.title, text: post.text })
}
})
},
@@ -43,7 +44,7 @@ module.exports = function (boardsAPI) {
this.setState(obj)
},
skip () {
- this.setState({ loading: false, updating: false, error: false })
+ this.setState({ loading: false, updating: false, error: false, success: false })
},
refresh () {
boardsAPI.use(b => this.downloadPost(b))
@@ -61,12 +62,22 @@ module.exports = function (boardsAPI) {
})
})
},
+ delete () {
+ this.setState({ deleting: true })
+ boardsAPI.use(boards => {
+ boards.deletePost(this.props.params.posthash, this.props.params.boardname, err => {
+ if (!err) console.log('Post deleted')
+ this.setState({ deleting: false, error: err, success: true })
+ })
+ })
+ },
additionalButtons () {
if (this.state.api && this.props.params.posthash) {
var url = '/@' + this.state.api.getMyID() + '/' + this.props.params.boardname + '/' + this.props.params.posthash
return
View
+
} else {
return
@@ -78,6 +89,11 @@ module.exports = function (boardsAPI) {
return
+ } else if (this.state.deleting) {
+ return
+ Pressing the Skip button will not abort the Delete operation.
+
+
} else if (this.state.loading) {
return
@@ -87,10 +103,11 @@ module.exports = function (boardsAPI) {
Pressing the Skip button will not abort the publish operation.
+ } else if (this.state.success) {
+ return
+ Note: due to a bug in go-ipfs, you may need to wait up to a minute for changes to appear.
+
} else {
- if (this.state.userid && this.props.params.boardname) {
- var boardurl = '/@' + this.state.userid + '/' + this.props.params.boardname
- }
return (
@@ -112,7 +129,6 @@ module.exports = function (boardsAPI) {
- {boardurl ? View Board : }
{this.additionalButtons()}
diff --git a/webapp/pages/profile-editor.jsx b/webapp/pages/profile-editor.jsx
index 000741a..bd45e90 100644
--- a/webapp/pages/profile-editor.jsx
+++ b/webapp/pages/profile-editor.jsx
@@ -36,7 +36,7 @@ module.exports = function (boardsAPI) {
},
init (boards) {
if (this.state.init) return
- this.setState({ api: boards })
+ this.setState({ api: boards, userid: boards.getMyID() })
this.getProfile(boards)
},
handleChange (event) {
@@ -101,7 +101,7 @@ module.exports = function (boardsAPI) {
- View
+ View
)
diff --git a/webapp/pages/profile.jsx b/webapp/pages/profile.jsx
index 62be316..a8e1298 100644
--- a/webapp/pages/profile.jsx
+++ b/webapp/pages/profile.jsx
@@ -13,13 +13,11 @@ module.exports = function (boardsAPI) {
componentDidMount () {
boardsAPI.use(boards => {
if (boards.isInit) {
- this.setState({ api: boards, id: boards.id })
this.init(boards)
}
var ee = boards.getEventEmitter()
ee.on('init', err => {
if (!err && this.isMounted()) {
- this.setState({ api: boards, id: boards.id })
this.init(boards)
}
})
@@ -50,10 +48,8 @@ module.exports = function (boardsAPI) {
},
init (boards) {
if (this.state.init) return
- if (boards.isInit || this.state.api) {
- this.downloadProfile(boards, this.props)
- this.setState({ init: true })
- }
+ this.setState({ init: true, api: boards, id: boards.id })
+ this.downloadProfile(boards, this.props)
},
linkToEditor () {
var uid = this.props.params.userid