Initialize graphWindowPreference in localstorage properly

This commit is contained in:
nymkappa 2021-12-13 11:56:24 +09:00
parent c9f5002dc2
commit aee319ed51

View file

@ -1,9 +1,25 @@
import { Injectable } from '@angular/core'; import { Injectable } from '@angular/core';
import { Router, ActivatedRoute } from '@angular/router';
@Injectable({ @Injectable({
providedIn: 'root' providedIn: 'root'
}) })
export class StorageService { export class StorageService {
constructor(private router: Router, private route: ActivatedRoute) {
let graphWindowPreference: string = this.getValue('graphWindowPreference');
if (graphWindowPreference === null) { // First visit to mempool.space
if (this.router.url.includes("graphs")) {
this.setValue('graphWindowPreference', this.route.snapshot.fragment ? this.route.snapshot.fragment : "2h");
} else {
this.setValue('graphWindowPreference', "2h");
}
} else if (this.router.url.includes("graphs")) { // Visit a different graphs#fragment from last visit
if (this.route.snapshot.fragment !== null && graphWindowPreference !== this.route.snapshot.fragment) {
this.setValue('graphWindowPreference', this.route.snapshot.fragment);
}
}
}
getValue(key: string): string { getValue(key: string): string {
try { try {
return localStorage.getItem(key); return localStorage.getItem(key);