Autoload OH if country code is not yet loaded

This commit is contained in:
Pieter Vander Vennet 2020-10-11 22:44:58 +02:00
parent c9478c100a
commit feab5a19b3
4 changed files with 19 additions and 5 deletions

View file

@ -113,12 +113,16 @@ export class UIEventSource<T>{
return newSource;
}
public static Chronic(millis: number):UIEventSource<Date>{
public static Chronic(millis: number, asLong: () => boolean = undefined): UIEventSource<Date> {
const source = new UIEventSource<Date>(undefined);
function run() {
source.setData(new Date());
window.setTimeout(run, millis);
if (asLong === undefined || asLong()) {
window.setTimeout(run, millis);
}
}
run();
return source;

View file

@ -23,7 +23,7 @@ export default class State {
// The singleton of the global state
public static state: State;
public static vNumber = "0.1.0c";
public static vNumber = "0.1.0d";
// The user journey states thresholds when a new feature gets unlocked
public static userJourney = {

View file

@ -13,9 +13,15 @@ export default class OpeningHoursVisualization extends UIElement {
super(tags);
this._key = key;
this.ListenTo(UIEventSource.Chronic(60*1000)); // Automatically reload every minute
this.ListenTo(UIEventSource.Chronic(500, () => {
return tags.data._country === undefined;
}));
}
private static GetRanges(oh: any, from: Date, to: Date): ({
isOpen: boolean,
isSpecial: boolean,
@ -144,6 +150,9 @@ export default class OpeningHoursVisualization extends UIElement {
nextSunday.setDate(nextSunday.getDate() + 7);
const tags = this._source.data;
if(tags._country === undefined){
return "Loading...";
}
const oh = new opening_hours(tags[this._key], {
lat: tags._lat,
lon: tags._lon,

View file

@ -5,10 +5,11 @@ import {UIEventSource} from "./Logic/UIEventSource";
import OpeningHoursVisualization from "./UI/OhVisualization";
const oh = "Tu-Fr 09:00-17:00 'as usual'; mo off 'yyy'; su off 'xxx'"
new OpeningHoursVisualization(new UIEventSource<any>({opening_hours:oh}), 'opening_hours').AttachTo('maindiv')
const tags = new UIEventSource<any>({opening_hours:oh});
new OpeningHoursVisualization(tags, 'opening_hours').AttachTo('maindiv')
window.setTimeout(() => {tags.data._country = "be"; }, 5000)
/*/