Skip to content

Commit

Permalink
fix(cookie-control): properly save partial cookie configurations
Browse files Browse the repository at this point in the history
  • Loading branch information
dargmuesli committed Jan 14, 2023
1 parent 9962060 commit ebb396e
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions src/runtime/components/CookieControl.vue
Original file line number Diff line number Diff line change
Expand Up @@ -214,9 +214,14 @@ const acceptNecessary = () => {
})
}
const acceptPartial = () => {
const localCookiesEnabledIds = getCookieIds(localCookiesEnabled.value)
setCookies({
isConsentGiven: true,
cookiesOptionalEnabled: localCookiesEnabled.value,
cookiesOptionalEnabled: [
...moduleOptions.cookies?.necessary,
...moduleOptions.cookies.optional,
].filter((cookie) => localCookiesEnabledIds.includes(getCookieId(cookie))),
})
}
const declineAll = () => {
Expand All @@ -226,13 +231,14 @@ const declineAll = () => {
})
}
const toogleCookie = (cookie: Cookie) => {
if (!localCookiesEnabled.value.includes(cookie)) {
const cookieIndex = getCookieIds(localCookiesEnabled.value).indexOf(
getCookieId(cookie)
)
if (cookieIndex < 0) {
localCookiesEnabled.value.push(cookie)
} else {
localCookiesEnabled.value.splice(
localCookiesEnabled.value.indexOf(cookie),
1
)
localCookiesEnabled.value.splice(cookieIndex, 1)
}
}
const getDescription = (description: Translatable) =>
Expand Down

0 comments on commit ebb396e

Please sign in to comment.