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

@@ -1,6 +1,14 @@
import { Component, OnInit } from '@angular/core';
import {Component, OnDestroy, OnInit} from '@angular/core';
import { AuthService } from './shared/auth/auth.service';
import {UpdateService} from "./shared/service-worker/update.service";
import {
NgcCookieConsentService,
NgcInitializationErrorEvent,
NgcInitializingEvent,
NgcNoCookieLawEvent, NgcStatusChangeEvent
} from "ngx-cookieconsent";
import {Subscription} from "rxjs";
import {CookieConsertService} from "./shared/cookie-consent/cookie-consert.service";
@Component({
selector: 'app-root',
@@ -11,12 +19,34 @@ export class AppComponent implements OnInit {
title = 'frontend-hideyoshi.com';
constructor(private authService: AuthService, private serviceWorker: UpdateService) {
cookieStatusChangeSubscription!: Subscription;
constructor(
private authService: AuthService,
private ccService: NgcCookieConsentService,
private cookieConsentService: CookieConsertService,
private serviceWorker: UpdateService) {
this.serviceWorker.checkForUpdates();
}
ngOnInit(): void {
this.authService.autoLogin();
let cookieConsentStatus = this.cookieConsentService.getCookieConsentStatusFromLocalStorage();
if (cookieConsentStatus) {
this.ccService.fadeOut();
}
this.cookieStatusChangeSubscription = this.ccService.statusChange$.subscribe(
(event: NgcStatusChangeEvent) => {
if (event.status === 'allow') {
this.cookieConsentService.consent();
} else if (event.status === 'deny') {
this.cookieConsentService.decline();
}
}
);
}
}