Skip to content

Commit

Permalink
Style: Fix various eslint warnings and errors
Browse files Browse the repository at this point in the history
  • Loading branch information
OndraM committed Apr 10, 2024
1 parent 096b6bd commit 0082e41
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 51 deletions.
6 changes: 3 additions & 3 deletions src/LmcCookieConsentManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,18 +132,18 @@ const LmcCookieConsentManager: CookieConsentManager = (serviceName, args) => {
cookie_name: cookieName, // Predefined cookie name. Do not override.
current_lang: defaultLang, // Default language used when auto_language is false (or when autodetect failed)
delay: 0, // Show the modal immediately after init
force_consent: displayMode == DisplayMode.FORCE,
force_consent: displayMode === DisplayMode.FORCE,
hide_from_bots: true, // To be hidden also from Selenium
page_scripts: true, // Manage third-party scripts loaded using <script>
use_rfc_cookie: true, // Store cookie content in RFC compatible format.
gui_options: {
consent_modal: {
layout:
displayMode == DisplayMode.FORCE
displayMode === DisplayMode.FORCE
? VanillaCookieConsent.GuiConsentLayout.BOX
: VanillaCookieConsent.GuiConsentLayout.BAR,
position:
displayMode == DisplayMode.FORCE
displayMode === DisplayMode.FORCE
? VanillaCookieConsent.GuiConsentPosition.MIDDLE_CENTER
: VanillaCookieConsent.GuiConsentPosition.BOTTOM_CENTER,
transition: VanillaCookieConsent.Transition.SLIDE, // zoom/slide
Expand Down
80 changes: 32 additions & 48 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,101 +38,85 @@ export const assembleSecondaryButton = (
secondaryButtonMode: Values<typeof SecondaryButtonMode>,
textAcceptNecessary: string,
textShowSettings: string,
): VanillaCookieConsent.ModalSecondaryButton => {
return {
text: secondaryButtonMode === SecondaryButtonMode.ACCEPT_NECESSARY ? textAcceptNecessary : textShowSettings,
role:
secondaryButtonMode === SecondaryButtonMode.ACCEPT_NECESSARY
? VanillaCookieConsent.SecondaryButtonRole.ACCEPT_NECESSARY
: VanillaCookieConsent.SecondaryButtonRole.SETTINGS,
};
};
): VanillaCookieConsent.ModalSecondaryButton => ({
text: secondaryButtonMode === SecondaryButtonMode.ACCEPT_NECESSARY ? textAcceptNecessary : textShowSettings,
role:
secondaryButtonMode === SecondaryButtonMode.ACCEPT_NECESSARY
? VanillaCookieConsent.SecondaryButtonRole.ACCEPT_NECESSARY
: VanillaCookieConsent.SecondaryButtonRole.SETTINGS,
});

export const isSettingsButtonNotShown = (secondaryButtonMode: Values<typeof SecondaryButtonMode>): boolean => {
return secondaryButtonMode !== SecondaryButtonMode.SHOW_SETTINGS;
};
export const isSettingsButtonNotShown = (secondaryButtonMode: Values<typeof SecondaryButtonMode>): boolean =>
secondaryButtonMode !== SecondaryButtonMode.SHOW_SETTINGS;

const assembleCategoryBlock = (
category: CookieConsentCategoryValues,
title: string,
description: string,
readonly: boolean,
cookieTableItems: VanillaCookieConsent.CookieTableItem[] | undefined,
): VanillaCookieConsent.ModalBlock => ({
title,
description,
toggle: { value: category, enabled: readonly, readonly },
...(typeof cookieTableItems !== 'undefined' && { cookie_table: cookieTableItems }),
});

export const assembleCategoryNecessary = (
title: string,
description: string,
cookieTable: CookieTableCategories,
): VanillaCookieConsent.ModalBlock => {
return assembleCategoryBlock(
): VanillaCookieConsent.ModalBlock =>
assembleCategoryBlock(
CookieConsentCategory.NECESSARY,
title,
description,
true,
cookieTable[CookieConsentCategory.NECESSARY],
);
};

export const assembleCategoryAd = (
title: string,
description: string,
cookieTable: CookieTableCategories,
): VanillaCookieConsent.ModalBlock => {
return assembleCategoryBlock(
CookieConsentCategory.AD,
title,
description,
false,
cookieTable[CookieConsentCategory.AD],
);
};
): VanillaCookieConsent.ModalBlock =>
assembleCategoryBlock(CookieConsentCategory.AD, title, description, false, cookieTable[CookieConsentCategory.AD]);

export const assembleCategoryAnalytics = (
title: string,
description: string,
cookieTable: CookieTableCategories,
): VanillaCookieConsent.ModalBlock => {
return assembleCategoryBlock(
): VanillaCookieConsent.ModalBlock =>
assembleCategoryBlock(
CookieConsentCategory.ANALYTICS,
title,
description,
false,
cookieTable[CookieConsentCategory.ANALYTICS],
);
};

export const assembleCategoryFunctionality = (
title: string,
description: string,
cookieTable: CookieTableCategories,
): VanillaCookieConsent.ModalBlock => {
return assembleCategoryBlock(
): VanillaCookieConsent.ModalBlock =>
assembleCategoryBlock(
CookieConsentCategory.FUNCTIONALITY,
title,
description,
false,
cookieTable[CookieConsentCategory.FUNCTIONALITY],
);
};

export const assembleCategoryPersonalization = (
title: string,
description: string,
cookieTable: CookieTableCategories,
): VanillaCookieConsent.ModalBlock => {
return assembleCategoryBlock(
): VanillaCookieConsent.ModalBlock =>
assembleCategoryBlock(
CookieConsentCategory.PERSONALIZATION,
title,
description,
false,
cookieTable[CookieConsentCategory.PERSONALIZATION],
);
};

const assembleCategoryBlock = (
category: CookieConsentCategoryValues,
title: string,
description: string,
readonly: boolean,
cookieTableItems: VanillaCookieConsent.CookieTableItem[] | undefined,
): VanillaCookieConsent.ModalBlock => {
return {
title,
description,
toggle: { value: category, enabled: readonly, readonly },
...(cookieTableItems !== undefined && { cookie_table: cookieTableItems }),
};
};

0 comments on commit 0082e41

Please sign in to comment.