From 468b7319d19c52ba7962236b34bad81e8f149aea Mon Sep 17 00:00:00 2001 From: Trevor Buckner Date: Sat, 20 Feb 2021 21:59:18 -0500 Subject: [PATCH] Unify brew structure in all pages --- client/homebrew/editor/editor.jsx | 4 ++- .../editor/metadataEditor/metadataEditor.jsx | 4 +-- client/homebrew/pages/homePage/homePage.jsx | 17 +++++++----- client/homebrew/pages/newPage/newPage.jsx | 26 ++++++++----------- package.json | 2 +- 5 files changed, 28 insertions(+), 25 deletions(-) diff --git a/client/homebrew/editor/editor.jsx b/client/homebrew/editor/editor.jsx index 78dec5d85..d2bf5c836 100644 --- a/client/homebrew/editor/editor.jsx +++ b/client/homebrew/editor/editor.jsx @@ -18,7 +18,9 @@ const SNIPPETBAR_HEIGHT = 25; const Editor = createClass({ getDefaultProps : function() { return { - brew : {}, + brew : { + text : '' + }, onChange : ()=>{}, onMetadataChange : ()=>{}, diff --git a/client/homebrew/editor/metadataEditor/metadataEditor.jsx b/client/homebrew/editor/metadataEditor/metadataEditor.jsx index 89f6f4bb4..badd7bfbc 100644 --- a/client/homebrew/editor/metadataEditor/metadataEditor.jsx +++ b/client/homebrew/editor/metadataEditor/metadataEditor.jsx @@ -50,7 +50,7 @@ const MetadataEditor = createClass({ }, 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 REALLY sure? You will not be able to recover the document.')) return; } else { @@ -114,7 +114,7 @@ const MetadataEditor = createClass({ renderAuthors : function(){ 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(', '); } return
diff --git a/client/homebrew/pages/homePage/homePage.jsx b/client/homebrew/pages/homePage/homePage.jsx index d782b8b81..341c0fe11 100644 --- a/client/homebrew/pages/homePage/homePage.jsx +++ b/client/homebrew/pages/homePage/homePage.jsx @@ -21,6 +21,9 @@ const BrewRenderer = require('../../brewRenderer/brewRenderer.jsx'); const HomePage = createClass({ getDefaultProps : function() { return { + brew : { + text : '' + }, welcomeText : '', ver : '0.0.0' }; @@ -29,13 +32,15 @@ const HomePage = createClass({ }, getInitialState : function() { return { - text : this.props.welcomeText + brew : { + text : this.props.welcomeText + } }; }, handleSave : function(){ request.post('/api') .send({ - text : this.state.text + text : this.state.brew.text }) .end((err, res)=>{ if(err) return; @@ -48,7 +53,7 @@ const HomePage = createClass({ }, handleTextChange : function(text){ this.setState({ - text : text + brew : { text: text } }); }, renderNavbar : function(){ @@ -71,12 +76,12 @@ const HomePage = createClass({
- - + +
-
+
Save current
diff --git a/client/homebrew/pages/newPage/newPage.jsx b/client/homebrew/pages/newPage/newPage.jsx index 89727cbdb..8d20277f9 100644 --- a/client/homebrew/pages/newPage/newPage.jsx +++ b/client/homebrew/pages/newPage/newPage.jsx @@ -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 - {this.state.metadata.title} + {this.state.brew.title} @@ -172,12 +169,11 @@ const NewPage = createClass({ - +
; diff --git a/package.json b/package.json index c516cb83c..5a95f7422 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,7 @@ "description": "Create authentic looking D&D homebrews using only markdown", "version": "2.10.7", "engines": { - "node": "12.16.x" + "node": "14.15.x" }, "repository": { "type": "git",