commit e928a9b6992c035f0b50bed0181f4124f63f6454
parent 8efdfc792c645125696d7cf7c0c449d043795491
Author: Katja (ctucx) <git@ctu.cx>
Date: Sun, 26 Jan 2025 15:00:05 +0100
parent 8efdfc792c645125696d7cf7c0c449d043795491
Author: Katja (ctucx) <git@ctu.cx>
Date: Sun, 26 Jan 2025 15:00:05 +0100
searchView: clear inputs on profile-change
3 files changed, 34 insertions(+), 4 deletions(-)
diff --git a/src/helpers.js b/src/helpers.js @@ -27,6 +27,16 @@ export const isValidDate = (date) => { composedDate.getFullYear() == y; }; +export const isEmptyObject = (obj) => { + for (const prop in obj) { + if (Object.hasOwn(obj, prop)) { + return false; + } + } + + return true; +} + export const getFrom = journeys => { return journeys[0].legs[0].origin; };
diff --git a/src/searchView.js b/src/searchView.js @@ -1,5 +1,5 @@ import { html, nothing, render } from 'lit-html'; -import { ElementById, hideElement, showElement, elementHidden, flipElement, unflipElement, padZeros, isValidDate } from './helpers.js'; +import { ElementById, hideElement, showElement, elementHidden, flipElement, unflipElement, padZeros, isValidDate, isEmptyObject } from './helpers.js'; import { db } from './dataStorage.js'; import { t, getJourneys, newJourneys, ds100Reverse } from './app_functions.js'; import { formatName, formatFromTo } from './formatters.js'; @@ -173,12 +173,25 @@ const journeysHistoryAction = (journeysHistory, element) => showSelectModal([ {'label': t('journeyoverview'), 'action': () => { go('/'+element.slug+'/'+settings.journeysViewMode); hideOverlay(); }} ]); -export const searchView = async () => { +export const searchView = async (clearInputs) => { const journeysHistory = (await db.getJourneysHistory()).slice().reverse(); render(searchTemplate(journeysHistory), ElementById('content')); - ElementById('from').focus(); + if (clearInputs === true) { + viewState.fromValue = ''; + viewState.viaValue = ''; + viewState.toValue = ''; + viewState.suggestions.from = {}; + viewState.suggestions.via = {}; + viewState.suggestions.to = {}; + ElementById('from').value = ''; + ElementById('via').value = ''; + ElementById('to').value = ''; + ElementById('fromSuggestions').innerHTML= ''; + ElementById('viaSuggestions').innerHTML = ''; + ElementById('toSuggestions').innerHTML = ''; + } for (const [product, enabled] of Object.entries(settings.products)) { const element = ElementById(product); @@ -186,6 +199,8 @@ export const searchView = async () => { element.checked = enabled; } + + ElementById('from').focus(); }; const submitForm = async (event) => {
diff --git a/src/settingsView.js b/src/settingsView.js @@ -69,6 +69,8 @@ const clearStorage = () => { }; const saveSettings = async () => { + const oldSettings = { ...settings }; + await modifySettings(settings => { settings.combineDateTime = ElementById('combineDateTime').checked; settings.showDS100 = ElementById('showDS100').checked; @@ -79,7 +81,10 @@ const saveSettings = async () => { return settings; }); + let clearInputs = false; + if (oldSettings.profile !== settings.profile) clearInputs = true; + await initHafasClient(settings.profile); - searchView(); + searchView(clearInputs); hideOverlay(); };