Implements Cookie Consent Popup

This commit is contained in:
2023-09-07 04:07:29 -03:00
parent 26be7de840
commit 304b02ed57
13 changed files with 358 additions and 147 deletions

View 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';
}
}