mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2026-01-16 12:32:39 +00:00
Unify brew structure in all pages
This commit is contained in:
@@ -18,7 +18,9 @@ const SNIPPETBAR_HEIGHT = 25;
|
|||||||
const Editor = createClass({
|
const Editor = createClass({
|
||||||
getDefaultProps : function() {
|
getDefaultProps : function() {
|
||||||
return {
|
return {
|
||||||
brew : {},
|
brew : {
|
||||||
|
text : ''
|
||||||
|
},
|
||||||
onChange : ()=>{},
|
onChange : ()=>{},
|
||||||
|
|
||||||
onMetadataChange : ()=>{},
|
onMetadataChange : ()=>{},
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ const MetadataEditor = createClass({
|
|||||||
},
|
},
|
||||||
|
|
||||||
handleDelete : function(){
|
handleDelete : function(){
|
||||||
if(this.props.metadata.authors.length <= 1){
|
if(this.props.metadata.authors && this.props.metadata.authors.length <= 1){
|
||||||
if(!confirm('Are you sure you want to delete this brew? Because you are the only owner of this brew, the document will be deleted permanently.')) return;
|
if(!confirm('Are you sure you want to delete this brew? Because you are the only owner of this brew, the document will be deleted permanently.')) return;
|
||||||
if(!confirm('Are you REALLY sure? You will not be able to recover the document.')) return;
|
if(!confirm('Are you REALLY sure? You will not be able to recover the document.')) return;
|
||||||
} else {
|
} else {
|
||||||
@@ -114,7 +114,7 @@ const MetadataEditor = createClass({
|
|||||||
|
|
||||||
renderAuthors : function(){
|
renderAuthors : function(){
|
||||||
let text = 'None.';
|
let text = 'None.';
|
||||||
if(this.props.metadata.authors.length){
|
if(this.props.metadata.authors && this.props.metadata.authors.length){
|
||||||
text = this.props.metadata.authors.join(', ');
|
text = this.props.metadata.authors.join(', ');
|
||||||
}
|
}
|
||||||
return <div className='field authors'>
|
return <div className='field authors'>
|
||||||
|
|||||||
@@ -21,6 +21,9 @@ const BrewRenderer = require('../../brewRenderer/brewRenderer.jsx');
|
|||||||
const HomePage = createClass({
|
const HomePage = createClass({
|
||||||
getDefaultProps : function() {
|
getDefaultProps : function() {
|
||||||
return {
|
return {
|
||||||
|
brew : {
|
||||||
|
text : ''
|
||||||
|
},
|
||||||
welcomeText : '',
|
welcomeText : '',
|
||||||
ver : '0.0.0'
|
ver : '0.0.0'
|
||||||
};
|
};
|
||||||
@@ -29,13 +32,15 @@ const HomePage = createClass({
|
|||||||
},
|
},
|
||||||
getInitialState : function() {
|
getInitialState : function() {
|
||||||
return {
|
return {
|
||||||
text : this.props.welcomeText
|
brew : {
|
||||||
|
text : this.props.welcomeText
|
||||||
|
}
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
handleSave : function(){
|
handleSave : function(){
|
||||||
request.post('/api')
|
request.post('/api')
|
||||||
.send({
|
.send({
|
||||||
text : this.state.text
|
text : this.state.brew.text
|
||||||
})
|
})
|
||||||
.end((err, res)=>{
|
.end((err, res)=>{
|
||||||
if(err) return;
|
if(err) return;
|
||||||
@@ -48,7 +53,7 @@ const HomePage = createClass({
|
|||||||
},
|
},
|
||||||
handleTextChange : function(text){
|
handleTextChange : function(text){
|
||||||
this.setState({
|
this.setState({
|
||||||
text : text
|
brew : { text: text }
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
renderNavbar : function(){
|
renderNavbar : function(){
|
||||||
@@ -71,12 +76,12 @@ const HomePage = createClass({
|
|||||||
|
|
||||||
<div className='content'>
|
<div className='content'>
|
||||||
<SplitPane onDragFinish={this.handleSplitMove} ref='pane'>
|
<SplitPane onDragFinish={this.handleSplitMove} ref='pane'>
|
||||||
<Editor value={this.state.text} onChange={this.handleTextChange} showMetaButton={false} ref='editor'/>
|
<Editor brew={this.state.brew} onChange={this.handleTextChange} showMetaButton={false} ref='editor'/>
|
||||||
<BrewRenderer text={this.state.text} />
|
<BrewRenderer text={this.state.brew.text} />
|
||||||
</SplitPane>
|
</SplitPane>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className={cx('floatingSaveButton', { show: this.props.welcomeText != this.state.text })} onClick={this.handleSave}>
|
<div className={cx('floatingSaveButton', { show: this.props.welcomeText != this.state.brew.text })} onClick={this.handleSave}>
|
||||||
Save current <i className='fas fa-save' />
|
Save current <i className='fas fa-save' />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
@@ -22,7 +22,8 @@ const KEY = 'homebrewery-new';
|
|||||||
const NewPage = createClass({
|
const NewPage = createClass({
|
||||||
getInitialState : function() {
|
getInitialState : function() {
|
||||||
return {
|
return {
|
||||||
metadata : {
|
brew : {
|
||||||
|
text : '',
|
||||||
gDrive : false,
|
gDrive : false,
|
||||||
title : '',
|
title : '',
|
||||||
description : '',
|
description : '',
|
||||||
@@ -32,7 +33,6 @@ const NewPage = createClass({
|
|||||||
systems : []
|
systems : []
|
||||||
},
|
},
|
||||||
|
|
||||||
text : '',
|
|
||||||
isSaving : false,
|
isSaving : false,
|
||||||
saveGoogle : (global.account && global.account.googleId ? true : false),
|
saveGoogle : (global.account && global.account.googleId ? true : false),
|
||||||
errors : []
|
errors : []
|
||||||
@@ -43,7 +43,7 @@ const NewPage = createClass({
|
|||||||
const storage = localStorage.getItem(KEY);
|
const storage = localStorage.getItem(KEY);
|
||||||
if(storage){
|
if(storage){
|
||||||
this.setState({
|
this.setState({
|
||||||
text : storage
|
brew : { text: storage }
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
document.addEventListener('keydown', this.handleControlKeys);
|
document.addEventListener('keydown', this.handleControlKeys);
|
||||||
@@ -70,13 +70,13 @@ const NewPage = createClass({
|
|||||||
|
|
||||||
handleMetadataChange : function(metadata){
|
handleMetadataChange : function(metadata){
|
||||||
this.setState({
|
this.setState({
|
||||||
metadata : _.merge({}, this.state.metadata, metadata)
|
brew : _.merge({}, this.state.brew, metadata)
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
handleTextChange : function(text){
|
handleTextChange : function(text){
|
||||||
this.setState({
|
this.setState({
|
||||||
text : text,
|
brew : { text: text },
|
||||||
errors : Markdown.validate(text)
|
errors : Markdown.validate(text)
|
||||||
});
|
});
|
||||||
localStorage.setItem(KEY, text);
|
localStorage.setItem(KEY, text);
|
||||||
@@ -92,7 +92,7 @@ const NewPage = createClass({
|
|||||||
if(this.state.saveGoogle) {
|
if(this.state.saveGoogle) {
|
||||||
const res = await request
|
const res = await request
|
||||||
.post('/api/newGoogle/')
|
.post('/api/newGoogle/')
|
||||||
.send(_.merge({}, this.state.metadata, { text: this.state.text }))
|
.send(this.state.brew)
|
||||||
.catch((err)=>{
|
.catch((err)=>{
|
||||||
console.log(err.status === 401
|
console.log(err.status === 401
|
||||||
? 'Not signed in!'
|
? 'Not signed in!'
|
||||||
@@ -106,9 +106,7 @@ const NewPage = createClass({
|
|||||||
window.location = `/edit/${brew.googleId}${brew.editId}`;
|
window.location = `/edit/${brew.googleId}${brew.editId}`;
|
||||||
} else {
|
} else {
|
||||||
request.post('/api')
|
request.post('/api')
|
||||||
.send(_.merge({}, this.state.metadata, {
|
.send(this.state.brew)
|
||||||
text : this.state.text
|
|
||||||
}))
|
|
||||||
.end((err, res)=>{
|
.end((err, res)=>{
|
||||||
if(err){
|
if(err){
|
||||||
this.setState({
|
this.setState({
|
||||||
@@ -122,7 +120,6 @@ const NewPage = createClass({
|
|||||||
window.location = `/edit/${brew.editId}`;
|
window.location = `/edit/${brew.editId}`;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
renderSaveButton : function(){
|
renderSaveButton : function(){
|
||||||
@@ -138,7 +135,7 @@ const NewPage = createClass({
|
|||||||
},
|
},
|
||||||
|
|
||||||
print : function(){
|
print : function(){
|
||||||
localStorage.setItem('print', this.state.text);
|
localStorage.setItem('print', this.state.brew.text);
|
||||||
window.open('/print?dialog=true&local=print', '_blank');
|
window.open('/print?dialog=true&local=print', '_blank');
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -152,7 +149,7 @@ const NewPage = createClass({
|
|||||||
return <Navbar>
|
return <Navbar>
|
||||||
|
|
||||||
<Nav.section>
|
<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>
|
||||||
|
|
||||||
<Nav.section>
|
<Nav.section>
|
||||||
@@ -172,12 +169,11 @@ const NewPage = createClass({
|
|||||||
<SplitPane onDragFinish={this.handleSplitMove} ref='pane'>
|
<SplitPane onDragFinish={this.handleSplitMove} ref='pane'>
|
||||||
<Editor
|
<Editor
|
||||||
ref='editor'
|
ref='editor'
|
||||||
value={this.state.text}
|
brew={this.state.brew}
|
||||||
onChange={this.handleTextChange}
|
onChange={this.handleTextChange}
|
||||||
metadata={this.state.metadata}
|
|
||||||
onMetadataChange={this.handleMetadataChange}
|
onMetadataChange={this.handleMetadataChange}
|
||||||
/>
|
/>
|
||||||
<BrewRenderer text={this.state.text} errors={this.state.errors} />
|
<BrewRenderer text={this.state.brew.text} errors={this.state.errors} />
|
||||||
</SplitPane>
|
</SplitPane>
|
||||||
</div>
|
</div>
|
||||||
</div>;
|
</div>;
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
"description": "Create authentic looking D&D homebrews using only markdown",
|
"description": "Create authentic looking D&D homebrews using only markdown",
|
||||||
"version": "2.10.7",
|
"version": "2.10.7",
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": "12.16.x"
|
"node": "14.15.x"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
|
|||||||
Reference in New Issue
Block a user