From c784e2e63bf287ec5c659f42a44e123a88226498 Mon Sep 17 00:00:00 2001 From: "G.Ambatte" Date: Sun, 16 Nov 2025 13:12:40 +1300 Subject: [PATCH 1/2] Fix New item on Nav Bar --- client/homebrew/navbar/newbrew.navitem.jsx | 51 ++++++++++++++++++---- 1 file changed, 42 insertions(+), 9 deletions(-) diff --git a/client/homebrew/navbar/newbrew.navitem.jsx b/client/homebrew/navbar/newbrew.navitem.jsx index d19b7595f..6197d6fc5 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('naturalcrit/nav/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)=>{ @@ -43,6 +40,34 @@ const NewBrew = ()=>{ reader.readAsText(file); }; + const checkLocalStorage = ()=>{ + // Check if changes exist for New editor + const currentText = localStorage.getItem(BREWKEY); + const currentStyle = localStorage.getItem(STYLEKEY); + const currentMeta = localStorage.getItem(METAKEY); + return (currentText || currentStyle || currentMeta); + }; + + const confirmLocalStorageChange = ()=>{ + // 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 (!checkLocalStorage() || 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 ( @@ -53,17 +78,25 @@ const NewBrew = ()=>{ new + resume editing + + { clearLocalStorage(); }}> from blank { document.getElementById('uploadTxt').click(); }}> From 429ad4d63b7bbdbe942455a0829ce4f8a676eb76 Mon Sep 17 00:00:00 2001 From: Trevor Buckner Date: Mon, 17 Nov 2025 23:48:56 -0500 Subject: [PATCH 2/2] Linting and move checkLocalStorage inside confirmLocalStorageChange --- client/homebrew/navbar/newbrew.navitem.jsx | 24 ++++++++-------------- 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/client/homebrew/navbar/newbrew.navitem.jsx b/client/homebrew/navbar/newbrew.navitem.jsx index 4914782a5..b8cf82ab7 100644 --- a/client/homebrew/navbar/newbrew.navitem.jsx +++ b/client/homebrew/navbar/newbrew.navitem.jsx @@ -34,25 +34,20 @@ 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 checkLocalStorage = ()=>{ - // Check if changes exist for New editor - const currentText = localStorage.getItem(BREWKEY); - const currentStyle = localStorage.getItem(STYLEKEY); - const currentMeta = localStorage.getItem(METAKEY); - return (currentText || currentStyle || currentMeta); - }; - 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 (!checkLocalStorage() || confirm( + 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?` )); }; @@ -75,7 +70,7 @@ const NewBrew = ()=>{ className='new' color='purple' icon='fa-solid fa-plus-square'> - new + new { newTab={true} color='purple' icon='fa-solid fa-file'> - resume editing + resume draft { color='yellow' icon='fa-solid fa-file-circle-plus' onClick={()=>{ clearLocalStorage(); }}> - from blank + from blank - { document.getElementById('uploadTxt').click(); }}> - from file + from file );