From c833d5bb74b8ec3a2ca97c97a3e4fe0f3f6feb72 Mon Sep 17 00:00:00 2001 From: "eric.minning" Date: Thu, 8 Jan 2026 17:18:43 +0100 Subject: [PATCH] Fixed errors and added the loading of step 3 document types --- electron/main/custom_document.html | 107 ++++++++++++++--------------- electron/main/index.html | 3 +- electron/main/renderer.js | 5 +- electron/main/script.js | 13 ++++ 4 files changed, 68 insertions(+), 60 deletions(-) diff --git a/electron/main/custom_document.html b/electron/main/custom_document.html index a12b429..e21971c 100644 --- a/electron/main/custom_document.html +++ b/electron/main/custom_document.html @@ -1,5 +1,6 @@ + @@ -21,7 +22,7 @@ padding: 30px; margin-top: 50px; border-radius: 12px; - box-shadow: 0 4px 20px rgba(0,0,0,0.1); + box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1); width: 90%; max-width: 600px; } @@ -38,7 +39,9 @@ color: #555; } - input[type="text"], textarea, select { + input[type="text"], + textarea, + select { width: 100%; padding: 10px; margin-top: 5px; @@ -59,7 +62,7 @@ } .hidden { - visibility: hidden; + visibility: hidden; } button { @@ -81,6 +84,7 @@ .buttons { flex-direction: column; } + .buttons button { width: 100%; margin-top: 10px; @@ -94,6 +98,7 @@ } +

Manage document types

@@ -105,8 +110,8 @@
- - + +
@@ -132,29 +137,23 @@ const resultDiv = document.getElementById("result"); const exampleText = ""; - - // Zurück zur Haupt-GUI - goBackBtn.addEventListener("click", () => { - window.electronAPI.goBackToMain(); - }); - // dokumente speichern generateBtn.addEventListener("click", () => { const name = docNameInput.value.trim(); const content = promptInput.value.trim(); - if (!name || !content) { - resultDiv.textContent = "Bitte Dokumentname und Prompt ausfüllen."; - setTimeout(() => { - resultDiv.textContent = ""; - }, 3000); - return; - } - window.api.saveTxtFile(name, content).then(); - resultDiv.textContent = "Dokument erfolgreich gespeichert!"; - setTimeout(() => { - resultDiv.textContent = ""; - }, 3000); - reloadDocuments(); + if (!name || !content) { + resultDiv.textContent = "Bitte Dokumentname und Prompt ausfüllen."; + setTimeout(() => { + resultDiv.textContent = ""; + }, 3000); + return; + } + window.api.saveTxtFile(name, content).then(); + resultDiv.textContent = "Dokument erfolgreich gespeichert!"; + setTimeout(() => { + resultDiv.textContent = ""; + }, 3000); + reloadDocuments(); }); @@ -162,49 +161,47 @@ const select = document.getElementById('existingDocs'); window.api.getTxtFiles().then(files => { - reloadDocuments(); + reloadDocuments(); }); //content anzeigen const docNameWrapper = document.getElementById("docNameWrapper"); existingDocs.addEventListener("change", async () => { - const selected = existingDocs.value; + const selected = existingDocs.value; - if (selected === "newDoc") { - docNameWrapper.classList.remove("hidden"); - docNameInput.value = ""; - promptInput.value = exampleText; - return; - } - docNameWrapper.classList.add("hidden"); + if (selected === "newDoc") { + docNameWrapper.classList.remove("hidden"); + docNameInput.value = ""; + promptInput.value = exampleText; + return; + } + docNameWrapper.classList.add("hidden"); - const content = await window.api.readTxtFile(selected); - promptInput.value = content; - docNameInput.value = selected.replace(".txt", ""); + const content = await window.api.readTxtFile(selected); + promptInput.value = content; + docNameInput.value = selected.replace(".txt", ""); }); - //reload drop down - function reloadDocuments() { - [...existingDocs.querySelectorAll('option:not([value="newDoc"])')] - .forEach(o => o.remove()); + //reload drop down + function reloadDocuments() { + [...existingDocs.querySelectorAll('option:not([value="newDoc"])')] + .forEach(o => o.remove()); - window.api.getTxtFiles().then(files => { - files.forEach(file => { - const option = document.createElement('option'); - option.value = file; - option.textContent = file - .replace('.txt', '') // Endung entfernen - .replace(/_/g, ' ') // Leerzeichen ersetzen - .replace(/\b\w/g, c => c.toUpperCase()) // ersten Buchstaben groß - existingDocs.appendChild(option); + window.api.getTxtFiles().then(files => { + files.forEach(file => { + const option = document.createElement('option'); + option.value = file; + option.textContent = file + .replace('.txt', '') // Endung entfernen + .replace(/_/g, ' ') // Leerzeichen ersetzen + .replace(/\b\w/g, c => c.toUpperCase()) // ersten Buchstaben groß + existingDocs.appendChild(option); + }); }); - }); - -} - + } - - + + \ No newline at end of file diff --git a/electron/main/index.html b/electron/main/index.html index 27cfbb3..99a7cdc 100644 --- a/electron/main/index.html +++ b/electron/main/index.html @@ -120,8 +120,7 @@
-
diff --git a/electron/main/renderer.js b/electron/main/renderer.js index 2aef9fb..58856de 100644 --- a/electron/main/renderer.js +++ b/electron/main/renderer.js @@ -16,7 +16,6 @@ window.addEventListener('load', async (e) => { console.log("Error in the window listener load in the renderer.js \n"); console.log(error); } - }); //Listener if the language of the displayed text's in the gui should be changed @@ -25,8 +24,8 @@ language_option.addEventListener('change', (e)=>{ const select = document.getElementById('language_option'); changeLanguage(select.value); } catch (error) { - console.log("Error in the language_option change listener in the renderer.js"); - console.log(error); + console.log("Error in the language_option change listener in the renderer.js"); + console.log(error); } }); diff --git a/electron/main/script.js b/electron/main/script.js index de91461..4b56dd5 100644 --- a/electron/main/script.js +++ b/electron/main/script.js @@ -419,3 +419,16 @@ function fileDownload() { console.error("Download failed:", error); } } + + +window.api.getTxtFiles().then(files => { + files.forEach(file => { + const option = document.createElement('option'); + option.value = file; + option.textContent = file + .replace('.txt', '') // Endung entfernen + .replace(/_/g, ' ') // Leerzeichen ersetzen + .replace(/\b\w/g, c => c.toUpperCase()) // ersten Buchstaben groß + costumDocumentType.appendChild(option); + }); + }); \ No newline at end of file