Skip to content

Commit

Permalink
fix: prevent session expired alerts from piling up
Browse files Browse the repository at this point in the history
  • Loading branch information
arielsvg committed Jul 20, 2020
1 parent 966783c commit 096b9c8
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions app/assets/javascripts/views/application/application_view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
} from '@/strings';
import { PureViewCtrl } from '@Views/abstract/pure_view_ctrl';
import { PermissionDialog } from '@node_modules/snjs/dist/@types/services/component_manager';
import { alertDialog } from '@/services/alertService';

class ApplicationViewCtrl extends PureViewCtrl {
private $compile?: ng.ICompileService
Expand All @@ -27,7 +28,8 @@ class ApplicationViewCtrl extends PureViewCtrl {
private tagsCollapsed = false
private showingDownloadStatus = false
private uploadSyncStatus: any
private lastAlertShownDate?: Date
private lastAlertShownTimeStamp = 0;
private showingInvalidSessionAlert = false;

/* @ngInject */
constructor(
Expand Down Expand Up @@ -249,16 +251,18 @@ class ApplicationViewCtrl extends PureViewCtrl {

showInvalidSessionAlert() {
/** Don't show repeatedly; at most 30 seconds in between */
const SHOW_INTERVAL = 30;
const SHOW_INTERVAL = 30 * 1000;
if (
!this.lastAlertShownDate ||
(new Date().getTime() - this.lastAlertShownDate!.getTime()) / 1000 > SHOW_INTERVAL
!this.showingInvalidSessionAlert &&
(Date.now() - this.lastAlertShownTimeStamp) > SHOW_INTERVAL
) {
this.lastAlertShownDate = new Date();
setTimeout(() => {
this.application!.alertService!.alert(
STRING_SESSION_EXPIRED
);
this.lastAlertShownTimeStamp = Date.now();
this.showingInvalidSessionAlert = true;
setTimeout(async () => {
await alertDialog({
text: STRING_SESSION_EXPIRED
});
this.showingInvalidSessionAlert = false;
}, 500);
}
}
Expand Down

0 comments on commit 096b9c8

Please sign in to comment.