1 |
56808
|
k.triantaf
|
import {Inject, Injectable, PLATFORM_ID} from "@angular/core";
|
2 |
|
|
import {BehaviorSubject, Observable} from "rxjs";
|
3 |
|
|
import {isPlatformBrowser} from "@angular/common";
|
4 |
|
|
|
5 |
|
|
@Injectable({
|
6 |
|
|
providedIn: "root"
|
7 |
|
|
})
|
8 |
|
|
export class LocalStorageService {
|
9 |
|
|
|
10 |
|
|
private communityDirectLink: BehaviorSubject<boolean>;
|
11 |
|
|
|
12 |
|
|
constructor(@Inject(PLATFORM_ID) private platformId: string) {
|
13 |
|
|
if(isPlatformBrowser(this.platformId)) {
|
14 |
|
|
let item = localStorage.getItem('communityDirectLink');
|
15 |
|
|
if(item !== null) {
|
16 |
|
|
this.communityDirectLink = new BehaviorSubject<boolean>(item == 'true');
|
17 |
|
|
} else {
|
18 |
|
|
this.communityDirectLink = new BehaviorSubject<boolean>(false);
|
19 |
|
|
}
|
20 |
|
|
} else this.communityDirectLink = new BehaviorSubject<boolean>(true);
|
21 |
|
|
}
|
22 |
|
|
|
23 |
|
|
public setCommunityDirectLink(value: string) {
|
24 |
|
|
localStorage.setItem('communityDirectLink', value);
|
25 |
|
|
this.communityDirectLink.next(Boolean(value).valueOf());
|
26 |
|
|
}
|
27 |
|
|
|
28 |
56836
|
k.triantaf
|
public get(): Observable<boolean> {;
|
29 |
56808
|
k.triantaf
|
return this.communityDirectLink.asObservable();
|
30 |
|
|
}
|
31 |
|
|
}
|