1
|
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('directLink');
|
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
|
this.communityDirectLink.next(Boolean(value).valueOf());
|
25
|
localStorage.setItem('directLink', value);
|
26
|
}
|
27
|
|
28
|
public get(): Observable<boolean> {
|
29
|
return this.communityDirectLink.asObservable();
|
30
|
}
|
31
|
}
|