Prompt refresh when build UUID changes (#24)
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone Build is passing

This commit is contained in:
2020-10-21 10:25:41 -05:00
parent a686ffd498
commit a72fc72c83
8 changed files with 9774 additions and 3 deletions

View File

@@ -10,6 +10,7 @@ import ApiResponse from '../structures/ApiResponse';
export class ApiService {
protected baseEndpoint: string = environment.backendBase;
protected statUrl: string = environment.statUrl;
protected versionUrl: string = environment.versionUrl;
constructor(
protected http: HttpClient,
@@ -31,6 +32,17 @@ export class ApiService {
return this._request(this.statUrl);
}
public version(): Promise<string> {
return new Promise((res, rej) => {
this._request(this.versionUrl).subscribe({
next: result => {
res(result.data.text.trim());
},
error: rej,
});
});
}
protected _request(endpoint, params = {}, method: 'get'|'post' = 'get'): Observable<ApiResponse> {
return new Observable<ApiResponse>(sub => {
let data: any = {}

View File

@@ -11,6 +11,7 @@ export class SessionService {
protected data: any = {};
protected saveTriggered = false;
protected saving = false;
protected loadedVersion = '';
protected privTriggerSave = debounce(() => {
if ( this.saving ) {
this.triggerSave();
@@ -26,11 +27,21 @@ export class SessionService {
this.privTriggerSave();
}
public get version() {
return this.loadedVersion;
}
constructor(
protected readonly api: ApiService,
) { }
async newVersionAvailable() {
return (await this.api.version()) !== this.loadedVersion;
}
async stat() {
this.loadedVersion = await this.api.version();
return new Promise((res, rej) => {
this.api.stat().subscribe(response => {
res(response.data);