fix: prevent session expired alerts from piling up
This commit is contained in:
@@ -15,6 +15,7 @@ import {
|
|||||||
} from '@/strings';
|
} from '@/strings';
|
||||||
import { PureViewCtrl } from '@Views/abstract/pure_view_ctrl';
|
import { PureViewCtrl } from '@Views/abstract/pure_view_ctrl';
|
||||||
import { PermissionDialog } from '@node_modules/snjs/dist/@types/services/component_manager';
|
import { PermissionDialog } from '@node_modules/snjs/dist/@types/services/component_manager';
|
||||||
|
import { alertDialog } from '@/services/alertService';
|
||||||
|
|
||||||
class ApplicationViewCtrl extends PureViewCtrl {
|
class ApplicationViewCtrl extends PureViewCtrl {
|
||||||
private $compile?: ng.ICompileService
|
private $compile?: ng.ICompileService
|
||||||
@@ -27,7 +28,8 @@ class ApplicationViewCtrl extends PureViewCtrl {
|
|||||||
private tagsCollapsed = false
|
private tagsCollapsed = false
|
||||||
private showingDownloadStatus = false
|
private showingDownloadStatus = false
|
||||||
private uploadSyncStatus: any
|
private uploadSyncStatus: any
|
||||||
private lastAlertShownDate?: Date
|
private lastAlertShownTimeStamp = 0;
|
||||||
|
private showingInvalidSessionAlert = false;
|
||||||
|
|
||||||
/* @ngInject */
|
/* @ngInject */
|
||||||
constructor(
|
constructor(
|
||||||
@@ -249,16 +251,18 @@ class ApplicationViewCtrl extends PureViewCtrl {
|
|||||||
|
|
||||||
showInvalidSessionAlert() {
|
showInvalidSessionAlert() {
|
||||||
/** Don't show repeatedly; at most 30 seconds in between */
|
/** Don't show repeatedly; at most 30 seconds in between */
|
||||||
const SHOW_INTERVAL = 30;
|
const SHOW_INTERVAL = 30 * 1000;
|
||||||
if (
|
if (
|
||||||
!this.lastAlertShownDate ||
|
!this.showingInvalidSessionAlert &&
|
||||||
(new Date().getTime() - this.lastAlertShownDate!.getTime()) / 1000 > SHOW_INTERVAL
|
(Date.now() - this.lastAlertShownTimeStamp) > SHOW_INTERVAL
|
||||||
) {
|
) {
|
||||||
this.lastAlertShownDate = new Date();
|
this.lastAlertShownTimeStamp = Date.now();
|
||||||
setTimeout(() => {
|
this.showingInvalidSessionAlert = true;
|
||||||
this.application!.alertService!.alert(
|
setTimeout(async () => {
|
||||||
STRING_SESSION_EXPIRED
|
await alertDialog({
|
||||||
);
|
text: STRING_SESSION_EXPIRED
|
||||||
|
});
|
||||||
|
this.showingInvalidSessionAlert = false;
|
||||||
}, 500);
|
}, 500);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user