mirror of
https://github.com/fazo96/ipfs-boards
synced 2025-01-10 12:24:20 +01:00
improved editors, added board editor
This commit is contained in:
parent
f72f3b079e
commit
4f574dbdfc
@ -131,7 +131,38 @@ BoardsAPI.prototype.createProfile = function (profile, done) {
|
||||
}
|
||||
|
||||
BoardsAPI.prototype.createBoard = function (board, done) {
|
||||
|
||||
console.log('Generating board:', board)
|
||||
try {
|
||||
var settings_str = JSON.stringify(board)
|
||||
} catch (e) {
|
||||
console.log('Error, invalid Board Settings:', e)
|
||||
return done(e)
|
||||
}
|
||||
var dest = '/ipfs-boards-profile/boards/' + board.id + '/settings.json'
|
||||
asyncjs.waterfall([
|
||||
// Create required directories
|
||||
cb => this.ipfs.files.mkdir('/ipfs-boards-profile/boards/' + board.id + '/', { p: true }, cb),
|
||||
(e, cb) => {
|
||||
// Remove old board files if present
|
||||
this.ipfs.files.rm(dest, { r: true }, res => cb())
|
||||
},
|
||||
(cb) => {
|
||||
// Serialize Board Settings and add to IPFS
|
||||
this.ipfs.add(new Buffer(settings_str), cb)
|
||||
},
|
||||
(res, cb) => {
|
||||
// Move Board into mfs
|
||||
console.log('added Board Settings to IPFS:', res.Hash)
|
||||
var spath = '/ipfs/' + res.Hash
|
||||
this.ipfs.files.cp([spath, dest], cb)
|
||||
},
|
||||
(e, cb) => this.ipfs.files.stat('/', cb),
|
||||
(res, cb) => {
|
||||
var profile_hash = res.Hash
|
||||
console.log('Publishing profile...')
|
||||
this.ipfs.name.publish(profile_hash, cb)
|
||||
}
|
||||
], done)
|
||||
}
|
||||
|
||||
BoardsAPI.prototype.backupCache = function () {
|
||||
@ -248,8 +279,14 @@ BoardsAPI.prototype.getProfile = function (userID, done) {
|
||||
this.ee.emit('error', err2)
|
||||
done(err2, null)
|
||||
} else {
|
||||
// TODO: JSON parse error handling
|
||||
var p = JSON.parse(res.toString())
|
||||
var p
|
||||
try {
|
||||
p = JSON.parse(res.toString())
|
||||
} catch (e) {
|
||||
this.ee.emit('error', e)
|
||||
if (done && done.apply) done(e)
|
||||
return
|
||||
}
|
||||
this.ee.emit('profile for ' + userID, p)
|
||||
done(null, p)
|
||||
}
|
||||
@ -284,8 +321,14 @@ BoardsAPI.prototype.getBoardSettings = function (userID, board, done) {
|
||||
} else {
|
||||
var url = r + this.baseurl + 'boards/' + board + '/settings.json'
|
||||
this.ipfs.cat(url, (err, resp) => {
|
||||
// TODO: error handling json conversion
|
||||
var settings = JSON.parse(resp.toString())
|
||||
var settings
|
||||
try {
|
||||
settings = JSON.parse(resp.toString())
|
||||
} catch (e) {
|
||||
this.ee.emit('error', e)
|
||||
if (done && done.apply) done(e)
|
||||
return
|
||||
}
|
||||
if (err) {
|
||||
this.ee.emit('error', err)
|
||||
if (done && done.apply) done(err)
|
||||
@ -405,8 +448,7 @@ BoardsAPI.prototype.getPostsInBoard = function (adminID, board) {
|
||||
// download posts for each user in whitelist
|
||||
whitelist.forEach(item => {
|
||||
this.getUserPostListInBoard(item, board, (err, postList) => {
|
||||
if (err) return
|
||||
postList.forEach(i => this.downloadPost(i.hash, adminID, board, item))
|
||||
if (!err) postList.forEach(i => this.downloadPost(i.hash, adminID, board, item))
|
||||
})
|
||||
})
|
||||
})
|
||||
@ -414,9 +456,7 @@ BoardsAPI.prototype.getPostsInBoard = function (adminID, board) {
|
||||
this.getAllowedContentProducers(adminID, board, { posts: true })
|
||||
// Get the admin's posts
|
||||
this.getUserPostListInBoard(adminID, board, (err, res) => {
|
||||
if (err) {
|
||||
console.log(err)
|
||||
} else res.forEach(item => this.downloadPost(item.hash, adminID, board, adminID))
|
||||
if (!err) res.forEach(item => this.downloadPost(item.hash, adminID, board, adminID))
|
||||
})
|
||||
} else {
|
||||
// TODO: Download all posts in board from everyone
|
||||
|
@ -26,6 +26,7 @@ var Board = require('board.jsx')(boards)
|
||||
var PostPage = require('postpage.jsx')(boards)
|
||||
var CommentPage = require('commentpage.jsx')(boards)
|
||||
var ProfileEditor = require('profile-editor.jsx')(boards)
|
||||
var BoardEditor = require('board-editor.jsx')(boards)
|
||||
|
||||
// Define Main Components
|
||||
|
||||
@ -90,11 +91,14 @@ ReactDOM.render(
|
||||
</Route>
|
||||
</Route>
|
||||
</Route>
|
||||
<Route path="/post/:posthash" component={PostPage} />
|
||||
<Route path="/board/:boardname" component={Board} />
|
||||
<Route path="/edit/profile" component={ProfileEditor} />
|
||||
<Route path="/users" component={Users} />
|
||||
<Route path="/settings" component={Settings} />
|
||||
<Route path="edit">
|
||||
<Route path="profile" component={ProfileEditor} />
|
||||
<Route path="board(/:boardname)" component={BoardEditor} />
|
||||
</Route>
|
||||
<Route path="post/:posthash" component={PostPage} />
|
||||
<Route path="board/:boardname" component={Board} />
|
||||
<Route path="users" component={Users} />
|
||||
<Route path="settings" component={Settings} />
|
||||
<Route path="*" component={NotFound} />
|
||||
</Route>
|
||||
</Router>, document.getElementById('root')
|
||||
|
@ -27,14 +27,14 @@ module.exports = function (boardsAPI) {
|
||||
this.getBoardSettings(boards)
|
||||
},
|
||||
getBoardSettings (boards) {
|
||||
if (!this.props.params.board) return
|
||||
if (!this.props.params.boardname) return
|
||||
this.setState({ loading: true })
|
||||
boards.getBoardSettings(boards.getMyID(), this.props.params.board, (err, s) => {
|
||||
boards.getBoardSettings(boards.getMyID(), this.props.params.boardname, (err, s) => {
|
||||
if (err) {
|
||||
this.setState({ error: err, loading: false })
|
||||
} else {
|
||||
} else if (this.state.loading) {
|
||||
this.setState({
|
||||
id: this.props.params.board,
|
||||
id: this.props.params.boardname,
|
||||
name: s.fullname,
|
||||
desc: s.description,
|
||||
loading: false
|
||||
@ -57,9 +57,9 @@ module.exports = function (boardsAPI) {
|
||||
save () {
|
||||
var boards = this.state.api
|
||||
var board = {
|
||||
id: this.state.shortname,
|
||||
id: this.state.shortname || this.props.params.boardname,
|
||||
fullname: this.state.name,
|
||||
description: this.state.description
|
||||
description: this.state.desc
|
||||
}
|
||||
this.setState({ updating: true })
|
||||
boards.createBoard(board, (err) => {
|
||||
@ -68,8 +68,8 @@ module.exports = function (boardsAPI) {
|
||||
})
|
||||
},
|
||||
additionalButtons () {
|
||||
if (this.state.api && this.props.params.board) {
|
||||
var url = '/@' + this.state.api.getMyID() + '/' + this.props.params.board
|
||||
if (this.state.api && this.props.params.boardname) {
|
||||
var url = '/@' + this.state.api.getMyID() + '/' + this.props.params.boardname
|
||||
return <span>
|
||||
<button onClick={this.refresh} className="button not-first">Refresh</button>
|
||||
<Link to={url} className="button not-first">View</Link>
|
||||
@ -85,7 +85,7 @@ module.exports = function (boardsAPI) {
|
||||
<div className="text-center">
|
||||
<Icon className="center-block fa-3x light" name="ban" />
|
||||
<h4 className="top-half-em">Ooops</h4>
|
||||
<p>{this.state.error}</p>
|
||||
<p>{'' + this.state.error}</p>
|
||||
<button className="button button-primary center-block" onClick={this.skip}>Continue</button>
|
||||
</div>
|
||||
</div>
|
||||
@ -93,7 +93,7 @@ module.exports = function (boardsAPI) {
|
||||
return <div>
|
||||
<div className="text-center">
|
||||
<Icon className="center-block fa-spin fa-3x light" name="refresh" />
|
||||
<h4 className="top-half-em">Fetching your current profile...</h4>
|
||||
<h4 className="top-half-em">Fetching your current Board Settings...</h4>
|
||||
<button className="button button-primary center-block" onClick={this.skip}>Skip</button>
|
||||
</div>
|
||||
</div>
|
||||
@ -117,18 +117,20 @@ module.exports = function (boardsAPI) {
|
||||
for your changes to be visibile. Your Boards will appear unchanged during
|
||||
this time.</p>
|
||||
<div className="row">
|
||||
<div className="six columns">
|
||||
<label htmlFor="shortname">ID</label>
|
||||
<input className="u-full-width" type="text" id="shortname" value={this.state.name} onChange={this.handleChange} placeholder="Choose a short name that identifies your Board." />
|
||||
</div>
|
||||
<div className="six columns">
|
||||
{this.props.params.boardname
|
||||
? <div></div>
|
||||
: <div className="six columns">
|
||||
<label htmlFor="shortname">ID</label>
|
||||
<input className="u-full-width" type="text" id="shortname" value={this.state.id} onChange={this.handleChange} placeholder="Choose a short ID." />
|
||||
</div>}
|
||||
<div className={(this.props.params.boardname ? 'twelve' : 'six') + ' columns'}>
|
||||
<label htmlFor="name">Title</label>
|
||||
<input className="u-full-width" type="text" id="name" value={this.state.port} onChange={this.onChange} placeholder="Name your board" />
|
||||
<input className="u-full-width" type="text" id="name" value={this.state.name} onChange={this.handleChange} placeholder="Name your board" />
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
<label htmlFor="desc">Description</label>
|
||||
<textarea className="u-full-width" id="desc" value={this.state.description} onChange={this.handleChange} placeholder="What's this Board about? Markdown is supported :)" />
|
||||
<textarea className="u-full-width" id="desc" value={this.state.desc} onChange={this.handleChange} placeholder="What's this Board about? Markdown is supported :)" />
|
||||
</div>
|
||||
<div className="buttons">
|
||||
<button className="button button-primary" onClick={this.save}>Publish</button>
|
||||
|
@ -71,7 +71,7 @@ module.exports = function (boardsAPI) {
|
||||
<div className="text-center">
|
||||
<Icon className="center-block fa-3x light" name="ban" />
|
||||
<h4 className="top-half-em">Ooops</h4>
|
||||
<p>{this.state.error}</p>
|
||||
<p>{'' + this.state.error}</p>
|
||||
<button className="button button-primary center-block" onClick={this.skip}>Continue</button>
|
||||
</div>
|
||||
</div>
|
||||
|
Loading…
Reference in New Issue
Block a user