Reset XP counter when API call is accepted

This commit is contained in:
Mikko Ahlroth 2017-08-27 20:54:58 +03:00 committed by Juha Ristolainen
parent ac731b06ed
commit 23466f311e
2 changed files with 9 additions and 3 deletions

View File

@ -26,7 +26,7 @@ export class CodeStatsAPI {
}
public sendUpdate(pulse: Pulse): void {
public sendUpdate(pulse: Pulse): axios.AxiosPromise {
// If we did not have API key, don't try to update
if (this.axios === null) {
return null;
@ -44,7 +44,7 @@ export class CodeStatsAPI {
let json: string = JSON.stringify(data);
console.log(`JSON: ${json}`);
this.axios.post(this.UPDATE_URL, json)
return this.axios.post(this.UPDATE_URL, json)
.then( (response) => {
console.log(response);
})

View File

@ -63,7 +63,13 @@ export class XpCounter {
}
this.updateTimeout = setTimeout(() => {
this.api.sendUpdate(this.pulse);
const promise = this.api.sendUpdate(this.pulse);
if (promise !== null) {
promise.then(() => {
this.updateStatusBar(show, `${this.pulse.getXP(document.languageId)}`);
});
}
}, this.UPDATE_DELAY);
}