mirror of
https://github.com/fazo96/ipfs-boards
synced 2025-04-02 01:38:37 +02:00
refactored all code to comply with new code style
This commit is contained in:
parent
307605a404
commit
78c659e123
@ -63,9 +63,9 @@ function BoardsAPI(ipfs){
|
|||||||
this.users = [] // list of IPNS names
|
this.users = [] // list of IPNS names
|
||||||
this.resolvingIPNS = {}
|
this.resolvingIPNS = {}
|
||||||
this.ee = new EventEmitter()
|
this.ee = new EventEmitter()
|
||||||
if(localStorage !== undefined){
|
if (window && window.localStorage !== undefined) {
|
||||||
// Use localStorage to store the IPNS cache
|
// Use localStorage to store the IPNS cache
|
||||||
var stored = localStorage.getItem('ipfs-boards-user-cache')
|
var stored = window.localStorage.getItem('ipfs-boards-user-cache')
|
||||||
try {
|
try {
|
||||||
this.users = JSON.parse(stored)
|
this.users = JSON.parse(stored)
|
||||||
if (this.users === null || this.users === undefined || !this.users.indexOf || !this.users.push) {
|
if (this.users === null || this.users === undefined || !this.users.indexOf || !this.users.push) {
|
||||||
@ -78,9 +78,9 @@ function BoardsAPI(ipfs){
|
|||||||
}
|
}
|
||||||
|
|
||||||
BoardsAPI.prototype.backupCache = function () {
|
BoardsAPI.prototype.backupCache = function () {
|
||||||
if(localStorage !== undefined){
|
if (window && window.localStorage !== undefined) {
|
||||||
// Use localStorage to store the IPNS cache
|
// Use localStorage to store the IPNS cache
|
||||||
localStorage.setItem('ipfs-boards-user-cache',JSON.stringify(this.users))
|
window.localStorage.setItem('ipfs-boards-user-cache', JSON.stringify(this.users))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -233,7 +233,7 @@ BoardsAPI.prototype.getBoardSettings = function(userID,board){
|
|||||||
} else {
|
} else {
|
||||||
// SETTINGS file is here, need to parse it a little bit
|
// SETTINGS file is here, need to parse it a little bit
|
||||||
this.ee.emit('settings for ' + board + '@' + userID, settings, r)
|
this.ee.emit('settings for ' + board + '@' + userID, settings, r)
|
||||||
if(settings.whitelist == true){
|
if (settings.whitelist === true) {
|
||||||
// Get the whitelist
|
// Get the whitelist
|
||||||
var url = r + this.baseurl + 'boards/' + board + '/whitelist'
|
var url = r + this.baseurl + 'boards/' + board + '/whitelist'
|
||||||
this.ipfs.cat(url, (err, res) => {
|
this.ipfs.cat(url, (err, res) => {
|
||||||
@ -241,14 +241,21 @@ BoardsAPI.prototype.getBoardSettings = function(userID,board){
|
|||||||
this.ee.emit('error', err)
|
this.ee.emit('error', err)
|
||||||
// Emit an empty whitelist.
|
// Emit an empty whitelist.
|
||||||
this.ee.emit('whitelist for ' + board + '@' + userID, [])
|
this.ee.emit('whitelist for ' + board + '@' + userID, [])
|
||||||
} else replyAsObj(res,false,(err,whitelist) => {
|
} else {
|
||||||
|
replyAsObj(res, false, (err, whitelist) => {
|
||||||
|
if (err) {
|
||||||
|
// Emit an empty whitelist.
|
||||||
|
this.ee.emit('whitelist for ' + board + '@' + userID, [])
|
||||||
|
} else {
|
||||||
// Send whitelist
|
// Send whitelist
|
||||||
var w = whitelist.split(' ').map(x => x.trim())
|
var w = whitelist.split(' ').map(x => x.trim())
|
||||||
this.ee.emit('whitelist for ' + board + '@' + userID, w)
|
this.ee.emit('whitelist for ' + board + '@' + userID, w)
|
||||||
})
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
if(!settings.whitelist_only && !settings.approval_required && settings.blacklist == true){
|
})
|
||||||
|
}
|
||||||
|
if (!settings.whitelist_only && !settings.approval_required && settings.blacklist === true) {
|
||||||
// Get the blacklist
|
// Get the blacklist
|
||||||
var u = r + this.baseurl + 'boards/' + board + '/blacklist'
|
var u = r + this.baseurl + 'boards/' + board + '/blacklist'
|
||||||
this.ipfs.cat(u, (err, blacklist) => {
|
this.ipfs.cat(u, (err, blacklist) => {
|
||||||
@ -278,6 +285,7 @@ BoardsAPI.prototype.downloadPost = function(hash,adminID,board,op,done){
|
|||||||
if (done && done.apply) done(err2)
|
if (done && done.apply) done(err2)
|
||||||
} else {
|
} else {
|
||||||
replyAsObj(r, true, (err, post) => {
|
replyAsObj(r, true, (err, post) => {
|
||||||
|
if (err) return
|
||||||
// TODO: add JSON parsing error handling
|
// TODO: add JSON parsing error handling
|
||||||
post.hash = hash
|
post.hash = hash
|
||||||
if (op) post.op = op // Inject op
|
if (op) post.op = op // Inject op
|
||||||
@ -312,14 +320,14 @@ BoardsAPI.prototype.getAllowedContentProducers = function(adminID,board,options)
|
|||||||
if (!options) return
|
if (!options) return
|
||||||
this.ee.on('settings for ' + board + '@' + adminID, function (settings, addr) {
|
this.ee.on('settings for ' + board + '@' + adminID, function (settings, addr) {
|
||||||
// Get stuff based on settings
|
// Get stuff based on settings
|
||||||
if(settings.approval_required == true){
|
if (settings.approval_required === true) {
|
||||||
// Get approved posts list
|
// Get approved posts list
|
||||||
if (options.posts) this.retrieveListOfApproved('posts', addr, adminID, board)
|
if (options.posts) this.retrieveListOfApproved('posts', addr, adminID, board)
|
||||||
// Get approved comments list
|
// Get approved comments list
|
||||||
if (options.comments) this.retrieveListOfApproved('comments', addr, adminID, board)
|
if (options.comments) this.retrieveListOfApproved('comments', addr, adminID, board)
|
||||||
} else if(settings.whitelist_only == true){
|
} else if (settings.whitelist_only === true) {
|
||||||
// TODO: emit all whitelisted users
|
// TODO: emit all whitelisted users
|
||||||
} else if(settings.blacklist == true){
|
} else if (settings.blacklist === true) {
|
||||||
// TODO: emit all users not in the blacklist
|
// TODO: emit all users not in the blacklist
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@ -337,6 +345,7 @@ BoardsAPI.prototype.getPostsInBoard = function(adminID,board){
|
|||||||
// download posts for each user in whitelist
|
// download posts for each user in whitelist
|
||||||
whitelist.forEach(item => {
|
whitelist.forEach(item => {
|
||||||
this.getUserPostListInBoard(item, board, (err, postList) => {
|
this.getUserPostListInBoard(item, board, (err, postList) => {
|
||||||
|
if (err) return
|
||||||
postList.forEach(i => this.downloadPost(i.hash, adminID, board, item))
|
postList.forEach(i => this.downloadPost(i.hash, adminID, board, item))
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
@ -366,7 +375,8 @@ BoardsAPI.prototype.getUserPostListInBoard = function(user,board,done){
|
|||||||
if (err) {
|
if (err) {
|
||||||
this.ee.emit('error', err)
|
this.ee.emit('error', err)
|
||||||
done(err)
|
done(err)
|
||||||
} else this.ipfs.ls(url+this.baseurl+'posts/'+board,(e,r) => {
|
} else {
|
||||||
|
this.ipfs.ls(url + this.baseurl + 'posts/' + board, (e, r) => {
|
||||||
if (e) {
|
if (e) {
|
||||||
this.ee.emit('error', e)
|
this.ee.emit('error', e)
|
||||||
done(e)
|
done(e)
|
||||||
@ -379,13 +389,14 @@ BoardsAPI.prototype.getUserPostListInBoard = function(user,board,done){
|
|||||||
done(null, l)
|
done(null, l)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
}
|
||||||
return true // remove myself from listeners
|
return true // remove myself from listeners
|
||||||
})
|
})
|
||||||
return this.ee
|
return this.ee
|
||||||
}
|
}
|
||||||
|
|
||||||
BoardsAPI.prototype.downloadComment = function (hash, adminID, board, target, done) {
|
BoardsAPI.prototype.downloadComment = function (hash, adminID, board, target, done) {
|
||||||
if(!done && typeof target == 'function'){
|
if (!done && typeof target === 'function') {
|
||||||
done = target
|
done = target
|
||||||
target = undefined
|
target = undefined
|
||||||
}
|
}
|
||||||
@ -423,7 +434,7 @@ BoardsAPI.prototype.getCommentsFor = function(parent,board,adminID,target){
|
|||||||
replyAsObj(res, true, (err2, obj) => {
|
replyAsObj(res, true, (err2, obj) => {
|
||||||
if (err2) {
|
if (err2) {
|
||||||
this.ee.emit('error', err2)
|
this.ee.emit('error', err2)
|
||||||
} else if(typeof obj.previous == 'string'){
|
} else if (typeof obj.previous === 'string') {
|
||||||
// Also get comments for the previous version of the parent!
|
// Also get comments for the previous version of the parent!
|
||||||
this.getCommentsFor(obj.previous, board, adminID, parent)
|
this.getCommentsFor(obj.previous, board, adminID, parent)
|
||||||
}
|
}
|
||||||
@ -441,6 +452,7 @@ BoardsAPI.prototype.getCommentsFor = function(parent,board,adminID,target){
|
|||||||
// download posts for each user in whitelist
|
// download posts for each user in whitelist
|
||||||
whitelist.forEach(item => {
|
whitelist.forEach(item => {
|
||||||
this.getUserCommentList(parent, item, (err, res) => {
|
this.getUserCommentList(parent, item, (err, res) => {
|
||||||
|
if (err) return
|
||||||
res.forEach(i => this.downloadComment(i.hash, adminID, board, target))
|
res.forEach(i => this.downloadComment(i.hash, adminID, board, target))
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
@ -460,7 +472,8 @@ BoardsAPI.prototype.getUserCommentList = function(parent,user,done){
|
|||||||
if (err) {
|
if (err) {
|
||||||
this.ee.emit('error', err)
|
this.ee.emit('error', err)
|
||||||
done(err)
|
done(err)
|
||||||
} else this.ipfs.ls(url+this.baseurl+'comments/'+parent,(e,r) => {
|
} else {
|
||||||
|
this.ipfs.ls(url + this.baseurl + 'comments/' + parent, (e, r) => {
|
||||||
if (e) {
|
if (e) {
|
||||||
this.ee.emit('error', e)
|
this.ee.emit('error', e)
|
||||||
done(e)
|
done(e)
|
||||||
@ -474,6 +487,7 @@ BoardsAPI.prototype.getUserCommentList = function(parent,user,done){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
}
|
||||||
return true // remove myself from listeners
|
return true // remove myself from listeners
|
||||||
})
|
})
|
||||||
return this.ee
|
return this.ee
|
||||||
|
@ -3,8 +3,6 @@ var ReactDOM = require('react-dom')
|
|||||||
var Router = require('react-router').Router
|
var Router = require('react-router').Router
|
||||||
var Route = require('react-router').Route
|
var Route = require('react-router').Route
|
||||||
var IndexRoute = require('react-router').IndexRoute
|
var IndexRoute = require('react-router').IndexRoute
|
||||||
var Redirect = require('react-router').Redirect
|
|
||||||
var Link = require('react-router').Link
|
|
||||||
|
|
||||||
// Load CSS
|
// Load CSS
|
||||||
require('normalize.css')
|
require('normalize.css')
|
||||||
@ -14,11 +12,9 @@ require('raleway.css')
|
|||||||
|
|
||||||
// Load Components
|
// Load Components
|
||||||
|
|
||||||
var opt = require('options.jsx').get()
|
var BoardsWrapper = require('boardsapiwrapper.js')
|
||||||
var boardsWrapper = require('boardsapiwrapper.js')
|
var boards = new BoardsWrapper()
|
||||||
var boards = new boardsWrapper()
|
|
||||||
var Icon = require('icon.jsx')
|
var Icon = require('icon.jsx')
|
||||||
var GetIPFS = require('getipfs.jsx')
|
|
||||||
|
|
||||||
// Load pages
|
// Load pages
|
||||||
|
|
||||||
@ -33,13 +29,13 @@ var CommentPage = require('commentpage.jsx')(boards)
|
|||||||
// Define Main Components
|
// Define Main Components
|
||||||
|
|
||||||
var Container = React.createClass({
|
var Container = React.createClass({
|
||||||
render: function(){
|
render () {
|
||||||
return (<div className="container app">{this.props.children}</div>)
|
return (<div className="container app">{this.props.children}</div>)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
var App = React.createClass({
|
var App = React.createClass({
|
||||||
render: function(){
|
render () {
|
||||||
return (<div><Navbar /><Container>{this.props.children}</Container></div>)
|
return (<div><Navbar /><Container>{this.props.children}</Container></div>)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@ -47,10 +43,10 @@ var App = React.createClass({
|
|||||||
// Static pages
|
// Static pages
|
||||||
|
|
||||||
var Static = React.createClass({
|
var Static = React.createClass({
|
||||||
html: function(){
|
html () {
|
||||||
return { __html: this.props.content }
|
return { __html: this.props.content }
|
||||||
},
|
},
|
||||||
render: function(){
|
render () {
|
||||||
if (this.props.content) {
|
if (this.props.content) {
|
||||||
return <div className={this.props.className} dangerouslySetInnerHTML={this.html()} />
|
return <div className={this.props.className} dangerouslySetInnerHTML={this.html()} />
|
||||||
} else {
|
} else {
|
||||||
@ -60,13 +56,13 @@ var Static = React.createClass({
|
|||||||
})
|
})
|
||||||
|
|
||||||
var Homepage = React.createClass({
|
var Homepage = React.createClass({
|
||||||
render: function(){
|
render () {
|
||||||
return <Static className="homepage" content={require('landing.md')} />
|
return <Static className="homepage" content={require('landing.md')} />
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
var NotFound = React.createClass({
|
var NotFound = React.createClass({
|
||||||
render: function(){
|
render () {
|
||||||
return (<div className="text-center">
|
return (<div className="text-center">
|
||||||
<h1><Icon name="ban"/></h1>
|
<h1><Icon name="ban"/></h1>
|
||||||
<p>Sorry, there's nothing here!</p>
|
<p>Sorry, there's nothing here!</p>
|
||||||
|
@ -18,16 +18,18 @@ module.exports = React.createClass({
|
|||||||
})
|
})
|
||||||
},
|
},
|
||||||
upDate: function () {
|
upDate: function () {
|
||||||
if(this.isMounted())
|
if (this.isMounted()) {
|
||||||
this.setState({ text: this.state.moment.unix(this.props.date).fromNow() })
|
this.setState({ text: this.state.moment.unix(this.props.date).fromNow() })
|
||||||
else
|
} else {
|
||||||
clearInterval(this.state.interval)
|
clearInterval(this.state.interval)
|
||||||
|
}
|
||||||
},
|
},
|
||||||
getDate: function () {
|
getDate: function () {
|
||||||
if(this.state.moment)
|
if (this.state.moment) {
|
||||||
return this.state.text
|
return this.state.text
|
||||||
else
|
} else {
|
||||||
return <Icon name="refresh" className="fa-spin" />
|
return <Icon name="refresh" className="fa-spin" />
|
||||||
|
}
|
||||||
},
|
},
|
||||||
render: function () {
|
render: function () {
|
||||||
return <div className="inline"><Icon name="clock-o" className={this.props.className} /> {this.getDate()}</div>
|
return <div className="inline"><Icon name="clock-o" className={this.props.className} /> {this.getDate()}</div>
|
||||||
|
@ -62,8 +62,9 @@ var Comments = React.createClass({
|
|||||||
boards.getCommentsFor(this.props.parent, this.props.board, this.props.adminID)
|
boards.getCommentsFor(this.props.parent, this.props.board, this.props.adminID)
|
||||||
}
|
}
|
||||||
boards.getEventEmitter().on('init', err => {
|
boards.getEventEmitter().on('init', err => {
|
||||||
if(!err && this.isMounted())
|
if (!err && this.isMounted()) {
|
||||||
boards.getCommentsFor(this.props.parent, this.props.board, this.props.adminID)
|
boards.getCommentsFor(this.props.parent, this.props.board, this.props.adminID)
|
||||||
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
module.exports = {
|
module.exports = {
|
||||||
get: function () {
|
get: function () {
|
||||||
var opt, s = localStorage.getItem('ipfs-boards-settings')
|
var opt
|
||||||
|
var s = window.localStorage.getItem('ipfs-boards-settings')
|
||||||
try {
|
try {
|
||||||
opt = JSON.parse(s)
|
opt = JSON.parse(s)
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
@ -13,8 +13,7 @@ module.exports = React.createClass({
|
|||||||
init: function (boards) {
|
init: function (boards) {
|
||||||
if (this.state.init) return
|
if (this.state.init) return
|
||||||
this.setState({ api: true })
|
this.setState({ api: true })
|
||||||
boards.getPostsInBoard(this.props.admin,this.props.board)
|
var onPost = (post, hash) => {
|
||||||
.on('post in '+this.props.board+(this.props.admin?'@'+this.props.admin:''),(post,hash) => {
|
|
||||||
if (!this.isMounted()) return true
|
if (!this.isMounted()) return true
|
||||||
var now = (new Date()).getTime()
|
var now = (new Date()).getTime()
|
||||||
var posts = this.state.posts
|
var posts = this.state.posts
|
||||||
@ -27,26 +26,33 @@ module.exports = React.createClass({
|
|||||||
console.log('Post discarded cause date in the future:', post)
|
console.log('Post discarded cause date in the future:', post)
|
||||||
}
|
}
|
||||||
this.setState({ posts })
|
this.setState({ posts })
|
||||||
})
|
}
|
||||||
|
boards.getEventEmitter().on('post in ' + this.props.board + (this.props.admin ? '@' + this.props.admin : ''), onPost)
|
||||||
|
boards.getPostsInBoard(this.props.admin, this.props.board)
|
||||||
this.setState({ init: true })
|
this.setState({ init: true })
|
||||||
},
|
},
|
||||||
componentDidMount: function () {
|
componentDidMount: function () {
|
||||||
var boards = this.props.api
|
var boards = this.props.api
|
||||||
if (boards) {
|
if (boards) {
|
||||||
if(boards.isInit) this.init(boards)
|
if (boards.isInit) {
|
||||||
else boards.getEventEmitter().on('init',err => {
|
this.init(boards)
|
||||||
|
} else {
|
||||||
|
boards.getEventEmitter().on('init', err => {
|
||||||
if (!err && this.isMounted()) this.init(boards)
|
if (!err && this.isMounted()) this.init(boards)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
}
|
||||||
},
|
},
|
||||||
getPosts: function () {
|
getPosts: function () {
|
||||||
if (this.state.posts.length > 0 || this.state.api) {
|
if (this.state.posts.length > 0 || this.state.api) {
|
||||||
return this.state.posts.map(post => {
|
return this.state.posts.map(post => {
|
||||||
return <Post key={post.hash} board={this.props.board} admin={this.props.admin} post={post} api={this.props.api} />
|
return <Post key={post.hash} board={this.props.board} admin={this.props.admin} post={post} api={this.props.api} />
|
||||||
})
|
})
|
||||||
} else return <div className="center-block text-center">
|
} else {
|
||||||
|
return <div className="center-block text-center">
|
||||||
<Icon name="refresh" className="fa-3x center-block light fa-spin" />
|
<Icon name="refresh" className="fa-3x center-block light fa-spin" />
|
||||||
</div>
|
</div>
|
||||||
|
}
|
||||||
},
|
},
|
||||||
render: function () {
|
render: function () {
|
||||||
return (
|
return (
|
||||||
|
@ -37,15 +37,16 @@ module.exports = React.createClass({
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
render: function () {
|
render: function () {
|
||||||
if(this.props.id === undefined || this.props.id === 'undefined')
|
if (this.props.id === undefined || this.props.id === 'undefined') {
|
||||||
return <div className="user-id">
|
return <div className="user-id">
|
||||||
<Icon name="ban" /> Unknown User
|
<Icon name="ban" /> Unknown User
|
||||||
</div>
|
</div>
|
||||||
else
|
} else {
|
||||||
return (<div className="user-id">
|
return (<div className="user-id">
|
||||||
<Link className="light nounderline" to={'/@' + this.props.id}>
|
<Link className="light nounderline" to={'/@' + this.props.id}>
|
||||||
{this.getContent()}{this.state.name || this.props.id}
|
{this.getContent()}{this.state.name || this.props.id}
|
||||||
</Link>
|
</Link>
|
||||||
</div>)
|
</div>)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
@ -1,7 +1,5 @@
|
|||||||
var React = require('react')
|
var React = require('react')
|
||||||
var Markdown = require('markdown.jsx')
|
var Markdown = require('markdown.jsx')
|
||||||
var Link = require('react-router').Link
|
|
||||||
var Icon = require('icon.jsx')
|
|
||||||
var UserID = require('userID.jsx')
|
var UserID = require('userID.jsx')
|
||||||
var PostList = require('postlist.jsx')
|
var PostList = require('postlist.jsx')
|
||||||
var GetIPFS = require('getipfs.jsx')
|
var GetIPFS = require('getipfs.jsx')
|
||||||
@ -29,9 +27,9 @@ module.exports = function(boardsAPI){
|
|||||||
})
|
})
|
||||||
if (this.props.params.userid) {
|
if (this.props.params.userid) {
|
||||||
ee.on('whitelist for ' + this.props.params.boardname + '@' + this.props.params.userid, (whitelist) => {
|
ee.on('whitelist for ' + this.props.params.boardname + '@' + this.props.params.userid, (whitelist) => {
|
||||||
if(this.isMounted())
|
if (this.isMounted()) {
|
||||||
this.setState({ whitelist })
|
this.setState({ whitelist })
|
||||||
else return true
|
} else return true
|
||||||
})
|
})
|
||||||
ee.on('settings for ' + this.props.params.boardname + '@' + this.props.params.userid, (res) => {
|
ee.on('settings for ' + this.props.params.boardname + '@' + this.props.params.userid, (res) => {
|
||||||
if (!this.isMounted()) return true
|
if (!this.isMounted()) return true
|
||||||
@ -47,8 +45,9 @@ module.exports = function(boardsAPI){
|
|||||||
},
|
},
|
||||||
init: function (boards) {
|
init: function (boards) {
|
||||||
if (!this.state.init) {
|
if (!this.state.init) {
|
||||||
if(this.props.params.userid)
|
if (this.props.params.userid) {
|
||||||
boards.getBoardSettings(this.props.params.userid, this.props.params.boardname)
|
boards.getBoardSettings(this.props.params.userid, this.props.params.boardname)
|
||||||
|
}
|
||||||
this.setState({ init: true, api: true, boards: boards })
|
this.setState({ init: true, api: true, boards: boards })
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -3,7 +3,6 @@ var Link = require('react-router').Link
|
|||||||
var Icon = require('icon.jsx')
|
var Icon = require('icon.jsx')
|
||||||
var UserID = require('userID.jsx')
|
var UserID = require('userID.jsx')
|
||||||
var GetIPFS = require('getipfs.jsx')
|
var GetIPFS = require('getipfs.jsx')
|
||||||
var Post = require('post.jsx')
|
|
||||||
var Comment = require('comment.jsx').Comment
|
var Comment = require('comment.jsx').Comment
|
||||||
|
|
||||||
module.exports = function (boardsAPI) {
|
module.exports = function (boardsAPI) {
|
||||||
@ -31,7 +30,9 @@ module.exports = function(boardsAPI){
|
|||||||
this.setState({ comment: false })
|
this.setState({ comment: false })
|
||||||
boards.downloadComment(props.params.commenthash, props.params.userid, props.params.boardname, (err, comment) => {
|
boards.downloadComment(props.params.commenthash, props.params.userid, props.params.boardname, (err, comment) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
this.setState({ comment: { title: 'Error', text: err.Message || err.Error }})
|
this.setState({
|
||||||
|
comment: { title: 'Error', text: err.Message || err.Error }
|
||||||
|
})
|
||||||
} else {
|
} else {
|
||||||
this.setState({ comment })
|
this.setState({ comment })
|
||||||
}
|
}
|
||||||
@ -44,10 +45,11 @@ module.exports = function(boardsAPI){
|
|||||||
},
|
},
|
||||||
getContext: function () {
|
getContext: function () {
|
||||||
if (this.props.params.userid) {
|
if (this.props.params.userid) {
|
||||||
if(this.props.params.boardname)
|
if (this.props.params.boardname) {
|
||||||
return <div>Comment by <UserID id={this.props.params.userid} api={this.state.boards} /> in <Link to={'@' + this.props.params.userid + '/' + this.props.params.boardname}>#{this.props.params.boardname}</Link> to <Link to={'/@' + this.props.params.userid + '/' + this.props.params.boardname + '/' + this.props.params.posthash }>{this.props.params.posthash}</Link></div>
|
return <div>Comment by <UserID id={this.props.params.userid} api={this.state.boards} /> in <Link to={'@' + this.props.params.userid + '/' + this.props.params.boardname}>#{this.props.params.boardname}</Link> to <Link to={'/@' + this.props.params.userid + '/' + this.props.params.boardname + '/' + this.props.params.posthash }>{this.props.params.posthash}</Link></div>
|
||||||
else
|
} else {
|
||||||
return <div>Comment by <UserID id={this.props.params.userid} api={this.state.boards} /></div>
|
return <div>Comment by <UserID id={this.props.params.userid} api={this.state.boards} /></div>
|
||||||
|
}
|
||||||
} else return <div><h6 className="light">You are viewing a single comment</h6></div>
|
} else return <div><h6 className="light">You are viewing a single comment</h6></div>
|
||||||
},
|
},
|
||||||
showComment: function () {
|
showComment: function () {
|
||||||
@ -61,14 +63,16 @@ module.exports = function(boardsAPI){
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
render: function () {
|
render: function () {
|
||||||
if(this.state.api)
|
if (this.state.api) {
|
||||||
return <div className="comment-page">
|
return <div className="comment-page">
|
||||||
<div className="text-center">
|
<div className="text-center">
|
||||||
{this.getContext()}
|
{this.getContext()}
|
||||||
</div>
|
</div>
|
||||||
{this.showComment()}
|
{this.showComment()}
|
||||||
</div>
|
</div>
|
||||||
else return <GetIPFS api={this.state.boards} />
|
} else {
|
||||||
|
return <GetIPFS api={this.state.boards} />
|
||||||
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -29,7 +29,9 @@ module.exports = function(boardsAPI){
|
|||||||
downloadPost: function (boards, props) {
|
downloadPost: function (boards, props) {
|
||||||
boards.downloadPost(props.params.posthash, props.params.userid, props.params.boardname, props.params.userid, (err, post) => {
|
boards.downloadPost(props.params.posthash, props.params.userid, props.params.boardname, props.params.userid, (err, post) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
this.setState({ post: { title: 'Error', text: err.Message || err.Error }})
|
this.setState({
|
||||||
|
post: { title: 'Error', text: err.Message || err.Error }
|
||||||
|
})
|
||||||
} else {
|
} else {
|
||||||
this.setState({ post })
|
this.setState({ post })
|
||||||
}
|
}
|
||||||
@ -42,14 +44,15 @@ module.exports = function(boardsAPI){
|
|||||||
},
|
},
|
||||||
getContext: function () {
|
getContext: function () {
|
||||||
if (this.props.params.userid) {
|
if (this.props.params.userid) {
|
||||||
if(this.props.params.boardname)
|
if (this.props.params.boardname) {
|
||||||
return <div>Posted by <UserID id={this.props.params.userid} api={this.state.boards} /> in <Link to={'@' + this.props.params.userid + '/' + this.props.params.boardname}>#{this.props.params.boardname}</Link></div>
|
return <div>Posted by <UserID id={this.props.params.userid} api={this.state.boards} /> in <Link to={'@' + this.props.params.userid + '/' + this.props.params.boardname}>#{this.props.params.boardname}</Link></div>
|
||||||
else
|
} else {
|
||||||
return <div>Posted by <UserID id={this.props.params.userid} api={this.state.boards} /></div>
|
return <div>Posted by <UserID id={this.props.params.userid} api={this.state.boards} /></div>
|
||||||
|
}
|
||||||
} else return <div><h6 className="light">You are viewing a single post</h6></div>
|
} else return <div><h6 className="light">You are viewing a single post</h6></div>
|
||||||
},
|
},
|
||||||
render: function () {
|
render: function () {
|
||||||
if(this.state.api)
|
if (this.state.api) {
|
||||||
return <div className="post-page">
|
return <div className="post-page">
|
||||||
<div className="text-center">
|
<div className="text-center">
|
||||||
{this.getContext()}
|
{this.getContext()}
|
||||||
@ -57,7 +60,9 @@ module.exports = function(boardsAPI){
|
|||||||
<Post post={this.state.post} board={this.props.params.boardname} api={this.state.boards} />
|
<Post post={this.state.post} board={this.props.params.boardname} api={this.state.boards} />
|
||||||
<Comments parent={this.props.params.posthash} board={this.props.params.boardname} adminID={this.props.params.userid} post={this.props.params.posthash} api={this.state.boards} />
|
<Comments parent={this.props.params.posthash} board={this.props.params.boardname} adminID={this.props.params.userid} post={this.props.params.posthash} api={this.state.boards} />
|
||||||
</div>
|
</div>
|
||||||
else return <GetIPFS api={this.state.boards} />
|
} else {
|
||||||
|
return <GetIPFS api={this.state.boards} />
|
||||||
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -51,9 +51,7 @@ module.exports = function(boardsAPI){
|
|||||||
},
|
},
|
||||||
init: function (boards) {
|
init: function (boards) {
|
||||||
if (this.state.init) return
|
if (this.state.init) return
|
||||||
var ee = boards.getEventEmitter()
|
|
||||||
if (boards.isInit || this.state.api) {
|
if (boards.isInit || this.state.api) {
|
||||||
var uid = this.props.params.userid
|
|
||||||
this.downloadProfile(boards, this.props)
|
this.downloadProfile(boards, this.props)
|
||||||
this.setState({ init: true })
|
this.setState({ init: true })
|
||||||
}
|
}
|
||||||
|
@ -13,22 +13,22 @@ module.exports = function(boardsAPI){
|
|||||||
if (!err && this.isMounted()) this.setState({ api: true })
|
if (!err && this.isMounted()) this.setState({ api: true })
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
var s = localStorage.getItem('ipfs-boards-settings')
|
var s = window.localStorage.getItem('ipfs-boards-settings')
|
||||||
var obj = this.getDefaults()
|
var obj = this.getDefaults()
|
||||||
try {
|
try {
|
||||||
obj = JSON.parse(s)
|
obj = JSON.parse(s)
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
localStorage.removeItem('ipfs-boards-settings')
|
window.localStorage.removeItem('ipfs-boards-settings')
|
||||||
}
|
}
|
||||||
return obj || this.getDefaults()
|
return obj || this.getDefaults()
|
||||||
},
|
},
|
||||||
save: function () {
|
save: function () {
|
||||||
if(isNaN(this.state.port) || parseInt(this.state.port) > 65535 || parseInt(this.state.port) < 1){
|
if (isNaN(this.state.port) || parseInt(this.state.port, 10) > 65535 || parseInt(this.state.port, 10) < 1) {
|
||||||
alert('Port number invalid')
|
window.alert('Port number invalid')
|
||||||
} else {
|
} else {
|
||||||
localStorage.setItem('ipfs-boards-settings',JSON.stringify({
|
window.localStorage.setItem('ipfs-boards-settings', JSON.stringify({
|
||||||
addr: this.state.addr,
|
addr: this.state.addr,
|
||||||
port: parseInt(this.state.port)
|
port: parseInt(this.state.port, 10)
|
||||||
}))
|
}))
|
||||||
window.location.reload(false)
|
window.location.reload(false)
|
||||||
}
|
}
|
||||||
@ -77,5 +77,4 @@ module.exports = function(boardsAPI){
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -23,7 +23,8 @@ var config = {
|
|||||||
eslint: {
|
eslint: {
|
||||||
configFile: './.eslintrc',
|
configFile: './.eslintrc',
|
||||||
failOnWarning: true,
|
failOnWarning: true,
|
||||||
failOnError: true
|
failOnError: true,
|
||||||
|
fix: true
|
||||||
},
|
},
|
||||||
module: {
|
module: {
|
||||||
preLoaders: [
|
preLoaders: [
|
||||||
@ -96,7 +97,7 @@ config.devServer = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function addTransformRuntime (l) {
|
function addTransformRuntime (l) {
|
||||||
if(process.env.os != 'Windows_NT'){
|
if (process.env.os !== 'Windows_NT') {
|
||||||
// Workaround for babel6 bug on windows
|
// Workaround for babel6 bug on windows
|
||||||
// https://phabricator.babeljs.io/T6670
|
// https://phabricator.babeljs.io/T6670
|
||||||
// https://phabricator.babeljs.io/T2954
|
// https://phabricator.babeljs.io/T2954
|
||||||
|
Loading…
Reference in New Issue
Block a user