searchView: various code improvements

This commit is contained in:
Milan Pässler 2020-09-18 21:14:47 +02:00
parent 1a3556679b
commit 8fc01cf986

View file

@ -12,7 +12,7 @@ import { showSettings } from './settingsView.js';
let currDate = new Date(); let currDate = new Date();
let fromValue = ''; let fromValue = '';
let viaValue = ''; let viaValue = '';
let toValue = ''; let toValue = '';
let isArrValue = false; let isArrValue = false;
let dateValue = currDate.getFullYear()+'-'+padZeros(currDate.getMonth()+1)+'-'+padZeros(currDate.getDate());; let dateValue = currDate.getFullYear()+'-'+padZeros(currDate.getMonth()+1)+'-'+padZeros(currDate.getDate());;
@ -227,7 +227,7 @@ export const search = async (requestId) => {
if (Object.entries(suggestionsCache.from).length !== 0) { if (Object.entries(suggestionsCache.from).length !== 0) {
from = suggestionsCache.from; from = suggestionsCache.from;
} else { } else {
let suggestions = await get("/suggestions", {"query": ElementById('from').value, "results": 1}, true); let suggestions = await get("/suggestions", {"query": fromValue, "results": 1}, true);
if (!suggestions[0]) { if (!suggestions[0]) {
showAlertModal("Abfahrtsbahnof ungültig"); showAlertModal("Abfahrtsbahnof ungültig");
@ -242,10 +242,10 @@ export const search = async (requestId) => {
} else if (Object.entries(suggestionsCache.via).length !== 0) { } else if (Object.entries(suggestionsCache.via).length !== 0) {
via = suggestionsCache.via; via = suggestionsCache.via;
} else { } else {
let suggestions = await get("/suggestions", {"query": ElementById('via').value, "results": 1}, true); let suggestions = await get("/suggestions", {"query": viaValue, "results": 1}, true);
if (!suggestions[0]) { if (!suggestions[0]) {
showAlertModal("Ankunftsbahnhof ungültig"); showAlertModal("Via-Bahnhof ungültig");
return; return;
} }
@ -255,7 +255,7 @@ export const search = async (requestId) => {
if (Object.entries(suggestionsCache.to).length !== 0) { if (Object.entries(suggestionsCache.to).length !== 0) {
to = suggestionsCache.to; to = suggestionsCache.to;
} else { } else {
let suggestions = await get("/suggestions", {"query": ElementById('to').value, "results": 1}, true); let suggestions = await get("/suggestions", {"query": toValue, "results": 1}, true);
if (!suggestions[0]) { if (!suggestions[0]) {
showAlertModal("Ankunftsbahnhof ungültig"); showAlertModal("Ankunftsbahnhof ungültig");