commit 7e7db6259aa3e2a531f97b281afa9fba713e1308
parent 1c720049d6c588ae55dc29667b32b015523bc16b
Author: Katja (ctucx) <git@ctu.cx>
Date: Thu, 23 Jan 2025 14:38:51 +0100
parent 1c720049d6c588ae55dc29667b32b015523bc16b
Author: Katja (ctucx) <git@ctu.cx>
Date: Thu, 23 Jan 2025 14:38:51 +0100
dataSorage.js: remove localStorage backend
1 file changed, 3 insertions(+), 59 deletions(-)
diff --git a/src/dataStorage.js b/src/dataStorage.js @@ -1,60 +1,9 @@ import { openDB, deleteDB } from 'idb'; export const devMode = false; -const dbName = devMode ? 'trainsearch_dev' : 'trainsearch'; - export let db; -class LocalStorage { - constructor() { - this.settings = JSON.parse(localStorage.getItem('settings') || "null"); - this.journey = JSON.parse(localStorage.getItem('journey') || "{}"); - 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; - } - localStorage.setItem('journey', JSON.stringify(this.journey)); - this.journeysOverview[overviewEntry.slug] = overviewEntry; - 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)); - } -} +const dbName = devMode ? 'trainsearch_dev' : 'trainsearch'; class IDBStorage { constructor(idb) { @@ -165,16 +114,11 @@ export const initDataStorage = async () => { try { db = await IDBStorage.open(); } catch(e) { - console.log("indexeddb initialization failed: ", e); - console.log("falling back to localstorage"); - db = new LocalStorage(); + console.log("IndexedDB initialization failed: ", e); + alert("IndexedDB initialization failed!"); } }; export const clearDataStorage = () => { - localStorage.removeItem('settings') - localStorage.removeItem('journey') - localStorage.removeItem('journeysHistory') - localStorage.removeItem('journeysOverview'); deleteDB(dbName); }