2019-07-30 15:26:31 +02:00
|
|
|
import {Inject, Injectable, PLATFORM_ID} from "@angular/core";
|
|
|
|
import {BehaviorSubject, Observable} from "rxjs";
|
|
|
|
import {isPlatformBrowser} from "@angular/common";
|
|
|
|
|
|
|
|
@Injectable({
|
|
|
|
providedIn: "root"
|
|
|
|
})
|
|
|
|
export class LocalStorageService {
|
|
|
|
|
|
|
|
private communityDirectLink: BehaviorSubject<boolean>;
|
|
|
|
|
|
|
|
constructor(@Inject(PLATFORM_ID) private platformId: string) {
|
|
|
|
if(isPlatformBrowser(this.platformId)) {
|
2020-06-24 20:20:19 +02:00
|
|
|
let item = localStorage.getItem('directLink');
|
2019-07-30 15:26:31 +02:00
|
|
|
if(item !== null) {
|
|
|
|
this.communityDirectLink = new BehaviorSubject<boolean>(item == 'true');
|
|
|
|
} else {
|
|
|
|
this.communityDirectLink = new BehaviorSubject<boolean>(false);
|
|
|
|
}
|
|
|
|
} else this.communityDirectLink = new BehaviorSubject<boolean>(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
public setCommunityDirectLink(value: string) {
|
|
|
|
this.communityDirectLink.next(Boolean(value).valueOf());
|
2020-06-24 20:20:19 +02:00
|
|
|
localStorage.setItem('directLink', value);
|
2019-07-30 15:26:31 +02:00
|
|
|
}
|
|
|
|
|
2020-06-05 18:29:06 +02:00
|
|
|
public get(): Observable<boolean> {
|
2019-07-30 15:26:31 +02:00
|
|
|
return this.communityDirectLink.asObservable();
|
|
|
|
}
|
|
|
|
}
|