diff --git a/client/homebrew/editor/editor.jsx b/client/homebrew/editor/editor.jsx index a00c47403..0ffd2e8a0 100644 --- a/client/homebrew/editor/editor.jsx +++ b/client/homebrew/editor/editor.jsx @@ -58,7 +58,7 @@ const Editor = createClass({ return { editorTheme : this.props.editorTheme, view : 'text', //'text', 'style', 'meta', 'snippet' - snippetbarHeight : 25 + snippetBarHeight : 26, }; }, @@ -85,7 +85,15 @@ const Editor = createClass({ editorTheme : editorTheme }); } - this.setState({ snippetbarHeight: document.querySelector('.editor > .snippetBar').offsetHeight }); + const snippetBar = document.querySelector('.editor > .snippetBar'); + if (!snippetBar) return; + + this.resizeObserver = new ResizeObserver(entries => { + const height = document.querySelector('.editor > .snippetBar').offsetHeight; + this.setState({ snippetBarHeight: height }); + }); + + this.resizeObserver.observe(snippetBar); }, componentDidUpdate : function(prevProps, prevState, snapshot) { @@ -108,6 +116,10 @@ const Editor = createClass({ } }, + componentWillUnmount() { + if (this.resizeObserver) this.resizeObserver.disconnect(); + }, + handleControlKeys : function(e){ if(!(e.ctrlKey && e.metaKey && e.shiftKey)) return; const LEFTARROW_KEY = 37; @@ -408,11 +420,7 @@ const Editor = createClass({ }, //Called when there are changes to the editor's dimensions - update : function(){ - const snipHeight = document.querySelector('.editor > .snippetBar').offsetHeight; - if(snipHeight !== this.state.snippetbarHeight) - this.setState({ snippetbarHeight: snipHeight }); - }, + update : function(){}, updateEditorTheme : function(newTheme){ window.localStorage.setItem(EDITOR_THEME_KEY, newTheme); @@ -437,7 +445,7 @@ const Editor = createClass({ onChange={this.props.onBrewChange('text')} editorTheme={this.state.editorTheme} rerenderParent={this.rerenderParent} - style={{ height: `calc(100% - ${this.state.snippetbarHeight}px)` }} /> + style={{ height: `calc(100% - ${this.state.snippetBarHeight}px)` }} /> ; } if(this.isStyle()){ @@ -451,7 +459,7 @@ const Editor = createClass({ enableFolding={true} editorTheme={this.state.editorTheme} rerenderParent={this.rerenderParent} - style={{ height: `calc(100% - ${this.state.snippetbarHeight}px)` }} /> + style={{ height: `calc(100% - ${this.state.snippetBarHeight}px)` }} /> ; } if(this.isMeta()){ @@ -468,7 +476,6 @@ const Editor = createClass({ userThemes={this.props.userThemes}/> ; } - if(this.isSnip()){ if(!this.props.brew.snippets) { this.props.brew.snippets = DEFAULT_SNIPPET_TEXT; } return <> @@ -481,7 +488,7 @@ const Editor = createClass({ enableFolding={true} editorTheme={this.state.editorTheme} rerenderParent={this.rerenderParent} - style={{ height: `calc(100% - ${this.state.snippetbarHeight}px)` }} /> + style={{ height: `calc(100% -${this.state.snippetBarHeight}px)` }} /> ; } }, diff --git a/client/homebrew/editor/snippetbar/snippetbar.less b/client/homebrew/editor/snippetbar/snippetbar.less index c53d4be8e..8e50aa764 100644 --- a/client/homebrew/editor/snippetbar/snippetbar.less +++ b/client/homebrew/editor/snippetbar/snippetbar.less @@ -14,7 +14,7 @@ .snippets { display : flex; justify-content : flex-start; - min-width : 432.18px; //must be controlled every time an item is added, must be hardcoded for the wrapping as it is applied + min-width : 499.35px; //must be controlled every time an item is added, must be hardcoded for the wrapping as it is applied } .editors { @@ -237,7 +237,7 @@ } } -@container editor (width < 683px) { +@container editor (width < 750px) { .snippetBar { .editors { flex : 1; diff --git a/client/homebrew/navbar/newbrew.navitem.jsx b/client/homebrew/navbar/newbrew.navitem.jsx index fe8c05dc7..b8cf82ab7 100644 --- a/client/homebrew/navbar/newbrew.navitem.jsx +++ b/client/homebrew/navbar/newbrew.navitem.jsx @@ -3,19 +3,16 @@ const _ = require('lodash'); const Nav = require('client/homebrew/navbar/nav.jsx'); const { splitTextStyleAndMetadata } = require('../../../shared/helpers.js'); // Importing the function from helpers.js -const BREWKEY = 'homebrewery-new'; -const STYLEKEY = 'homebrewery-new-style'; -const METAKEY = 'homebrewery-new-meta'; +const BREWKEY = 'HB_newPage_content'; +const STYLEKEY = 'HB_newPage_style'; +const METAKEY = 'HB_newPage_meta'; const NewBrew = ()=>{ const handleFileChange = (e)=>{ const file = e.target.files[0]; if(!file) return; - const currentNew = localStorage.getItem(BREWKEY); - if(currentNew && !confirm( - `You have some text in the new brew space, if you load a file that text will be lost, are you sure you want to load the file?` - )) return; + if(!confirmLocalStorageChange()) return; const reader = new FileReader(); reader.onload = (e)=>{ @@ -37,12 +34,35 @@ const NewBrew = ()=>{ alert(`This file is invalid: ${!type ? 'Missing file extension' :`.${type} files are not supported`}. Only .txt files exported from the Homebrewery are allowed.`); - console.log(file); }; reader.readAsText(file); }; + const confirmLocalStorageChange = ()=>{ + const currentText = localStorage.getItem(BREWKEY); + const currentStyle = localStorage.getItem(STYLEKEY); + const currentMeta = localStorage.getItem(METAKEY); + + // TRUE if no data in any local storage key + // TRUE if data in any local storage key AND approval given + // FALSE if data in any local storage key AND approval declined + return (!(currentText || currentStyle || currentMeta) || confirm( + `You have made changes in the new brew space. If you continue, that information will be PERMANENTLY LOST.\nAre you sure you wish to continue?` + )); + }; + + const clearLocalStorage = ()=>{ + if(!confirmLocalStorageChange()) return; + + localStorage.removeItem(BREWKEY); + localStorage.removeItem(STYLEKEY); + localStorage.removeItem(METAKEY); + + window.location.href = '/new'; + return; + }; + return ( @@ -50,24 +70,31 @@ const NewBrew = ()=>{ className='new' color='purple' icon='fa-solid fa-plus-square'> - new + new - from blank + resume draft + + { clearLocalStorage(); }}> + from blank - { document.getElementById('uploadTxt').click(); }}> - from file + from file ); diff --git a/client/homebrew/pages/newPage/newPage.less b/client/homebrew/pages/newPage/newPage.less index 083e1ee09..d2f07ac40 100644 --- a/client/homebrew/pages/newPage/newPage.less +++ b/client/homebrew/pages/newPage/newPage.less @@ -1,12 +1,15 @@ .newPage { .navItem.save { - .fadeInRight(); - .transition(opacity); background-color : @orange; + transition:all 0.2s; &:hover { background-color : @green; } + &.neverSaved { - .fadeOutRight(); + translate:-100%; opacity: 0; + background-color :#333; + cursor:auto; } } } +