diff --git a/public/app.js b/public/app.js index ef56535..d9f5efb 100644 --- a/public/app.js +++ b/public/app.js @@ -309,6 +309,11 @@ const app = { this.handleFileUpload(e.target.files[0]); }); + document.getElementById('importFile').addEventListener('change', (e) => { + this.handleFileUpload(e.target.files[0]); + e.target.value = ''; // Reset + }); + // Add event listeners for all four color inputs for (let i = 1; i <= 4; i++) { document.getElementById(`colorHex${i}`).addEventListener('input', (e) => { @@ -355,9 +360,13 @@ const app = { nfcReader.stop(); + // Determine context for error reporting + const isFormVisible = !document.getElementById('formSection').classList.contains('hidden'); + const statusId = isFormVisible ? 'writeStatus' : 'readStatus'; + const format = formats.detectFormatFromFilename(file.name); if (!format) { - this.showStatus('readStatus', 'error', 'Unsupported file type'); + this.showStatus(statusId, 'error', 'Unsupported file type'); return; } @@ -368,12 +377,19 @@ const app = { try { const data = formats.parseData(format, e.target.result); this.populateForm(data, format); + output += `Format: ${formats.getDisplayName(format)}\n`; output += `Material: ${data.materialType}\n`; - this.showDecodedData(output); - this.transitionToForm(format); + + if (!isFormVisible) { + this.showDecodedData(output); + this.transitionToForm(format); + } else { + // Just update UI if already in form mode + this.showStatus(statusId, 'success', `Loaded ${formats.getDisplayName(format)}`); + } } catch (err) { - this.showStatus('readStatus', 'error', `Invalid ${format} file`); + this.showStatus(statusId, 'error', `Invalid ${format} file`); } }; diff --git a/public/formats.js b/public/formats.js index 2051b33..441ec7e 100644 --- a/public/formats.js +++ b/public/formats.js @@ -70,7 +70,7 @@ const formats = { detectFormatFromFilename(filename) { for (const key in this.FORMATS) { - if (filename.endsWith(this.FORMATS[key].getFileExtension(key))) { + if (filename.endsWith(this.getFileExtension(key))) { return key; } } diff --git a/public/index.html b/public/index.html index bc1b9e5..337f535 100644 --- a/public/index.html +++ b/public/index.html @@ -526,6 +526,17 @@