commit 1514d24a353bac508017814cf871d9700612f7f9
parent 00855ae296898fce39afb663f6c8007933189047
Author: Katja (ctucx) <git@ctu.cx>
Date: Wed, 22 Jan 2025 12:29:45 +0100
parent 00855ae296898fce39afb663f6c8007933189047
Author: Katja (ctucx) <git@ctu.cx>
Date: Wed, 22 Jan 2025 12:29:45 +0100
dataStorage: fix v3 migration
1 file changed, 25 insertions(+), 2 deletions(-)
diff --git a/src/dataStorage.js b/src/dataStorage.js @@ -12,6 +12,7 @@ class LocalStorage { this.journeysHistory = JSON.parse(localStorage.getItem('journeysHistory') || "[]"); this.journeysOverview = JSON.parse(localStorage.getItem('journeysOverview') || "{}"); } + async addJourneys(journeyEntries, overviewEntry, historyEntry) { for (let j of journeyEntries) { this.journey[j.refreshToken] = j; @@ -21,27 +22,34 @@ class LocalStorage { localStorage.setItem('journeysOverview', JSON.stringify(this.journeysOverview)); this.addHistoryEntry(historyEntry); } + async getJourneysHistory() { return this.journeysHistory; } + async addHistoryEntry(newEntry) { this.journeysHistory.push(newEntry); localStorage.setItem('journeysHistory', JSON.stringify(this.journeysHistory)); } + async getSettings() { return this.settings; } + async modifySettings(prevSettings, callback) { const newSettings = callback(prevSettings); localStorage.setItem('settings', JSON.stringify(newSettings)); return newSettings; } + async getJourneysOverview(slug) { return this.journeysOverview[slug]; } + async getJourney(refreshToken) { return this.journey[refreshToken]; } + async updateJourney(data) { this.journey[data.refreshToken] = data; localStorage.setItem('journey', JSON.stringify(this.journey)); @@ -86,9 +94,11 @@ class IDBStorage { db.createObjectStore('journeysHistory', {autoIncrement: true}); case 2: const settings = await transaction.objectStore('settings').get('settings'); - if (settings.profile === 'vbb') { + + if (settings !== undefined && settings.profile === 'vbb') { settings.profile = 'db'; } + await transaction.objectStore('settings').put(settings, 'settings'); case 3: //... add migrations for 3->4 here @@ -115,15 +125,19 @@ class IDBStorage { proms.push(tx.done); await Promise.all(proms); } + async getJourneysHistory() { return await this.idb.getAll('journeysHistory'); } + async addHistoryEntry(newEntry) { await this.idb.put('journeysHistory', newEntry); } + async getSettings() { return await this.idb.get('settings', 'settings'); } + async modifySettings(prevSettings, callback) { const tx = this.idb.transaction('settings', 'readwrite'); const newSettings = callback(prevSettings); @@ -133,12 +147,15 @@ class IDBStorage { ]); return newSettings; } + async getJourneysOverview(slug) { return await this.idb.get('journeysOverview', slug); } + async getJourney(refreshToken) { return await this.idb.get('journey', refreshToken); } + async updateJourney(data) { return await this.idb.put('journey', data); } @@ -154,4 +171,10 @@ export const initDataStorage = async () => { } }; -export const clearDataStorage = () => deleteDB(dbName); +export const clearDataStorage = () => { + localStorage.removeItem('settings') + localStorage.removeItem('journey') + localStorage.removeItem('journeysHistory') + localStorage.removeItem('journeysOverview'); + deleteDB(dbName); +}