mirror of
https://github.com/fazo96/ipfs-boards
synced 2025-02-04 16:34:19 +01:00
added a post editor, doesn't work yet though
This commit is contained in:
parent
4081d5aa12
commit
0020f52a48
@ -27,6 +27,7 @@ var PostPage = require('postpage.jsx')(boards)
|
|||||||
var CommentPage = require('commentpage.jsx')(boards)
|
var CommentPage = require('commentpage.jsx')(boards)
|
||||||
var ProfileEditor = require('profile-editor.jsx')(boards)
|
var ProfileEditor = require('profile-editor.jsx')(boards)
|
||||||
var BoardEditor = require('board-editor.jsx')(boards)
|
var BoardEditor = require('board-editor.jsx')(boards)
|
||||||
|
var PostEditor = require('post-editor.jsx')(boards)
|
||||||
|
|
||||||
// Define Main Components
|
// Define Main Components
|
||||||
|
|
||||||
@ -93,9 +94,9 @@ ReactDOM.render(
|
|||||||
</Route>
|
</Route>
|
||||||
<Route path="edit">
|
<Route path="edit">
|
||||||
<Route path="profile" component={ProfileEditor} />
|
<Route path="profile" component={ProfileEditor} />
|
||||||
<Route path="board" component={BoardEditor}>
|
<Route path="board(/:boardname)">
|
||||||
<Route path=":boardname" component={BoardEditor}>
|
<IndexRoute component={BoardEditor} />
|
||||||
</Route>
|
<Route path="post(/:posthash)" component={PostEditor} />
|
||||||
</Route>
|
</Route>
|
||||||
</Route>
|
</Route>
|
||||||
<Route path="post/:posthash" component={PostPage} />
|
<Route path="post/:posthash" component={PostPage} />
|
||||||
|
103
webapp/pages/post-editor.jsx
Normal file
103
webapp/pages/post-editor.jsx
Normal file
@ -0,0 +1,103 @@
|
|||||||
|
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')
|
||||||
|
|
||||||
|
module.exports = function (boardsAPI) {
|
||||||
|
return React.createClass({
|
||||||
|
getInitialState () {
|
||||||
|
return { }
|
||||||
|
},
|
||||||
|
componentDidMount () {
|
||||||
|
boardsAPI.use(boards => {
|
||||||
|
boards.init()
|
||||||
|
boards.getEventEmitter().on('init', err => {
|
||||||
|
if (!err && this.isMounted()) {
|
||||||
|
this.init(boards)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
if (this.isMounted() && boards.isInit) {
|
||||||
|
this.init(boards)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
},
|
||||||
|
init (boards) {
|
||||||
|
if (this.state.init) return
|
||||||
|
this.setState({ api: boards, init: true })
|
||||||
|
// TODO: DOWNLOAD POST
|
||||||
|
},
|
||||||
|
handleChange (event) {
|
||||||
|
var obj = {}
|
||||||
|
obj[event.target.id] = event.target.value
|
||||||
|
this.setState(obj)
|
||||||
|
},
|
||||||
|
skip () {
|
||||||
|
this.setState({ loading: false, updating: false, error: false })
|
||||||
|
},
|
||||||
|
refresh () {
|
||||||
|
this.setState({ loading: true })
|
||||||
|
// boardsAPI.use(b => this.getBoardSettings(b))
|
||||||
|
// TODO: DOWNLOAD POST
|
||||||
|
},
|
||||||
|
save () {
|
||||||
|
this.setState({ updating: true })
|
||||||
|
// TODO: SAVE POST IMPL
|
||||||
|
},
|
||||||
|
additionalButtons () {
|
||||||
|
if (this.state.api && this.props.params.posthash) {
|
||||||
|
var url = '/@' + this.state.api.getMyID() + '/' + this.props.params.boardname + '/post/' + this.props.params.posthash
|
||||||
|
return <span>
|
||||||
|
<button onClick={this.refresh} className="button not-first">Refresh</button>
|
||||||
|
<Link to={url} className="button not-first">View</Link>
|
||||||
|
</span>
|
||||||
|
} else {
|
||||||
|
return <span></span>
|
||||||
|
}
|
||||||
|
},
|
||||||
|
render () {
|
||||||
|
if (this.state.api) {
|
||||||
|
if (this.state.error) {
|
||||||
|
return <Error error={this.state.error} >
|
||||||
|
<button className="button button-primary center-block" onClick={this.skip}>Continue</button>
|
||||||
|
</Error>
|
||||||
|
} else if (this.state.loading) {
|
||||||
|
return <Loading title="Downloading Post">
|
||||||
|
<button className="button button-primary center-block" onClick={this.skip}>Skip</button>
|
||||||
|
</Loading>
|
||||||
|
} else if (this.state.updating) {
|
||||||
|
return <Saving>
|
||||||
|
<p>Pressing the Skip button will not abort the publish operation.</p>
|
||||||
|
<button className="button button-primary center-block" onClick={this.skip}>Skip</button>
|
||||||
|
</Saving>
|
||||||
|
} else {
|
||||||
|
return (
|
||||||
|
<div className="editor">
|
||||||
|
<h2><Icon name="pencil" className="light" />
|
||||||
|
{this.props.params.posthash ? ' Edit Post' : ' New Post'}
|
||||||
|
</h2>
|
||||||
|
<p>This App uses IPFS to store your Posts. When you are offline,
|
||||||
|
other users or servers that viewed your content will serve it to
|
||||||
|
others.</p>
|
||||||
|
<p><b>Warning:</b> due to a bug in go-ipfs, it may take up to a minute
|
||||||
|
for your changes to be visibile. Your Post will not appear or appear
|
||||||
|
unchanged during this time.</p>
|
||||||
|
<div>
|
||||||
|
<label htmlFor="title">Title</label>
|
||||||
|
<input className="u-full-width" type="text" id="title" value={this.state.title} onChange={this.handleChange} placeholder="Choose a title" />
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<label htmlFor="desc">Content</label>
|
||||||
|
<textarea className="u-full-width" id="desc" value={this.state.desc} onChange={this.handleChange} placeholder="Write your post. Markdown is supported :)" />
|
||||||
|
</div>
|
||||||
|
<div className="buttons">
|
||||||
|
<button className="button button-primary" onClick={this.save}>Publish</button>
|
||||||
|
{this.additionalButtons()}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
} else return <GetIPFS api={this.state.api} />
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user