Initialize graphWindowPreference in localstorage properly
This commit is contained in:
		
							parent
							
								
									c9f5002dc2
								
							
						
					
					
						commit
						aee319ed51
					
				@ -1,9 +1,25 @@
 | 
			
		||||
import { Injectable } from '@angular/core';
 | 
			
		||||
import { Router, ActivatedRoute } from '@angular/router';
 | 
			
		||||
 | 
			
		||||
@Injectable({
 | 
			
		||||
  providedIn: 'root'
 | 
			
		||||
})
 | 
			
		||||
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 {
 | 
			
		||||
    try {
 | 
			
		||||
      return localStorage.getItem(key);
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user