Implements Cookie Consent Popup
This commit is contained in:
52
src/app/shared/cookie-consent/cookie-consert.service.ts
Normal file
52
src/app/shared/cookie-consent/cookie-consert.service.ts
Normal file
@@ -0,0 +1,52 @@
|
||||
import {Injectable} from '@angular/core';
|
||||
import {BehaviorSubject, Subject, Subscription} from "rxjs";
|
||||
import {CookieService} from "ngx-cookie-service";
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class CookieConsertService {
|
||||
|
||||
private storage: Storage;
|
||||
|
||||
cookieStatusChangeSubscription!: BehaviorSubject<boolean>
|
||||
|
||||
constructor(private cookieService: CookieService) {
|
||||
this.storage = window.localStorage
|
||||
|
||||
this.cookieStatusChangeSubscription = new BehaviorSubject<boolean>(
|
||||
this.getCookieConsentStatusFromLocalStorage()
|
||||
);
|
||||
}
|
||||
|
||||
consent() {
|
||||
let status = true;
|
||||
|
||||
this.cookieStatusChangeSubscription.next(status);
|
||||
this.setCookieConsentStatusToLocalStorage(status);
|
||||
}
|
||||
|
||||
decline() {
|
||||
let status = false;
|
||||
|
||||
this.cookieStatusChangeSubscription.next(status);
|
||||
this.setCookieConsentStatusToLocalStorage(status);
|
||||
|
||||
this.cookieService.deleteAll();
|
||||
}
|
||||
|
||||
setCookieConsentStatusToLocalStorage(status: boolean) {
|
||||
this.storage.setItem('cookieConsentStatus', status.toString());
|
||||
}
|
||||
|
||||
getCookieConsentStatusFromLocalStorage(): boolean {
|
||||
let status = this.storage.getItem('cookieConsentStatus');
|
||||
|
||||
if (status === null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return status === 'true';
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user