Starterkit-userConsent-Check wieder implementiert

This commit is contained in:
Alexander Müller 2024-12-29 12:48:45 +01:00
parent df6e9483e6
commit 0a0e6b8538
2 changed files with 32 additions and 10 deletions

View file

@ -13,9 +13,11 @@ export function getUserConsent() {
// Überprüft, ob bereits eine Zustimmung vorliegt
export function checkConsent() {
return getUserConsent() !== null;
const consent = getUserConsent();
return consent === true; // Liefert true nur, wenn explizit zugestimmt wurde
}
// Zeigt das Consent-Banner an
export function showConsentPopup(onAccept, onDecline) {
const title = 'Datenschutzeinstellungen';

View file

@ -1,5 +1,7 @@
import { createRecommendationPopup, populateAuthorsContainer } from './recommendations-utils.js';
import { checkConsent, showConsentPopup, setUserConsent } from '../components/consentManager.js';
// StarterKit-Element erstellen
export function createStarterKitElement(kit) {
const template = document.getElementById('starterkit-template').content.cloneNode(true);
@ -8,39 +10,57 @@ export function createStarterKitElement(kit) {
kitElement.querySelector('h3').textContent = kit.name;
kitElement.querySelector('p').textContent = kit.description;
// Aufteilen der Profilanzahl in zwei Zeilen
// Profilanzahl
const profileCount = kitElement.querySelector('.profile-count');
profileCount.querySelector('.profile-line2').textContent = `${kit.accounts.length}`;
// Hinzufügen der Autoren mit 'created by' über die neue Funktion
// Autoren hinzufügen
const authorsContainer = kitElement.querySelector('.authors-container');
if (!authorsContainer) {
console.error('Fehlendes Element: .authors-container im Template. Bitte prüfen!');
return kitElement; // Gibt das unvollständige Element zurück
return kitElement;
}
populateAuthorsContainer(authorsContainer, kit.authors); // Nutzt die ausgelagerte Funktion
populateAuthorsContainer(authorsContainer, kit.authors);
kitElement.dataset.accounts = JSON.stringify(kit.accounts);
return kitElement;
}
// StarterKits mit Event-Listenern versehen
export function enhanceStarterKits() {
const starterkits = document.querySelectorAll('.starterkit');
starterkits.forEach(kit => {
kit.addEventListener('click', function () {
// Direkt die Profile laden, ohne Consent-Überprüfung
loadStarterKitProfiles(kit);
handleStarterKitClick(kit);
});
});
}
// Funktion zum Laden der StarterKit-Profile
// StarterKit-Klick behandeln
function handleStarterKitClick(kit) {
if (checkConsent()) {
// Zustimmung vorhanden StarterKit-Popup öffnen
loadStarterKitProfiles(kit);
} else {
// Keine Zustimmung Consent-Popup anzeigen
showConsentPopup(
() => {
setUserConsent(true); // Zustimmung speichern
loadStarterKitProfiles(kit); // Nachträglich StarterKit-Popup öffnen
},
() => {
console.log('Consent wurde abgelehnt. StarterKit-Popup wird nicht geöffnet.');
}
);
}
}
// StarterKit-Profile laden
function loadStarterKitProfiles(kit) {
const title = kit.querySelector('h3').textContent;
const description = kit.querySelector('p').textContent; // Beschreibung auslesen
const description = kit.querySelector('p').textContent;
const accounts = JSON.parse(kit.dataset.accounts || '[]');
const authors = Array.from(kit.querySelectorAll('.authors-container .account')).map(author => author.href);