From b91b9c44f1ba63cf6f87bfa65e574c17a54c7732 Mon Sep 17 00:00:00 2001 From: Orest Bida Date: Mon, 1 Apr 2024 18:19:09 +0200 Subject: [PATCH] fix: default enabled categories reset on modal close --- src/core/api.js | 4 ++-- src/utils/general.js | 10 ++++++---- src/utils/scripts.js | 7 +++++-- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/src/core/api.js b/src/core/api.js index 0c607daf..0dd5823b 100644 --- a/src/core/api.js +++ b/src/core/api.js @@ -614,6 +614,8 @@ const retrieveState = () => { * and calculate acceptType */ if (!state._invalidConsent) { + state._enabledServices = {...state._acceptedServices}; + state._acceptedServices = { ...state._acceptedServices, ...services @@ -630,8 +632,6 @@ const retrieveState = () => { ]; } } - - state._enabledServices = {...state._acceptedServices}; }; /** diff --git a/src/utils/general.js b/src/utils/general.js index 4466b09d..ffe9b3bb 100644 --- a/src/utils/general.js +++ b/src/utils/general.js @@ -303,6 +303,7 @@ export const resolveEnabledCategories = (categories, excludedCategories) => { _readOnlyCategories, _preferencesModalExists, _enabledServices, + _defaultEnabledCategories, _allDefinedServices } = globalObj._state; @@ -312,12 +313,13 @@ export const resolveEnabledCategories = (categories, excludedCategories) => { let enabledCategories = []; if (!categories) { - enabledCategories = _acceptedCategories; + enabledCategories = [..._acceptedCategories, ..._defaultEnabledCategories]; //{{START: GUI}} - _preferencesModalExists && (enabledCategories = retrieveCategoriesFromModal()); + if (_preferencesModalExists) { + enabledCategories = retrieveCategoriesFromModal(); + } //{{END: GUI}} } else { - if (isArray(categories)) { enabledCategories.push(...categories); } else if (isString(categories)) { @@ -394,7 +396,7 @@ export const resolveEnabledServices = (relativeCategory) => { const selectedServices = _enabledServices[categoryName]; _acceptedServices[categoryName].push(...selectedServices); } else { - _acceptedServices[categoryName] = []; + _acceptedServices[categoryName] = state._enabledServices[categoryName]; } } diff --git a/src/utils/scripts.js b/src/utils/scripts.js index c7cb3ee3..2e01a891 100644 --- a/src/utils/scripts.js +++ b/src/utils/scripts.js @@ -196,12 +196,15 @@ export const retrieveEnabledCategoriesAndServices = () => { for (const categoryName of state._allCategoryNames) { const category = state._allDefinedCategories[categoryName]; - if (category.readOnly || (category.enabled && state._userConfig.mode === OPT_OUT_MODE)) { + if (category.readOnly || category.enabled) { state._defaultEnabledCategories.push(categoryName); const services = state._allDefinedServices[categoryName] || {}; for (let serviceName in services) { - state._acceptedServices[categoryName].push(serviceName); + state._enabledServices[categoryName].push(serviceName); + if (state._userConfig.mode === OPT_OUT_MODE) { + state._acceptedServices[categoryName].push(serviceName); + } } } }