mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2026-01-03 06:12:51 +00:00
Linting and move checkLocalStorage inside confirmLocalStorageChange
This commit is contained in:
@@ -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.`);
|
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);
|
console.log(file);
|
||||||
};
|
};
|
||||||
reader.readAsText(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 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 no data in any local storage key
|
||||||
// TRUE if data in any local storage key AND approval given
|
// TRUE if data in any local storage key AND approval given
|
||||||
// FALSE if data in any local storage key AND approval declined
|
// 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?`
|
`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'
|
className='new'
|
||||||
color='purple'
|
color='purple'
|
||||||
icon='fa-solid fa-plus-square'>
|
icon='fa-solid fa-plus-square'>
|
||||||
new
|
new
|
||||||
</Nav.item>
|
</Nav.item>
|
||||||
<Nav.item
|
<Nav.item
|
||||||
className='new'
|
className='new'
|
||||||
@@ -83,7 +78,7 @@ const NewBrew = ()=>{
|
|||||||
newTab={true}
|
newTab={true}
|
||||||
color='purple'
|
color='purple'
|
||||||
icon='fa-solid fa-file'>
|
icon='fa-solid fa-file'>
|
||||||
resume editing
|
resume draft
|
||||||
</Nav.item>
|
</Nav.item>
|
||||||
<Nav.item
|
<Nav.item
|
||||||
className='fromBlank'
|
className='fromBlank'
|
||||||
@@ -91,16 +86,15 @@ const NewBrew = ()=>{
|
|||||||
color='yellow'
|
color='yellow'
|
||||||
icon='fa-solid fa-file-circle-plus'
|
icon='fa-solid fa-file-circle-plus'
|
||||||
onClick={()=>{ clearLocalStorage(); }}>
|
onClick={()=>{ clearLocalStorage(); }}>
|
||||||
from blank
|
from blank
|
||||||
</Nav.item>
|
</Nav.item>
|
||||||
|
|
||||||
<Nav.item
|
<Nav.item
|
||||||
className='fromFile'
|
className='fromFile'
|
||||||
color='green'
|
color='green'
|
||||||
icon='fa-solid fa-upload'
|
icon='fa-solid fa-upload'
|
||||||
onClick={()=>{ document.getElementById('uploadTxt').click(); }}>
|
onClick={()=>{ document.getElementById('uploadTxt').click(); }}>
|
||||||
<input id='uploadTxt' className='newFromLocal' type='file' onChange={handleFileChange} style={{ display: 'none' }} />
|
<input id='uploadTxt' className='newFromLocal' type='file' onChange={handleFileChange} style={{ display: 'none' }} />
|
||||||
from file
|
from file
|
||||||
</Nav.item>
|
</Nav.item>
|
||||||
</Nav.dropdown>
|
</Nav.dropdown>
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user