0
0
mirror of https://github.com/naturalcrit/homebrewery.git synced 2026-01-17 05:52:42 +00:00

reordering

This commit is contained in:
Víctor Losada Hernández
2025-08-21 12:23:41 +02:00
parent cca9ebefdb
commit 320f1e120f

View File

@@ -10,44 +10,45 @@ const METAKEY = 'homebrewery-new-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) { if(!file) return;
const reader = new FileReader();
reader.onload = (e)=>{ const currentNew = localStorage.getItem(BREWKEY);
const fileContent = e.target.result; if(currentNew && !confirm(
const newBrew = { `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?`
text : fileContent, )) return;
style : ''
}; const reader = new FileReader();
if(fileContent.startsWith('```metadata')) { reader.onload = (e)=>{
splitTextStyleAndMetadata(newBrew); // Modify newBrew directly const fileContent = e.target.result;
localStorage.setItem(BREWKEY, newBrew.text); const newBrew = { text: fileContent, style: '' };
localStorage.setItem(STYLEKEY, newBrew.style);
localStorage.setItem( if(fileContent.startsWith('```metadata')) {
METAKEY, splitTextStyleAndMetadata(newBrew);
JSON.stringify( localStorage.setItem(BREWKEY, newBrew.text);
_.pick(newBrew, ['title', 'description', 'tags', 'systems', 'renderer', 'theme', 'lang']) localStorage.setItem(STYLEKEY, newBrew.style);
) localStorage.setItem(METAKEY, JSON.stringify(
); _.pick(newBrew, ['title', 'description', 'tags', 'systems', 'renderer', 'theme', 'lang'])
window.location.href = '/new'; ));
} else { window.location.href = '/new';
const type = file.name.split('.').pop().toLowercase(); return;
if(type === 'txt') { }
alert(
`This file type is correct, but it is not from the homebrewery or has been tampered with, const type = file.name.split('.').pop().toLowerCase();
please try with a correct file or report this as an issue if you think it is a mistake.` if(type === 'txt') {
); alert(
} else if(!type) { `This file type is correct, but it is not from the homebrewery or has been tampered with, please try with a correct file or report this as an issue if you think it is a mistake.`
alert('This file is invalid, please, enter a valid file'); );
console.log(file); } else if(!type) {
} else { alert('This file is invalid, please, enter a valid file');
alert(`This is a .${type} file, only '.txt' files are allowed`); console.log(file);
} } else {
} alert(`This is a .${type} file, only .txt files are allowed`);
}; }
reader.readAsText(file); };
} reader.readAsText(file);
}; };
return ( return (
<Nav.dropdown> <Nav.dropdown>
<Nav.item <Nav.item