1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00

Save update available date in session storage

Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com>
This commit is contained in:
Alex Andreev 2022-05-27 15:18:00 +03:00
parent b60893c35a
commit 91edfc7206

View File

@ -13,7 +13,7 @@ interface Dependencies {
export class AppUpdateWarning extends Singleton {
@observable warningLevel: "high" | "medium" | "light" | "" = "";
@observable private updateAvailableDate: Date | null = null;
@observable private updateAvailableDate: Date | null = this.getDateFromSessionStorage();
private interval: NodeJS.Timeout | null = null;
constructor(dependencies: Dependencies) {
@ -27,9 +27,28 @@ export class AppUpdateWarning extends Singleton {
});
}
saveDateToSessionStorage() {
if (this.updateAvailableDate) {
window.sessionStorage.setItem("when-update-available", this.updateAvailableDate.toISOString());
}
}
getDateFromSessionStorage() {
const value = window.sessionStorage.getItem("when-update-available");
if (!value) {
return null;
}
const date = new Date(value);
return isNaN(date.getTime()) ? null : date;
}
setUpdateAvailableDate() {
if (!this.updateAvailableDate) {
this.updateAvailableDate = new Date();
this.saveDateToSessionStorage();
}
}