mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2026-01-06 14:22:52 +00:00
Fix New item on Nav Bar
This commit is contained in:
@@ -3,19 +3,16 @@ const _ = require('lodash');
|
|||||||
const Nav = require('naturalcrit/nav/nav.jsx');
|
const Nav = require('naturalcrit/nav/nav.jsx');
|
||||||
const { splitTextStyleAndMetadata } = require('../../../shared/helpers.js'); // Importing the function from helpers.js
|
const { splitTextStyleAndMetadata } = require('../../../shared/helpers.js'); // Importing the function from helpers.js
|
||||||
|
|
||||||
const BREWKEY = 'homebrewery-new';
|
const BREWKEY = 'HB_newPage_content';
|
||||||
const STYLEKEY = 'homebrewery-new-style';
|
const STYLEKEY = 'HB_newPage_style';
|
||||||
const METAKEY = 'homebrewery-new-meta';
|
const METAKEY = 'HB_newPage_meta';
|
||||||
|
|
||||||
const NewBrew = ()=>{
|
const NewBrew = ()=>{
|
||||||
const handleFileChange = (e)=>{
|
const handleFileChange = (e)=>{
|
||||||
const file = e.target.files[0];
|
const file = e.target.files[0];
|
||||||
if(!file) return;
|
if(!file) return;
|
||||||
|
|
||||||
const currentNew = localStorage.getItem(BREWKEY);
|
if(!confirmLocalStorageChange()) return;
|
||||||
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;
|
|
||||||
|
|
||||||
const reader = new FileReader();
|
const reader = new FileReader();
|
||||||
reader.onload = (e)=>{
|
reader.onload = (e)=>{
|
||||||
@@ -43,6 +40,34 @@ const NewBrew = ()=>{
|
|||||||
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 = ()=>{
|
||||||
|
// 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 (
|
return (
|
||||||
<Nav.dropdown>
|
<Nav.dropdown>
|
||||||
@@ -53,17 +78,25 @@ const NewBrew = ()=>{
|
|||||||
new
|
new
|
||||||
</Nav.item>
|
</Nav.item>
|
||||||
<Nav.item
|
<Nav.item
|
||||||
className='fromBlank'
|
className='new'
|
||||||
href='/new'
|
href='/new'
|
||||||
newTab={true}
|
newTab={true}
|
||||||
color='purple'
|
color='purple'
|
||||||
icon='fa-solid fa-file'>
|
icon='fa-solid fa-file'>
|
||||||
|
resume editing
|
||||||
|
</Nav.item>
|
||||||
|
<Nav.item
|
||||||
|
className='fromBlank'
|
||||||
|
newTab={true}
|
||||||
|
color='yellow'
|
||||||
|
icon='fa-solid fa-file-circle-plus'
|
||||||
|
onClick={()=>{ clearLocalStorage(); }}>
|
||||||
from blank
|
from blank
|
||||||
</Nav.item>
|
</Nav.item>
|
||||||
|
|
||||||
<Nav.item
|
<Nav.item
|
||||||
className='fromFile'
|
className='fromFile'
|
||||||
color='purple'
|
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' }} />
|
||||||
|
|||||||
Reference in New Issue
Block a user