From 91367a7198b937953fbae6c5d207867e74ca07f1 Mon Sep 17 00:00:00 2001 From: Vibe Nuage Agent Date: Fri, 5 Jun 2026 11:28:05 +0000 Subject: [PATCH] Fix: Verhindere Ueberschreiben von Nextcloud-Daten mit leeren Arrays - In saveNextcloudConfig(): Nur speichern, wenn Daten vorhanden sind - Falls keine lokalen Daten, aber Nextcloud hat Daten: behalte Nextcloud-Daten - Verhindert Datenverlust, wenn Nextcloud bereits Daten hat Fixes: Datenverlust bei Nextcloud-Anmeldung Co-authored-by: trevor1969 --- app.js | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/app.js b/app.js index f1180cf..8685a61 100644 --- a/app.js +++ b/app.js @@ -993,8 +993,34 @@ class TeeTracker { // This will automatically fall back to localStorage if Nextcloud has no data await this.loadData(); - // Save the loaded/merged data to Nextcloud - await this.saveData(); + // Only save to Nextcloud if we actually have data to save + // This prevents overwriting existing Nextcloud data with empty arrays + if (this.teas.length > 0 || this.entries.length > 0) { + await this.saveData(); + } else { + // No data to save, but check if Nextcloud has existing data + const existingTeas = await ncStorage.loadFile(DATA_DIRECTORY + 'teas.json'); + const existingEntries = await ncStorage.loadFile(DATA_DIRECTORY + 'entries.json'); + + // If Nextcloud has data, keep it and load it + if (existingTeas || existingEntries) { + if (existingTeas) { + this.teas = existingTeas.map(tea => ({ + ...tea, + organic: tea.organic !== undefined ? tea.organic : false, + rating: tea.rating !== undefined ? tea.rating : 3 + })); + } + if (existingEntries) { + this.entries = existingEntries.map(entry => ({ + ...entry, + teaspoons: entry.teaspoons !== undefined ? entry.teaspoons : 1 + })); + } + // Don't save, just use the existing Nextcloud data + } + // If Nextcloud has no data and we have no data, nothing to do + } this.showStatusMessage('✅ Konfiguration gespeichert und Daten synchronisiert!', 'success'); } else {