mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2026-01-20 18:22:40 +00:00
Unify brew structure in all pages
This commit is contained in:
@@ -22,7 +22,8 @@ const KEY = 'homebrewery-new';
|
||||
const NewPage = createClass({
|
||||
getInitialState : function() {
|
||||
return {
|
||||
metadata : {
|
||||
brew : {
|
||||
text : '',
|
||||
gDrive : false,
|
||||
title : '',
|
||||
description : '',
|
||||
@@ -32,7 +33,6 @@ const NewPage = createClass({
|
||||
systems : []
|
||||
},
|
||||
|
||||
text : '',
|
||||
isSaving : false,
|
||||
saveGoogle : (global.account && global.account.googleId ? true : false),
|
||||
errors : []
|
||||
@@ -43,7 +43,7 @@ const NewPage = createClass({
|
||||
const storage = localStorage.getItem(KEY);
|
||||
if(storage){
|
||||
this.setState({
|
||||
text : storage
|
||||
brew : { text: storage }
|
||||
});
|
||||
}
|
||||
document.addEventListener('keydown', this.handleControlKeys);
|
||||
@@ -70,13 +70,13 @@ const NewPage = createClass({
|
||||
|
||||
handleMetadataChange : function(metadata){
|
||||
this.setState({
|
||||
metadata : _.merge({}, this.state.metadata, metadata)
|
||||
brew : _.merge({}, this.state.brew, metadata)
|
||||
});
|
||||
},
|
||||
|
||||
handleTextChange : function(text){
|
||||
this.setState({
|
||||
text : text,
|
||||
brew : { text: text },
|
||||
errors : Markdown.validate(text)
|
||||
});
|
||||
localStorage.setItem(KEY, text);
|
||||
@@ -92,7 +92,7 @@ const NewPage = createClass({
|
||||
if(this.state.saveGoogle) {
|
||||
const res = await request
|
||||
.post('/api/newGoogle/')
|
||||
.send(_.merge({}, this.state.metadata, { text: this.state.text }))
|
||||
.send(this.state.brew)
|
||||
.catch((err)=>{
|
||||
console.log(err.status === 401
|
||||
? 'Not signed in!'
|
||||
@@ -106,9 +106,7 @@ const NewPage = createClass({
|
||||
window.location = `/edit/${brew.googleId}${brew.editId}`;
|
||||
} else {
|
||||
request.post('/api')
|
||||
.send(_.merge({}, this.state.metadata, {
|
||||
text : this.state.text
|
||||
}))
|
||||
.send(this.state.brew)
|
||||
.end((err, res)=>{
|
||||
if(err){
|
||||
this.setState({
|
||||
@@ -122,7 +120,6 @@ const NewPage = createClass({
|
||||
window.location = `/edit/${brew.editId}`;
|
||||
});
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
renderSaveButton : function(){
|
||||
@@ -138,7 +135,7 @@ const NewPage = createClass({
|
||||
},
|
||||
|
||||
print : function(){
|
||||
localStorage.setItem('print', this.state.text);
|
||||
localStorage.setItem('print', this.state.brew.text);
|
||||
window.open('/print?dialog=true&local=print', '_blank');
|
||||
},
|
||||
|
||||
@@ -152,7 +149,7 @@ const NewPage = createClass({
|
||||
return <Navbar>
|
||||
|
||||
<Nav.section>
|
||||
<Nav.item className='brewTitle'>{this.state.metadata.title}</Nav.item>
|
||||
<Nav.item className='brewTitle'>{this.state.brew.title}</Nav.item>
|
||||
</Nav.section>
|
||||
|
||||
<Nav.section>
|
||||
@@ -172,12 +169,11 @@ const NewPage = createClass({
|
||||
<SplitPane onDragFinish={this.handleSplitMove} ref='pane'>
|
||||
<Editor
|
||||
ref='editor'
|
||||
value={this.state.text}
|
||||
brew={this.state.brew}
|
||||
onChange={this.handleTextChange}
|
||||
metadata={this.state.metadata}
|
||||
onMetadataChange={this.handleMetadataChange}
|
||||
/>
|
||||
<BrewRenderer text={this.state.text} errors={this.state.errors} />
|
||||
<BrewRenderer text={this.state.brew.text} errors={this.state.errors} />
|
||||
</SplitPane>
|
||||
</div>
|
||||
</div>;
|
||||
|
||||
Reference in New Issue
Block a user