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