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 {