commit 55eba5783170d74232292f981cb15a27f4f34354
parent 8d5685ad69982bda0a2c1057a5326605337589d4
Author: Katja (ctucx) <git@ctu.cx>
Date: Fri, 31 Jan 2025 12:46:49 +0100
parent 8d5685ad69982bda0a2c1057a5326605337589d4
Author: Katja (ctucx) <git@ctu.cx>
Date: Fri, 31 Jan 2025 12:46:49 +0100
some code-style changes
6 files changed, 31 insertions(+), 48 deletions(-)
diff --git a/src/app_functions.js b/src/app_functions.js @@ -53,13 +53,8 @@ const addJourneys = async data => { await db.addJourneys(journeyEntries, journeysOverviewEntry, historyEntry); }; -const processJourneys = data => { - for (const journey of data.journeys) processJourney(journey); -} - -const processJourney = journey => { - for (const leg of journey.legs) processLeg(leg); -}; +const processJourneys = data => { for (const journey of data.journeys) processJourney(journey) }; +const processJourney = journey => { for (const leg of journey.legs) processLeg(leg) }; export const processLeg = leg => { if (leg.plannedDeparture) leg.plannedDeparture = new Date(leg.plannedDeparture); @@ -90,15 +85,15 @@ export const getJourneys = async slug => { }; export const getJourney = async (refreshToken, profile) => { - let data = await db.getJourney(refreshToken); + let journeyObject = await db.getJourney(refreshToken); - if (!data || JSON.stringify(data.settings) != JSON.stringify(journeySettings())) { - data = await refreshJourney(refreshToken, profile); + if (!journeyObject || JSON.stringify(journeyObject.settings) != JSON.stringify(journeySettings())) { + journeyObject = await refreshJourney(refreshToken, profile); } - processJourney(data); + processJourney(journeyObject); - return data; + return journeyObject; }; export const getMoreJourneys = async (slug, mode) => {
diff --git a/src/dataStorage.js b/src/dataStorage.js @@ -69,11 +69,7 @@ class IDBStorage { await transaction.objectStore('settings').put(settings, 'settings'); } - }, - blocking: async () => { - db.close(); - location.reload(); - }, + } }); return new IDBStorage(idb); @@ -145,7 +141,8 @@ class IDBStorage { } async getJourney(refreshToken) { - return await this.idb.get('journey', refreshToken); + const journeyObject = await this.idb.get('journey', refreshToken); + return journeyObject; } async updateJourney(data) { @@ -153,7 +150,8 @@ class IDBStorage { } } -export const initDataStorage = async () => { +export const clearDataStorage = async () => await deleteDB(dbName); +export const initDataStorage = async () => { try { db = await IDBStorage.open(); } catch(e) { @@ -161,7 +159,3 @@ export const initDataStorage = async () => { alert("IndexedDB initialization failed!"); } }; - -export const clearDataStorage = () => { - deleteDB(dbName); -};
diff --git a/src/formatters.js b/src/formatters.js @@ -23,17 +23,17 @@ export const formatName = (point) => { export const formatDateTime = (date, format) => { if (format != null) { switch (format) { - case 'full': - return padZeros(date.getHours()) + ':' + padZeros(date.getMinutes()) + ', ' + date.getDate() + '.' + (date.getMonth() + 1) + '.' + date.getFullYear(); - break; + case 'full': + return padZeros(date.getHours()) + ':' + padZeros(date.getMinutes()) + ', ' + date.getDate() + '.' + (date.getMonth() + 1) + '.' + date.getFullYear(); + break; - case 'date': - return date.getDate() + '.' + (date.getMonth() + 1) + '.' + date.getFullYear(); - break; + case 'date': + return date.getDate() + '.' + (date.getMonth() + 1) + '.' + date.getFullYear(); + break; - default: - return false; - break; + default: + return false; + break; } } @@ -78,9 +78,7 @@ export const formatPrice = price => { if (!price) return '-'; const currencies = { USD: '$', EUR: '€', GBP: '£' }; let ret = currencies[price.currency] || price.currency; - ret += Math.floor(price.amount); - ret += '.'; - ret += padZeros(price.amount * 100 % 100, 2); + ret += `${Math.floor(price.amount)}.${padZeros(price.amount * 100 % 100, 2)}`; return ret; }; @@ -113,6 +111,4 @@ export const formatLineAdditionalName = (line) => { return null; }; -export const formatLineDisplayName = (line) => { - return line?.name || line?.operator?.name || "???"; -}; +export const formatLineDisplayName = (line) => line?.name || line?.operator?.name || "???";
diff --git a/src/journeysViewCanvas.js b/src/journeysViewCanvas.js @@ -13,10 +13,10 @@ const colorFor = (leg, type) => { return colors[type][product] || colors[type].default; }; const loadFactorColors = { - "low-to-medium": [ "#777", "#ccc", "#ccc" ], - "high": [ "#777", "#777", "#ccc" ], - "very-high": [ "#ee8800", "#ee8800", "#ee8800" ], - "exceptionally-high": [ "#cc3300", "#cc3300", "#cc3300" ], + 'low-to-medium': [ '#777', '#ccc', '#ccc' ], + 'high': [ '#777', '#777', '#ccc' ], + 'very-high': [ '#ee8800', '#ee8800', '#ee8800' ], + 'exceptionally-high': [ '#cc3300', '#cc3300', '#cc3300' ], }; const flatten = (arr) => [].concat(...arr);
diff --git a/src/settings.js b/src/settings.js @@ -1,6 +1,7 @@ import { db } from './dataStorage.js'; import { getDefaultLanguage } from './languages.js'; +const subscribers = []; const defaultSettings = { language: getDefaultLanguage(), profile: "db", @@ -26,16 +27,13 @@ const defaultSettings = { showVia: false, }; -const subscribers = []; - export let settings; -export const subscribeSettings = cb => { - subscribers.push(cb); -}; +export const subscribeSettings = cb => subscribers.push(cb); export const initSettings = async () => { settings = (await db.getSettings()) || defaultSettings; + for (const cb of subscribers) await cb(); };
diff --git a/src/settingsView.js b/src/settingsView.js @@ -76,7 +76,7 @@ const profileChangeHandler = (profile) => { }; }; -const clearStorage = () => { +const clearStorage = async () => { clearDataStorage(); caches.keys().then(names => {